From patchwork Fri Jul 21 09:07: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: 1810808 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=T127SADP; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R6kKb1QMnz1yYc for ; Fri, 21 Jul 2023 19:10: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=T127SADP; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4R6kKb0K6tz3dDY for ; Fri, 21 Jul 2023 19:10:11 +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=T127SADP; 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 4R6kGS2wrXz3c3j for ; Fri, 21 Jul 2023 19:07:28 +1000 (AEST) Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36L8aBQ0022622 for ; Fri, 21 Jul 2023 09:07:26 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=Gn/a8WbJKqUdYQlXMSvITX7IRID+EfNOET2U22LNQKY=; b=T127SADPwEZqoFkW2T3ku+MUYEzHKOJMpVw6boPTSlbpL1BTt4L2WpQzUG/3N/ncMLc1 kcJ/kd5gvWHw0GeX3T6zZ9Rr461JpowH6uYosIoes2tUOvcizYFOJ+m2A/KR55xIoW+v tpxImg7dTUDAMWjF24xBZBIcutrEtELg7VoIRfQNUl+wRznQ9q/qUOtK7nHG/fk02uOS /R4mAsp8Y0ma61Pw0hlDdUBH85vBV0BC8+cztmcM4u8DSTtz1c28IxD7OLz1tiHY8pB6 0sVX60wa2YXTM4s6ADzJju4PbHsCxssjE4J9H5hh1gbAXt7MCCgkXHxSoreUN2cT8/5V Tg== 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 3ryp34spyp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:26 +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 36L6tiJr004156 for ; Fri, 21 Jul 2023 09:07:24 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3rv8g1dy10-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:24 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 36L97NhK58130722 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 21 Jul 2023 09:07:23 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DF81420040 for ; Fri, 21 Jul 2023 09:07:22 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AE52C2004B for ; Fri, 21 Jul 2023 09:07:22 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.179.31.149]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Fri, 21 Jul 2023 09:07:22 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Fri, 21 Jul 2023 11:07:07 +0200 Message-ID: <20230721090721.26050-2-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230721090721.26050-1-clombard@linux.ibm.com> References: <20230721090721.26050-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: swmeYYF3Pj5u-J6BkKoFb3QsNS1YUTux X-Proofpoint-GUID: swmeYYF3Pj5u-J6BkKoFb3QsNS1YUTux X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-21_05,2023-07-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 phishscore=0 spamscore=0 clxscore=1015 malwarescore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 suspectscore=0 adultscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307210081 Subject: [Skiboot] [PATCH V5 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 87952dbf..e3efcc2b 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 00000000..5a36b3da --- /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 8622453b..80ee85c0 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 Fri Jul 21 09:07: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: 1810810 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=TRnuopvB; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R6kKx3w4mz1yYc for ; Fri, 21 Jul 2023 19:10:29 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=TRnuopvB; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4R6kKx2sqNz3dG0 for ; Fri, 21 Jul 2023 19:10:29 +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=TRnuopvB; 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 4R6kGT2kz2z3c4s for ; Fri, 21 Jul 2023 19:07:29 +1000 (AEST) Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36L8Zl5a005176 for ; Fri, 21 Jul 2023 09:07:27 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=95f6rnX8Fr5LMXfE7xNmAXDrkw1NU4kjSLZx8KtKO9o=; b=TRnuopvBfpzrYfOOf3Rj0U/lzr310KC8ANnBptLmiOKXkNvj7aHT//1ZYlJX1kYDRqDD c4ELCksjECvXqObqTCD1pc9JbADaPQagfIinin7xbclyHmxpN34nX6yL+1dl+W9MmPH4 bLR4/SOqp1q8cMJ5Z2YiPVHh6FsU51pkMLKqxj8YNJNuPHUwNPgxRTagCYuPWYbZh8FB 4sPXSnElmQrkIDyTgapXfFsimSea2g1Us98bEH1HDTQmeFUdI6M8tWi3U6HoN1ickzC9 5pTgl6ELLLrmqnYG31xef01XVknicbpvZk6eroSYLvwizp6KsC/aHZ1i3QZ/3kfRMkTf gg== 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 3ryc7g670x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:27 +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 36L85Nns030570 for ; Fri, 21 Jul 2023 09:07:25 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3rv79k2vw5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:25 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 36L97NmG39780812 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 21 Jul 2023 09:07:23 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5162C2004D for ; Fri, 21 Jul 2023 09:07:23 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 15ECB2004B for ; Fri, 21 Jul 2023 09:07:23 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.179.31.149]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Fri, 21 Jul 2023 09:07:22 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Fri, 21 Jul 2023 11:07:08 +0200 Message-ID: <20230721090721.26050-3-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230721090721.26050-1-clombard@linux.ibm.com> References: <20230721090721.26050-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 4VUlU39oE0iIcD3Feobw5o2ev2VxQACj X-Proofpoint-ORIG-GUID: 4VUlU39oE0iIcD3Feobw5o2ev2VxQACj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-21_05,2023-07-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 priorityscore=1501 suspectscore=0 adultscore=0 mlxscore=0 spamscore=0 clxscore=1015 impostorscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307210081 Subject: [Skiboot] [PATCH V5 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 a233ea3e..656c38c0 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 2fbd6d32..75efeb54 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 Fri Jul 21 09:07: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: 1810809 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=dCelUnXu; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R6kKm0f59z1yYc for ; Fri, 21 Jul 2023 19:10:20 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=dCelUnXu; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4R6kKl6bYYz3dFK for ; Fri, 21 Jul 2023 19:10: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=dCelUnXu; 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 4R6kGS3Vzfz3cV1 for ; Fri, 21 Jul 2023 19:07:28 +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 36L972WS022385 for ; Fri, 21 Jul 2023 09:07:26 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=mm67r6p/qZ7t0FpJFnrFtLcKU5PwkN1FBIlqyC+C91M=; b=dCelUnXu5H9YZCCqh9E8lojA6aPZKqxRayXEGUU9hP8Mj9He5nA2ChSjl3ahUyphIw8a eSQslZc6REi0aGAB9Tf6fGnw9/wlsPtaEd1U9rW99oNUlyR5qtJPYzNk10SJpGhNjzal sLfv61Wg1WG+snzW426NXXH/vYtnvbOBwBD1XNnefJsNWD1pVEBZ0APuxw/x8FZvhCJn JGi4JgcxPI+QQWv4Ncg5PEY9CkgpEx9CKkXfiqkagjvkXAzRxQYKcxJLlx0ycyNiVgiH e9MB/OlS9Di3PUA57dNa1AvFPk5QVRtbiZ4Z83ZOmKV/m9eO/LjAv7VFbxeRJR9a5xDX xQ== 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 3ry9q8kh4t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:26 +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 36L6eKLC004143 for ; Fri, 21 Jul 2023 09:07:25 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3rv8g1dy15-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:25 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 36L97NRS54001982 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 21 Jul 2023 09:07:23 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AD85E2004D for ; Fri, 21 Jul 2023 09:07:23 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 71C7720040 for ; Fri, 21 Jul 2023 09:07:23 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.179.31.149]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Fri, 21 Jul 2023 09:07:23 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Fri, 21 Jul 2023 11:07:09 +0200 Message-ID: <20230721090721.26050-4-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230721090721.26050-1-clombard@linux.ibm.com> References: <20230721090721.26050-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: KuykBOTexybd8TbVsK94GlECZ437Ltbt X-Proofpoint-GUID: KuykBOTexybd8TbVsK94GlECZ437Ltbt X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-21_05,2023-07-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 clxscore=1015 bulkscore=0 phishscore=0 spamscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=999 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307210081 Subject: [Skiboot] [PATCH V5 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 c506bd4f..568ed232 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 656c38c0..19164a6b 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 75efeb54..5d1593af 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 Fri Jul 21 09:07:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1810816 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=SdhHmVt+; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R6kLy3ZK9z1yYc for ; Fri, 21 Jul 2023 19:11:22 +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=SdhHmVt+; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4R6kLy2PyVz3dKs for ; Fri, 21 Jul 2023 19:11:22 +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=SdhHmVt+; 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 4R6kGW5Xgfz3cWy for ; Fri, 21 Jul 2023 19:07:31 +1000 (AEST) Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36L945OM005119 for ; Fri, 21 Jul 2023 09:07:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=w80TeiqqtsWvttV7gdzVhC8t+evEQkpx6cyyA31d5TQ=; b=SdhHmVt+q96L/1/MVK/FseNjshfeS2e48MkUgXKbw070KGXHDxif8RGCiP0B39rTRDO8 hIL3SfVugjfGPzHiSG3DcPAGR+XAovfrFH7ER8r6DinLvvWzJIaCCbhwgeUgqmLaGB3w UemEyxoPfBBltYkQM6j1+2Doq9jyw3eZA0LuugT1YqkkburgMJ5EGd70hWRkpsgPPqYA n/Ddwj7xZWwlFJkSNwzzUUT0kYn4F8ZXkeNiWkK37xjM8eOaRg8oN7uiQZjb8fIkByJt LSf9N6qh5NBU8FJAbJqJRF5hSlAIE5jcWLFztCSGaYtIuAmcf+YBnpEqvCYP5D0Ttdtl UA== 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 3ryc7g671k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:28 +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 36L7o5P1031299 for ; Fri, 21 Jul 2023 09:07:26 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3rv79k2vwb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:26 +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 36L97O6R26083900 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 21 Jul 2023 09:07:24 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0D5AD2007E for ; Fri, 21 Jul 2023 09:07:24 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CE0D820067 for ; Fri, 21 Jul 2023 09:07:23 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.179.31.149]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Fri, 21 Jul 2023 09:07:23 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Fri, 21 Jul 2023 11:07:10 +0200 Message-ID: <20230721090721.26050-5-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230721090721.26050-1-clombard@linux.ibm.com> References: <20230721090721.26050-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: KcrQfjRJBvz5MHUklUB_FZvS-0M_-TcR X-Proofpoint-ORIG-GUID: KcrQfjRJBvz5MHUklUB_FZvS-0M_-TcR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-21_05,2023-07-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 priorityscore=1501 suspectscore=0 adultscore=0 mlxscore=0 spamscore=0 clxscore=1015 impostorscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307210081 Subject: [Skiboot] [PATCH V5 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 19164a6b..9183b097 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 Fri Jul 21 09:07:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1810811 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=CG3XemUw; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R6kL63K5Hz1yYc for ; Fri, 21 Jul 2023 19:10:38 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=CG3XemUw; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4R6kL628F3z3dGf for ; Fri, 21 Jul 2023 19:10:38 +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=CG3XemUw; 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 4R6kGT6TFjz3cWk for ; Fri, 21 Jul 2023 19:07:29 +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 36L93BCW008911 for ; Fri, 21 Jul 2023 09:07:28 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=6uC6HmkAqya6sb2ue8TumjSf5ILGjHWopQzMUM8kmMw=; b=CG3XemUw2I5roS2Ob3s8nWreLUoNTeh7c+C/SafAkguy4qu/oRzYt/zPBQaJiek8tbYZ 6MOVXwntpJlDKrCCoKpk4FmAVrHiME0rLDK6Sdp+tNsr87jeKl5inuJyIZ4V7A/BjTc6 GGUzENlbDym6Mnj9umWP0O/H90hUpXu/anBrK7atQbiDOc5MvrHGYFHuqVWiU9M7kmtg 4osaYmY9cb8I9lD0PoHGVfnAZQr01Vqu78bJiQni8ugG4NW1lGvD76vhJdLuj6acNbYk ZNx91gTNgal7SxHgD4RsgjG27QYOcOLqoO/t2Vg+/WyU6UK3dtMSnKLAAROPokNm5Fyd IQ== 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 3rypxsgc8m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:27 +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 36L8f7ZX029141 for ; Fri, 21 Jul 2023 09:07:26 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3rv6smw7u2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:26 +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 36L97O6q26083906 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 21 Jul 2023 09:07:24 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 72B5820071 for ; Fri, 21 Jul 2023 09:07:24 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3839A20065 for ; Fri, 21 Jul 2023 09:07:24 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.179.31.149]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Fri, 21 Jul 2023 09:07:24 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Fri, 21 Jul 2023 11:07:11 +0200 Message-ID: <20230721090721.26050-6-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230721090721.26050-1-clombard@linux.ibm.com> References: <20230721090721.26050-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: RBSEzEQIIPsUc51RVyZvK6NKzh_kt_gx X-Proofpoint-ORIG-GUID: RBSEzEQIIPsUc51RVyZvK6NKzh_kt_gx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-21_05,2023-07-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 priorityscore=1501 adultscore=0 suspectscore=0 mlxlogscore=999 spamscore=0 lowpriorityscore=0 impostorscore=0 mlxscore=0 bulkscore=0 malwarescore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307210081 Subject: [Skiboot] [PATCH V5 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 9183b097..1589514e 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 Fri Jul 21 09:07:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1810817 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=BVkZx7fR; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R6kM71fzlz1yYc for ; Fri, 21 Jul 2023 19:11:31 +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=BVkZx7fR; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4R6kM70W8cz3dRH for ; Fri, 21 Jul 2023 19:11:31 +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=BVkZx7fR; 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 4R6kGX0qwSz3cWk for ; Fri, 21 Jul 2023 19:07:31 +1000 (AEST) Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36L8ZEHu004399 for ; Fri, 21 Jul 2023 09:07:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=igFycxqRk8mfkRgS3LnMJe7R0dZb8UJWATxTK9YsOZA=; b=BVkZx7fRHqNmRsfgUqFfXqnz4a4OqYLDK3ZPHDs5M8X8a/Llbsw9UXD9XPA21Z/5d//M A9xJ09jWUmFp+z1QuSQRjea74OiO4fOOm1pNiJmhwvs0Dyr4nMAfQ/5sFLDCTdQA70JS N9SikeGPGtg90+Hd6HbX87mWJrNjusI86t+WnpYir2vEh7qt3rZN9DbPDA2CdthikjFi G/9fidKEdRZeYNMrjIuja4r0bMf/qmFcoTBb48iNT33x9X5kslY4ACx9Q2tSilXSfiob Wqw637R5Uu/BkDhwzu/pzDq/3s3w9i5IQgy7LY/XiYN83wZgdv+uRatCVDHoLtb537TX jw== 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 3ryc7g672d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:28 +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 36L6d7sQ003171 for ; Fri, 21 Jul 2023 09:07:27 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3rv65xw7f1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:26 +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 36L97OdL27591176 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 21 Jul 2023 09:07:24 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C17FF20071 for ; Fri, 21 Jul 2023 09:07:24 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 917A52007E for ; Fri, 21 Jul 2023 09:07:24 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.179.31.149]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Fri, 21 Jul 2023 09:07:24 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Fri, 21 Jul 2023 11:07:12 +0200 Message-ID: <20230721090721.26050-7-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230721090721.26050-1-clombard@linux.ibm.com> References: <20230721090721.26050-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: o-FYjuSzwJCG9DliNiXJKlsYPXs4eNfp X-Proofpoint-ORIG-GUID: o-FYjuSzwJCG9DliNiXJKlsYPXs4eNfp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-21_05,2023-07-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 priorityscore=1501 suspectscore=0 adultscore=0 mlxscore=0 spamscore=0 clxscore=1015 impostorscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307210081 Subject: [Skiboot] [PATCH V5 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 568ed232..eeb20280 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 5d1593af..542cc188 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 Fri Jul 21 09:07:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1810813 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=QE1d/fMV; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R6kLR6R6pz1yYc for ; Fri, 21 Jul 2023 19:10: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=QE1d/fMV; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4R6kLR5MQ4z3dJ8 for ; Fri, 21 Jul 2023 19:10: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=QE1d/fMV; 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 4R6kGV4xwRz3cWk for ; Fri, 21 Jul 2023 19:07:30 +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 36L96tpt021590 for ; Fri, 21 Jul 2023 09:07:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=eqjngO2+pMIM1Bag/m16S1o0psmP01eEsmnAIf55spQ=; b=QE1d/fMVkiTmoUqmJJtsCdwft/T+xEJPF45HAMX1FmsL5rBPvDYd4Fg3NchLJOhrAvrq roV9sUMOOnND0opjCoNfXQ5q0sPrLj4joIq+4DWCgik757USscyYw3I6DiI7FsXLXalN sdCvvApACzp1rzhj7YsAbzHMJUR/Pw20LJAngASmHES0uNFfxg6n39Vrnbc2NMb+fshm f+KUydIlC9laxJ78gEMx57HpA0c2bGRKcX761A3hRs0ZMUMo0bA3AaBihMbKE7x7iH8z BpD5esNIkjmfHvzjnyPtZFvMFn8o9yUhv1LkBwXe/vxILT6gjcLwH07jSz5aYuRoAxI3 Jg== 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 3ry9q8kh6t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:28 +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 36L8aL7n003394 for ; Fri, 21 Jul 2023 09:07:27 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3rv65xw7f4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:27 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 36L97P7T12059186 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 21 Jul 2023 09:07:25 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 30FD120040 for ; Fri, 21 Jul 2023 09:07:25 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EAF8F20074 for ; Fri, 21 Jul 2023 09:07:24 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.179.31.149]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Fri, 21 Jul 2023 09:07:24 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Fri, 21 Jul 2023 11:07:13 +0200 Message-ID: <20230721090721.26050-8-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230721090721.26050-1-clombard@linux.ibm.com> References: <20230721090721.26050-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 7eYHQ4A0cK381JBu83TMu7B3UxPcl66d X-Proofpoint-GUID: 7eYHQ4A0cK381JBu83TMu7B3UxPcl66d X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-21_05,2023-07-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 clxscore=1015 bulkscore=0 phishscore=0 spamscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=999 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307210081 Subject: [Skiboot] [PATCH V5 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 eeb20280..13387304 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 Fri Jul 21 09:07:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1810812 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Dl5Nqv6p; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R6kLH1MzYz1yYc for ; Fri, 21 Jul 2023 19:10:47 +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=Dl5Nqv6p; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4R6kLG72Z8z3dHQ for ; Fri, 21 Jul 2023 19:10:46 +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=Dl5Nqv6p; 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 4R6kGV3QBmz3cQf for ; Fri, 21 Jul 2023 19:07:30 +1000 (AEST) Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36L95UCI013718 for ; Fri, 21 Jul 2023 09:07:28 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=Ea/y4+9hdxZ00baZY7IWjXxWFMxbe2CL3ftE+W2HBzs=; b=Dl5Nqv6pHgmtxAUd9FkV0+A75/kS2H9rX8SRfMybNUdY7N5ghH8+CCqjwJ7jUUjWntzH 4rQ/XxFeyNZ84C80AELDrf9OB9bsO9Rd7rYD6cssPXv54S4kyG3Xqd9Ejvh4JD3Tp7/r BPUAGDZ8xknF8SFiP8y30TLJ61f8lQ4kyJdPpDI3+widESZmCPqb7sQdEKX1RQP+Pquf fTIie2tFLghvLIowIZJivWMgi00x6cZKayUFnvhYNujaK+jbdv6SpG3M+qBaPDn02BwF 5HlYfh8yuUb/qBYCNUHqVPUyx62PmED49gmijxyU9DH5Pf+ddAxfsoRsvcbP3pY6/s9v ow== 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 3ryp34sq2k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:28 +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 36L7slmF007434 for ; Fri, 21 Jul 2023 09:07:27 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3rv80jjwb1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:27 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 36L97P5p12059190 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 21 Jul 2023 09:07:25 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8CD2420040 for ; Fri, 21 Jul 2023 09:07:25 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 51D2020067 for ; Fri, 21 Jul 2023 09:07:25 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.179.31.149]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Fri, 21 Jul 2023 09:07:25 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Fri, 21 Jul 2023 11:07:14 +0200 Message-ID: <20230721090721.26050-9-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230721090721.26050-1-clombard@linux.ibm.com> References: <20230721090721.26050-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 86AuxViQ-6rQ-6koU3P9vMZueoKilV1S X-Proofpoint-GUID: 86AuxViQ-6rQ-6koU3P9vMZueoKilV1S X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-21_05,2023-07-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 phishscore=0 spamscore=0 clxscore=1015 malwarescore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 suspectscore=0 adultscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307210081 Subject: [Skiboot] [PATCH V5 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 13387304..8bd373cc 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 542cc188..32038bb7 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -35,6 +35,21 @@ struct pldm_tx_data { uint8_t data[0]; }; +/* Return an integer with a bit set in the position corresponding to + * the given enumeration (starting from 0 = the least significant + * bit) and zeroes in the other positions. + * Used for libpldm enumeration constants. + * + * + * @example enum_bit(0) = 0x00000001 + * @example enum_bit(1) = 0x00000002 + * @example enum_bit(4) = 0x00000010 + */ +inline uint32_t enum_bit(unsigned int enumeration) +{ + return 1 << enumeration; +} + struct pldm_rx_data { struct pldm_header_info hdrinf; /* parsed message header */ From patchwork Fri Jul 21 09:07:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1810815 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=bK1xZ/+p; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R6kLn38cmz1yYc for ; Fri, 21 Jul 2023 19:11:13 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=bK1xZ/+p; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4R6kLn20Vzz3dKp for ; Fri, 21 Jul 2023 19:11:13 +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=bK1xZ/+p; 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 4R6kGW5Jscz3cWW for ; Fri, 21 Jul 2023 19:07:31 +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 36L970pC022107 for ; Fri, 21 Jul 2023 09:07:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=xKa0t9ZwChKbCv2S3CPGaphO/oEp/nQh8OrX/CR1hmw=; b=bK1xZ/+p5pM5NDCVACYmcsI2evqj0pBvsVxXVfJZrMf7Ex5ElimBg7l46hT+Dt5U6ur9 b3NbNL4+dI76BaZULNKP6lC88eYn+Ps1NIpor93ZEfgsXrqOw/nJX3tCA4u4n8XgFKPT mquyrY4kcBFb50Gi6yuUUI4g7s2zjop4+wHpaENOWj9cDax9YFdFitbiWoQG4nTFHLWc tMKwR3ggzuU5cFW29VBkmksJAGeWe7IVmC2RpnLKq1DD/YiDhoYvRyJuFHpLpk6WpcKE YLE/KTYco/l8nbAY7Qnt7FCBMow3XYzwGY+7RAt4JFXUc0jUCCw6Ixnxh9IBg7OV2sRS ZQ== 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 3ry9q8kh7q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:29 +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 36L7TuAL030687 for ; Fri, 21 Jul 2023 09:07:28 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3rv79k2vwk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:27 +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 36L97Q5v47514008 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 21 Jul 2023 09:07:26 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DF5E420040 for ; Fri, 21 Jul 2023 09:07:25 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AD3EB20076 for ; Fri, 21 Jul 2023 09:07:25 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.179.31.149]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Fri, 21 Jul 2023 09:07:25 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Fri, 21 Jul 2023 11:07:15 +0200 Message-ID: <20230721090721.26050-10-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230721090721.26050-1-clombard@linux.ibm.com> References: <20230721090721.26050-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: NNeBLp8Vqm53f9M5pexMQKFBW0nTha7i X-Proofpoint-GUID: NNeBLp8Vqm53f9M5pexMQKFBW0nTha7i X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-21_05,2023-07-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 clxscore=1015 bulkscore=0 phishscore=0 spamscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=999 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307210081 Subject: [Skiboot] [PATCH V5 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 1589514e..3eba2e9b 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 Fri Jul 21 09:07:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1810819 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=iDV/PllG; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R6kMT2hlZz1yYc for ; Fri, 21 Jul 2023 19:11:49 +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=iDV/PllG; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4R6kMT1VfMz3dSp for ; Fri, 21 Jul 2023 19:11:49 +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=iDV/PllG; 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 4R6kGX3QRPz3cX8 for ; Fri, 21 Jul 2023 19:07:32 +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 36L979l0023591 for ; Fri, 21 Jul 2023 09:07:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=JqkWJntpjvQqEiQe3ltXs3bDyYBMEHPY5BkgTDFMK0I=; b=iDV/PllGglM1MMlYfPokTXeBJVRyUMZOkrtoEMTV9bUexH6g6h8zAVXBlK8Y7i8NeLmt R+w+Vga8ZgvRfEPuoCkY+1YsPICDDAR9wn+jd5/docbzX0Ab0sG6F7LhUZ6MD1W/8qkU NwhfTiWUwxRBh048y7Q7ul5Q1iTIDh0jX1T8qXJ+xubEaunMogxyRL3hk0mPwWp+u9+A jc2+8TXTO6QZH3hNj3e6HUZfEqDZFH/RVcjH42vgE6awNDzRgESWtFr0+7FyAKJhnM6V JM1+d2fDHK5n2zVjr5zJNPfR5BBTVz+gjU26CnnPZFBGfSpcvdoVNNaMOhdRvstIPOxw 3g== 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 3ry9q8kh8n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:30 +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 36L8noXt029129 for ; Fri, 21 Jul 2023 09:07:28 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3rv6smw7ua-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:28 +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 36L97Q7N44302968 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 21 Jul 2023 09:07:26 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4704820075 for ; Fri, 21 Jul 2023 09:07:26 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 157A82004E for ; Fri, 21 Jul 2023 09:07:26 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.179.31.149]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Fri, 21 Jul 2023 09:07:25 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Fri, 21 Jul 2023 11:07:16 +0200 Message-ID: <20230721090721.26050-11-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230721090721.26050-1-clombard@linux.ibm.com> References: <20230721090721.26050-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 40HEztMdUu0Nat-XEQtcCz-GK4i18Dgd X-Proofpoint-GUID: 40HEztMdUu0Nat-XEQtcCz-GK4i18Dgd X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-21_05,2023-07-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 clxscore=1015 bulkscore=0 phishscore=0 spamscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=999 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307210081 Subject: [Skiboot] [PATCH V5 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 ce78374e..0d003ff1 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 3eba2e9b..3ab813f3 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 32038bb7..cf34d5b0 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 Fri Jul 21 09:07:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1810818 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=BYb37R7J; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R6kMH6svFz1yYc for ; Fri, 21 Jul 2023 19:11:39 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=BYb37R7J; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4R6kMH5lKmz3dRP for ; Fri, 21 Jul 2023 19:11:39 +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=BYb37R7J; 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 4R6kGX38Rbz3cX7 for ; Fri, 21 Jul 2023 19:07:32 +1000 (AEST) Received: from pps.filterd (m0353726.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36L8hLL0026830 for ; Fri, 21 Jul 2023 09:07:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=Fl2TsCaew1cKbRDKeQiwsb/AdsfXFbYo8aIj8osP59g=; b=BYb37R7JAosUny9cx+CKXkCB+zgtv3UxkN4t368v8VbC00RQXfjejy3l1sNetSVdGut/ 9gixau0hB0JmeozwDplyZzR7ZE7Mfk1lK6+K/huz0iC31tPCZ3G1P56Dm4gvhlDvkXPo tukhA68R56ybcE7bBX7hNIo5JeCstsj/TbWQHJ9T9qymX7cpVMHZ4XQUKpOCbEDZbziX NS864wZnbYC+cT95g4RiRTrsaOvX+hzKeGTvE8dRomUi8CQF+H4dTUxhs2U4v7NDO1li Mvell1s0FoVY5YlEsc6OfGkQef4A1VvgqGB0KBCRgU00jjhQrodolRUY4y0f6GUUalpF jQ== 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 3rye3fksgq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:30 +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 36L6d7sS003171 for ; Fri, 21 Jul 2023 09:07:28 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3rv65xw7f6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:28 +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 36L97QiU34079318 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 21 Jul 2023 09:07:26 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A194C20063 for ; Fri, 21 Jul 2023 09:07:26 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 70FE120043 for ; Fri, 21 Jul 2023 09:07:26 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.179.31.149]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Fri, 21 Jul 2023 09:07:26 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Fri, 21 Jul 2023 11:07:17 +0200 Message-ID: <20230721090721.26050-12-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230721090721.26050-1-clombard@linux.ibm.com> References: <20230721090721.26050-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Cy9aNwxzHlB815lj4sucyUYFRD16eX84 X-Proofpoint-ORIG-GUID: Cy9aNwxzHlB815lj4sucyUYFRD16eX84 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-21_05,2023-07-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 spamscore=0 mlxscore=0 priorityscore=1501 adultscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 malwarescore=0 impostorscore=0 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307210081 Subject: [Skiboot] [PATCH V5 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 0d003ff1..a9359c00 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 3ab813f3..d42d9f52 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 cf34d5b0..13315ae1 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 Fri Jul 21 09:07:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1810821 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=gA4pZ2UZ; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R6kMp57lbz1yYc for ; Fri, 21 Jul 2023 19:12:06 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=gA4pZ2UZ; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4R6kMp458kz3dVJ for ; Fri, 21 Jul 2023 19:12:06 +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=gA4pZ2UZ; 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 4R6kGY3n38z3cTq for ; Fri, 21 Jul 2023 19:07:33 +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 36L8uAKk020311 for ; Fri, 21 Jul 2023 09:07:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=PvEArTCpwLn3KgHYJ/GBTVtiFoKufCi8ptXlEtStka8=; b=gA4pZ2UZPhtipy2xTr+ueGw5+raaw+AX0MwlHAVUdUjUHgTPH8KlIOsydpnO2y+7kXiW gP6O02yETglXgk1XSUq3JGAdf8Z5UBep5IR54Oi9w7Y5cfTEgkQW1jbxgFO2qdUV5eaM +YHFKDC5RHQxUtw8vZm7t9ehI8own/gpOeETMpxHNg35bGODN2QF+cCGjgvVsYTbS4JD A+RjI8X9FS2++xR6jer3j5XHL4amhiG7ofMxhm3hrlXVHqBgX0GNiBD2B7NY979/+3As IVpAYPVCEM1Wa6S7AUDYSau2nZtozu08uqXYqK7ZMsz8RuGikirYmxMQt2+hfn3EvjBs hg== 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 3rypxsgcbb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:31 +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 36L8Iv5J016886 for ; Fri, 21 Jul 2023 09:07:30 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3rv5ss661t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:30 +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 36L97RvH19989212 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 21 Jul 2023 09:07:27 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0435420069 for ; Fri, 21 Jul 2023 09:07:27 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CCD5420040 for ; Fri, 21 Jul 2023 09:07:26 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.179.31.149]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Fri, 21 Jul 2023 09:07:26 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Fri, 21 Jul 2023 11:07:18 +0200 Message-ID: <20230721090721.26050-13-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230721090721.26050-1-clombard@linux.ibm.com> References: <20230721090721.26050-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: I54F0rIgpO_jysTNx_m92NjSbEO0PE8c X-Proofpoint-ORIG-GUID: I54F0rIgpO_jysTNx_m92NjSbEO0PE8c X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-21_05,2023-07-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 priorityscore=1501 adultscore=0 suspectscore=0 mlxlogscore=999 spamscore=0 lowpriorityscore=0 impostorscore=0 mlxscore=0 bulkscore=0 malwarescore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307210081 Subject: [Skiboot] [PATCH V5 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 8bd373cc..cb0ff944 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 d42d9f52..7dbde7db 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 80ee85c0..e33de7dc 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 Fri Jul 21 09:07:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1810822 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=tXLTVdat; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R6kMz3w7Wz1yYc for ; Fri, 21 Jul 2023 19:12:15 +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=tXLTVdat; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4R6kMz2qlYz3dW3 for ; Fri, 21 Jul 2023 19:12:15 +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=tXLTVdat; 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 4R6kGZ3dwYz3cR2 for ; Fri, 21 Jul 2023 19:07:34 +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 36L972WZ022385 for ; Fri, 21 Jul 2023 09:07:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=pB08gbQu3zJfYBvg7wxHkNDi/jtWPohEm0JnT9VEX44=; b=tXLTVdatgd1zpj3J2U352opKlK+1qXyQrYlh/YZoQ6DuoXXZ9WaRENAmuk0zypr3mpNx 3FU7OV/EbfD+zVTgh5l9zSiJFsD8pIt+EbAQB3cCFRWToCktYa3ukE+0jMOmTkV06yVY scwCh4TJDKkfHr4c9kg5l1h2yOL/cOP5Q5nh2+IIZECZMFPsUxZ22+J7dKJ0fnHf58t7 gUU/k+SXTh+WTWueJnbZAWc8ZyMlbXNsgBl5IT6KQ2PJRUrJ74o9db5XKCaq6TBIWF3O UyLfPVY14KR34i38YQNOkwrTdOce+UUXW1Qjk4RVrE3KaNWiS2Tg7aiGomW+K4cjobLb nw== 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 3ry9q8khat-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:32 +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 36L85Nnx030570 for ; Fri, 21 Jul 2023 09:07:31 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3rv79k2vwu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:31 +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 36L97ROX19989216 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 21 Jul 2023 09:07:28 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5EB0820069 for ; Fri, 21 Jul 2023 09:07:27 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2DE8A20077 for ; Fri, 21 Jul 2023 09:07:27 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.179.31.149]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Fri, 21 Jul 2023 09:07:27 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Fri, 21 Jul 2023 11:07:19 +0200 Message-ID: <20230721090721.26050-14-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230721090721.26050-1-clombard@linux.ibm.com> References: <20230721090721.26050-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: bUbhfJZ5gX3OiJpt6NTXsmyFoJD2Jndw X-Proofpoint-GUID: bUbhfJZ5gX3OiJpt6NTXsmyFoJD2Jndw X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-21_05,2023-07-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 clxscore=1015 bulkscore=0 phishscore=0 spamscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=999 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307210081 Subject: [Skiboot] [PATCH V5 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 e3efcc2b..14aa105b 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 00000000..16797999 --- /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 e33de7dc..7f944e7e 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 Fri Jul 21 09:07:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1810823 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=YhDUbBr2; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R6kN90zVlz1yYc for ; Fri, 21 Jul 2023 19:12: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=YhDUbBr2; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4R6kN86zBGz3cYT for ; Fri, 21 Jul 2023 19:12:24 +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=YhDUbBr2; 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 4R6kGb3Ml0z3cXs for ; Fri, 21 Jul 2023 19:07:35 +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 36L96sZw021517 for ; Fri, 21 Jul 2023 09:07:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=a8XdhAQadEhTrTmCZb6RmNVVZM84lTgpU1wU+00oKmg=; b=YhDUbBr2IIL/FRVerB02Wo3AEdQyWmGl9XRtsfcrZTCjRujU/vTpTj8LQv3RE6QeVadL Pifq/o9DYLKv7Sksf1aiLQKgfcqkWttyUAsqmB5KH6+UTjxCXvG/X1rYjCWi0udrL2zR TEMqDQguu1bh7N3xeJjftOKaAwVjNB13nT2Gc8F4Z2XEB+8TkPpnb2JKNTnPBKaXRwIa BmjQ3m0PKW3xaGy1G71YukPVxcat8h5pOnFZ0oCKNazMVHjFUYErif52ZdWlbd6SWnix ODsCHXF1/V+M+yks1agSsFtSKJClQBkqcQbBsiWrgQtDnWZhHq+DoWC3S5nK7V9lWtf7 Cg== 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 3ry9q8khbv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:33 +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 36L8OQQR017218 for ; Fri, 21 Jul 2023 09:07:32 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3rv5ss6626-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:32 +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 36L97SFL52822388 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 21 Jul 2023 09:07:28 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C49C22006A for ; Fri, 21 Jul 2023 09:07:27 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 89FB82004D for ; Fri, 21 Jul 2023 09:07:27 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.179.31.149]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Fri, 21 Jul 2023 09:07:27 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Fri, 21 Jul 2023 11:07:20 +0200 Message-ID: <20230721090721.26050-15-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230721090721.26050-1-clombard@linux.ibm.com> References: <20230721090721.26050-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: Ia3V86683U1m9n5ahbeInK0hXhDm8bIe X-Proofpoint-GUID: Ia3V86683U1m9n5ahbeInK0hXhDm8bIe X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-21_05,2023-07-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 clxscore=1015 bulkscore=0 phishscore=0 spamscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=999 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307210081 Subject: [Skiboot] [PATCH V5 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 | 293 +++++++++++++++++++++++++++++++++++++++++ include/pldm.h | 5 + 3 files changed, 299 insertions(+), 1 deletion(-) create mode 100644 core/pldm/pldm-opal.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index 14aa105b..4484fac3 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 00000000..11a5531d --- /dev/null +++ b/core/pldm/pldm-opal.c @@ -0,0 +1,293 @@ +// 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\n"); + return OPAL_UNSUPPORTED; + } + + prlog(PR_TRACE, "%s - cmd: 0x%02x netfn: 0x%02x len: 0x%02llx\n", + __func__, opal_ipmi_msg->cmd, opal_ipmi_msg->netfn >> 2, + msg_len); + + switch (opal_ipmi_msg->cmd) { + case IPMI_GET_DEVICE_ID_CMD: + return opal_get_bmc_info(opal_ipmi_msg, msg_len); + + case IPMI_GET_DEVICE_GUID_CMD: + return opal_get_tid_req(opal_ipmi_msg, msg_len); + } + + return OPAL_UNSUPPORTED; +} + +static int64_t opal_ipmi_recv(uint64_t interface, + struct opal_ipmi_msg *opal_ipmi_msg, + __be64 *msg_len) +{ + struct ipmi_msg *msg; + int64_t rc; + + lock(&msgq_lock); + msg = list_top(&msgq, struct ipmi_msg, link); + + if (!msg) { + rc = OPAL_EMPTY; + goto out_unlock; + } + + if (opal_ipmi_msg->version != OPAL_IPMI_MSG_FORMAT_VERSION_1) { + prerror("OPAL IPMI: Incorrect version\n"); + rc = OPAL_UNSUPPORTED; + goto out_del_msg; + } + + if (interface != IPMI_DEFAULT_INTERFACE) { + prerror("IPMI: Invalid interface 0x%llx in %s\n", interface, __func__); + rc = OPAL_PARAMETER; + goto out_del_msg; + } + + if (be64_to_cpu(*msg_len) - sizeof(struct opal_ipmi_msg) < msg->resp_size + 1) { + rc = OPAL_RESOURCE; + goto out_del_msg; + } + + list_del(&msg->link); + if (list_empty(&msgq)) + opal_update_pending_evt(opal_event_ipmi_recv, 0); + unlock(&msgq_lock); + + opal_ipmi_msg->cmd = msg->cmd; + opal_ipmi_msg->netfn = msg->netfn; + opal_ipmi_msg->data[0] = msg->cc; + memcpy(&opal_ipmi_msg->data[1], msg->data, msg->resp_size); + + prlog(PR_TRACE, "%s - cmd: 0x%02x netfn: 0x%02x resp_size: 0x%02x\n", + __func__, msg->cmd, msg->netfn >> 2, msg->resp_size); + + /* Add one as the completion code is returned in the message data */ + *msg_len = cpu_to_be64(msg->resp_size + sizeof(struct opal_ipmi_msg) + 1); + free(msg); + + return OPAL_SUCCESS; + +out_del_msg: + list_del(&msg->link); + if (list_empty(&msgq)) + opal_update_pending_evt(opal_event_ipmi_recv, 0); + free(msg); + +out_unlock: + unlock(&msgq_lock); + return rc; +} + +void pldm_opal_init(void) +{ + struct dt_node *opal_ipmi, *opal_event = NULL; + + opal_ipmi = dt_new(opal_node, "ipmi"); + dt_add_property_strings(opal_ipmi, "compatible", "ibm,opal-ipmi"); + dt_add_property_cells(opal_ipmi, "ibm,ipmi-interface-id", + IPMI_DEFAULT_INTERFACE); + opal_event_ipmi_recv = opal_dynamic_event_alloc(); + dt_add_property_cells(opal_ipmi, "interrupts", + ilog2(opal_event_ipmi_recv)); + + opal_event = dt_find_by_name(opal_node, "event"); + if (opal_event) + dt_add_property_cells(opal_ipmi, "interrupt-parent", + opal_event->phandle); + + opal_register(OPAL_IPMI_SEND, opal_ipmi_send, 3); + opal_register(OPAL_IPMI_RECV, opal_ipmi_recv, 3); +} diff --git a/include/pldm.h b/include/pldm.h index 7f944e7e..54c9bd4b 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 Fri Jul 21 09:07:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1810820 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=f05jb9fq; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R6kMf0QGmz1yYc for ; Fri, 21 Jul 2023 19:11: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=f05jb9fq; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4R6kMd6QmXz3dTX for ; Fri, 21 Jul 2023 19:11:57 +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=f05jb9fq; 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 4R6kGY1hTFz3cX8 for ; Fri, 21 Jul 2023 19:07:33 +1000 (AEST) Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36L8ouO7009140 for ; Fri, 21 Jul 2023 09:07:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=9Y1t7Lyyn03nfKON2Y05MmXGSvdaXav3Rh2g1v5lrm0=; b=f05jb9fqMy4yuHx4UJCmnIZYQTZWR6JfIW601r+bBq09nk+wM8Z+p+Jf4sUACW0Mnsn/ H5rw9POWTpqbTRleDEXKrV5U6P1Z5I3Ndf384Z6vwu/3TPHaRqgVp0xnpIpkfnQ5Xo3d kQYDcHKdllRV5RzyXhBtNVTiVWLVmlbiHyJNAzxHhOJge+/I/50s0oMI0CUy8YcHgbZ4 ai9b0UCkUS2Mn/HakaBkFeloy7ZWd/0+02FwtPv5UHHqclrvrPHkvr1sSqF7mEhUng40 2xiXiyLOQm7MreghN4mwfb9l6hDzDttcKoWrbYQuB7d7MZLRLX06nForv5nrQsfyf4lX xA== 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 3ryp34sq55-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:31 +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 36L7tujr007605 for ; Fri, 21 Jul 2023 09:07:30 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3rv80jjwbb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:30 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 36L97Stt20841028 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 21 Jul 2023 09:07:28 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2B9AB20043 for ; Fri, 21 Jul 2023 09:07:28 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E53982004D for ; Fri, 21 Jul 2023 09:07:27 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.179.31.149]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Fri, 21 Jul 2023 09:07:27 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Fri, 21 Jul 2023 11:07:21 +0200 Message-ID: <20230721090721.26050-16-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230721090721.26050-1-clombard@linux.ibm.com> References: <20230721090721.26050-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: L-A7dKV0mU4-IWlYVxdx-YCtHjoR-7Ck X-Proofpoint-GUID: L-A7dKV0mU4-IWlYVxdx-YCtHjoR-7Ck X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-21_05,2023-07-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 phishscore=0 spamscore=0 clxscore=1015 malwarescore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 suspectscore=0 adultscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307210081 Subject: [Skiboot] [PATCH V5 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 73748a5d..2d8a5459 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 00f22123..7783fe20 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 6697230b..675eb218 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 64f2249d..853da467 100644 --- a/platforms/astbmc/pnor.c +++ b/platforms/astbmc/pnor.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -32,6 +33,30 @@ static enum ast_flash_style ast_flash_get_fallback_style(void) return raw_mem; } +#ifdef CONFIG_PLDM +int pnor_pldm_init(void) +{ + struct blocklevel_device *bl = NULL; + int rc = 0; + + rc = pldm_lid_files_init(&bl); + if (rc) { + prerror("PLAT: Failed to init PNOR driver\n"); + goto fail; + } + + rc = flash_register(bl); + if (!rc) + return 0; + +fail: + if (bl) + pldm_lid_files_exit(bl); + + return rc; +} +#endif + int pnor_init(void) { struct spi_flash_ctrl *pnor_ctrl = NULL; diff --git a/platforms/qemu/qemu.c b/platforms/qemu/qemu.c index 96153e85..0f6e089f 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 } }