From patchwork Tue Aug 29 09:24:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1827196 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=LJERMI4+; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RZhvr4cXZz1yZs for ; Tue, 29 Aug 2023 19:29:28 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=LJERMI4+; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RZhvr3WzVz3c4r for ; Tue, 29 Aug 2023 19:29:28 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=LJERMI4+; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4RZhnv6mMjz3c01 for ; Tue, 29 Aug 2023 19:24:19 +1000 (AEST) Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37T9Dtaa004104 for ; Tue, 29 Aug 2023 09:24:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=JXRn+Hje4r4GCPF54Cnw3BdVtJWiWePsR+7CULggpjA=; b=LJERMI4+jWJnF3Xok6uQNpmYnUnOA4Kks0IEww1MksdKLDsEdu0K7sU0oRVJw8A1cOdB RPNIxLY8IdbbTli4mTJRp4FRNPE1yuGrIOW81pw1gCXZ+FJ3s/Jj/GyuipZs8us2Zeln cw4efZT4XfL7w47HuDll4XhjM1AXYIZcF8djKV+sxO9ZXKKhldahV8/zobLE66z4n7qf c+h+BBjqFH4kW2qcXcyo9sDJDNTfBm9hwCeJ4AvDaW3r4i13+jLID1mbxxTIt5lNfBvl +R/w8tdB0LSQpSnPN5SqT4H52JWOMsEpIzbEX7V+P20zI4fIZpkDcAwAcRTIt8pouZ3w LA== Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3sr87hqh1s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:17 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 37T9AWkY020530 for ; Tue, 29 Aug 2023 09:24:16 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3sqv3yafk9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:16 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 37T9OE4x33948362 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 29 Aug 2023 09:24:14 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BEFD12004E for ; Tue, 29 Aug 2023 09:24:14 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8355E20043 for ; Tue, 29 Aug 2023 09:24:14 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.171.88.232]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 29 Aug 2023 09:24:14 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 29 Aug 2023 11:24:06 +0200 Message-ID: <20230829092409.75899-13-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230829092409.75899-1-clombard@linux.ibm.com> References: <20230829092409.75899-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: PyicmBmIcn6pg-kM_hdbg9SFu1T_MPWT X-Proofpoint-GUID: PyicmBmIcn6pg-kM_hdbg9SFu1T_MPWT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_06,2023-08-28_04,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 priorityscore=1501 clxscore=1015 impostorscore=0 suspectscore=0 adultscore=0 mlxscore=0 malwarescore=0 phishscore=0 bulkscore=0 lowpriorityscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290078 Subject: [Skiboot] [PATCH V6 12/15] core/pldm: Update boot progress state X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" PLDM Event Messages are PLDM monitoring and control messages that are used by a PLDM terminus to synchronously or asynchronously report PLDM events to a central party called the PLDM Event Receiver. This patch allows to send a: - generic sensor events (events related to PLDM numeric and state sensors). - boot progress sensor event. Signed-off-by: Christophe Lombard --- core/pldm/pldm-platform-requests.c | 267 +++++++++++++++++++++++++++++ core/pldm/pldm-responder.c | 1 + include/pldm.h | 12 ++ 3 files changed, 280 insertions(+) diff --git a/core/pldm/pldm-platform-requests.c b/core/pldm/pldm-platform-requests.c index 8bd373ccc..cb0ff9443 100644 --- a/core/pldm/pldm-platform-requests.c +++ b/core/pldm/pldm-platform-requests.c @@ -72,6 +72,51 @@ int pldm_platform_pdr_find_record(uint32_t record_handle, return OPAL_SUCCESS; } +/* + * Search the matching record and return the sensor id. + * PDR type = PLDM_STATE_SENSOR_PDR + */ +static int find_sensor_id_by_state_set_Id(uint16_t entity_type, + uint16_t state_set_id, + uint16_t *sensor_id, + uint16_t terminus_handle) +{ + struct state_sensor_possible_states *possible_states; + struct pldm_state_sensor_pdr *state_sensor_pdr; + const pldm_pdr_record *record = NULL; + uint8_t *outData = NULL; + uint32_t size; + + do { + /* Find (first) PDR record by PLDM_STATE_SENSOR_PDR type + * if record not NULL, then search will begin from this + * record's next record + */ + record = pldm_pdr_find_record_by_type( + pdrs_repo, /* PDR repo handle */ + PLDM_STATE_SENSOR_PDR, + record, /* PDR record handle */ + &outData, &size); + + if (record) { + state_sensor_pdr = (struct pldm_state_sensor_pdr *) outData; + + *sensor_id = le16_to_cpu(state_sensor_pdr->sensor_id); + + possible_states = (struct state_sensor_possible_states *) + state_sensor_pdr->possible_states; + + if ((le16_to_cpu(state_sensor_pdr->entity_type) == entity_type) && + (le16_to_cpu(state_sensor_pdr->terminus_handle) == terminus_handle) && + (le16_to_cpu(possible_states->state_set_id) == state_set_id)) + return OPAL_SUCCESS; + } + + } while (record); + + return OPAL_PARAMETER; +} + /* * Search the matching record and return the effecter id. * PDR type = PLDM_STATE_EFFECTER_PDR @@ -263,6 +308,228 @@ int pldm_platform_restart(void) return set_state_effecter_states_req(effecter_id, &field, true); } +static int send_sensor_state_changed_event(uint16_t state_set_id, + uint16_t sensor_id, + uint8_t sensor_offset, + uint8_t sensor_state, + bool no_timeout) +{ + size_t event_data_size = 0, actual_event_data_size; + size_t response_len, payload_len, data_size; + uint8_t *event_data = NULL; + struct pldm_tx_data *tx; + void *response_msg; + int rc, i; + + struct pldm_platform_event_message_req event_message_req = { + .format_version = PLDM_PLATFORM_EVENT_MESSAGE_FORMAT_VERSION, + .tid = HOST_TID, + .event_class = PLDM_SENSOR_EVENT, + }; + + struct pldm_platform_event_message_resp response; + + prlog(PR_DEBUG, "%s - state_set_id: %d, sensor_id: %d, sensor_state: %d\n", + __func__, state_set_id, sensor_id, sensor_state); + + /* + * The first time around this loop, event_data is nullptr which + * instructs the encoder to not actually do the encoding, but + * rather fill out actual_change_records_size with the correct + * size, stop and return PLDM_SUCCESS. Then we allocate the + * proper amount of memory and call the encoder again, which + * will cause it to actually encode the message. + */ + for (i = 0; i < 2; i++) { + rc = encode_sensor_event_data( + (struct pldm_sensor_event_data *)event_data, + event_data_size, + sensor_id, + PLDM_STATE_SENSOR_STATE, + sensor_offset, + sensor_state, + sensor_state, + &actual_event_data_size); + if (rc) { + prlog(PR_ERR, "encode PldmSensorChgEventData Error, rc: %d\n", rc); + return OPAL_PARAMETER; + } + + if (event_data == NULL) { + event_data_size = actual_event_data_size; + event_data = zalloc(event_data_size); + if (!event_data) { + prlog(PR_ERR, "failed to allocate event data (size: 0x%lx)\n", event_data_size); + return OPAL_NO_MEM; + } + } + } + + /* Send the event request */ + payload_len = PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + event_data_size; + + data_size = sizeof(struct pldm_msg_hdr) + + sizeof(struct pldm_platform_event_message_req) + + event_data_size; + tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = data_size - 1; + + /* Encode the platform event message request */ + rc = encode_platform_event_message_req( + DEFAULT_INSTANCE_ID, + event_message_req.format_version, + event_message_req.tid, + event_message_req.event_class, + (const uint8_t *)event_data, + event_data_size, + (struct pldm_msg *)tx->data, + payload_len); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode PlatformEventMessage Error, rc: %d\n", rc); + free(event_data); + free(tx); + return OPAL_PARAMETER; + } + free(event_data); + + /* Send and get the response message bytes. + * It may happen that for some commands, the responder does not + * have time to respond. + */ + if (no_timeout) { + rc = pldm_mctp_message_tx(tx); + if (rc) + prlog(PR_ERR, "Failed to send PlatformEventMessage request, rc = %d\n", rc); + free(tx); + return rc; + } + + /* Send and get the response message bytes */ + rc = pldm_requester_queue_and_wait(tx, + &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: PlatformEventMessage, rc: %d\n", rc); + free(tx); + return rc; + } + free(tx); + + /* Decode the message */ + payload_len = response_len - sizeof(struct pldm_msg_hdr); + rc = decode_platform_event_message_resp( + response_msg, + payload_len, + &response.completion_code, + &response.platform_event_status); + if (rc != PLDM_SUCCESS || response.completion_code != PLDM_SUCCESS) { + prlog(PR_ERR, "Decode PlatformEventMessage Error, rc: %d, cc: %d, pes: %d\n", + rc, response.completion_code, + response.platform_event_status); + free(response_msg); + return OPAL_PARAMETER; + } + + free(response_msg); + + return OPAL_SUCCESS; +} + +#define BOOT_STATE_SENSOR_INDEX 0 + +int pldm_platform_send_progress_state_change( + enum pldm_state_set_boot_progress_state_values state) +{ + struct state_sensor_possible_states *possible_states; + struct pldm_state_sensor_pdr *sensor_pdr = NULL; + const pldm_pdr_record *record = NULL; + uint16_t terminus_handle; + uint8_t *outData = NULL; + uint16_t sensor_id = 0; + uint32_t size; + + if (!pdr_ready) + return OPAL_HARDWARE; + + prlog(PR_INFO, "Setting boot progress, state: %d\n", state); + + do { + /* Find (first) PDR record by PLDM_STATE_SENSOR_PDR type + * if record not NULL, then search will begin from this + * record's next record + */ + record = pldm_pdr_find_record_by_type( + pdrs_repo, /* PDR repo handle */ + PLDM_STATE_SENSOR_PDR, + record, /* PDR record handle */ + &outData, &size); + + if (record) { + sensor_pdr = (struct pldm_state_sensor_pdr *) outData; + terminus_handle = le16_to_cpu(sensor_pdr->terminus_handle); + + if ((le16_to_cpu(sensor_pdr->entity_type) == PLDM_ENTITY_SYS_BOARD) && + (terminus_handle == HOST_TID)) { + possible_states = (struct state_sensor_possible_states *) + sensor_pdr->possible_states; + + if (le16_to_cpu(possible_states->state_set_id) == + PLDM_STATE_SET_BOOT_PROGRESS){ + sensor_id = le16_to_cpu(sensor_pdr->sensor_id); + break; + } + } + } + + } while (record); + + if (sensor_id == 0) + return OPAL_PARAMETER; + + return send_sensor_state_changed_event( + PLDM_STATE_SET_BOOT_PROGRESS, + sensor_id, + BOOT_STATE_SENSOR_INDEX, + state, + false); +} + +#define SW_TERM_GRACEFUL_SHUTDOWN_INDEX 0 + +/* + * entity_type: System Firmware + * state_set: Software Termination Status(129) + * states: Graceful Shutdown Requested(7) + */ +int pldm_platform_initiate_shutdown(void) +{ + uint16_t sensor_id; + int rc; + + if (!pdr_ready) + return OPAL_HARDWARE; + + rc = find_sensor_id_by_state_set_Id( + PLDM_ENTITY_SYSTEM_CHASSIS, + PLDM_STATE_SET_SW_TERMINATION_STATUS, + &sensor_id, HOST_TID); + if (rc) { + prlog(PR_ERR, "%s - sensor id not found\n", __func__); + return rc; + } + + prlog(PR_INFO, "sending system firmware Graceful Shutdown request (sensor_id: %d)\n", + sensor_id); + + return send_sensor_state_changed_event( + PLDM_STATE_SET_SW_TERMINATION_STATUS, + sensor_id, + SW_TERM_GRACEFUL_SHUTDOWN_INDEX, + PLDM_SW_TERM_GRACEFUL_SHUTDOWN, + true); +} + static int add_state_sensor_pdr(pldm_pdr *repo, uint32_t *record_handle, uint16_t entity_type, diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index d42d9f52a..7dbde7dba 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -792,6 +792,7 @@ static int platform_set_state_effecter_states_handler(const struct pldm_rx_data cpu_to_be64(SOFT_REBOOT)); } + pldm_platform_initiate_shutdown(); break; case PLDM_STATE_SET_BOOT_RESTART_CAUSE_WARM_RESET: diff --git a/include/pldm.h b/include/pldm.h index 80ee85c00..e33de7dcb 100644 --- a/include/pldm.h +++ b/include/pldm.h @@ -6,6 +6,7 @@ #define __PLDM_H__ #include +#include /** * Handle PLDM messages received from MCTP @@ -33,6 +34,11 @@ int pldm_platform_power_off(void); */ int pldm_platform_restart(void); +/** + * Send a system firmware Graceful Shutdown request + */ +int pldm_platform_initiate_shutdown(void); + /** * Update the firmware version device-tree field */ @@ -53,4 +59,10 @@ bool pldm_lid_files_exit(struct blocklevel_device *bl); */ int pldm_watchdog_init(void); +/** + * Update boot progress state + */ +int pldm_platform_send_progress_state_change( + enum pldm_state_set_boot_progress_state_values state); + #endif /* __PLDM_H__ */