From patchwork Tue Aug 29 09:24:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1827198 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=lTjUWVoS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RZhwB13m9z1yZs for ; Tue, 29 Aug 2023 19:29:46 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=lTjUWVoS; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RZhw97449z3cBC for ; Tue, 29 Aug 2023 19:29:45 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=lTjUWVoS; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4RZhnw4tBXz3bYc for ; Tue, 29 Aug 2023 19:24:20 +1000 (AEST) Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37T99nJY030217 for ; Tue, 29 Aug 2023 09:24:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=Vah39+3RSbwNEQrl7OGbkd1mwzu1SsWuXNbr+tb2ys0=; b=lTjUWVoSfVoHmuX/Q1kU+DQIXzCCccdVhYekLogwp4++bH1uq8AWpLBq9NTzTgPgMvJV 0EZK/LcbDK1v0hMWj8SJgJ5enDK3Sc8Z/lS6dk4B8jVjuLBvwrPRZBvXtSd6ULtbyqfZ az6dMs+mr6jg6zXxDkrVtbV5qO6iNYThYWnKegqDAPxWpqtP5MULJZsS1vovbUtwzdqC 3XAxxa7Os+I0Hvd9i43wiW78QS4qd6GVjBIg7X53qXgc+Cadeo3d/pfPZa4iI4mApRdI iVwV3ykZvH0eTfVlN/tVeMoBMuguWrtkG/cHQPPB9AZE3NY4cztx0n2n++xCzPMcYpBj /A== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3sr8s75xrp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:18 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 37T7bbOm009989 for ; Tue, 29 Aug 2023 09:24:17 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3sqw7ka3c0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:17 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 37T9OFtn36635064 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 29 Aug 2023 09:24:15 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7632520043 for ; Tue, 29 Aug 2023 09:24:15 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3E9E920040 for ; Tue, 29 Aug 2023 09:24:15 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.171.88.232]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 29 Aug 2023 09:24:15 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 29 Aug 2023 11:24:08 +0200 Message-ID: <20230829092409.75899-15-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230829092409.75899-1-clombard@linux.ibm.com> References: <20230829092409.75899-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: XGA_Vtx6qK30rcUYuWa5-oK5E1_g2d74 X-Proofpoint-ORIG-GUID: XGA_Vtx6qK30rcUYuWa5-oK5E1_g2d74 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_06,2023-08-28_04,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 suspectscore=0 adultscore=0 malwarescore=0 mlxlogscore=999 mlxscore=0 impostorscore=0 phishscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290078 Subject: [Skiboot] [PATCH V6 14/15] core/pldm: Register OPAL_IPMI_SEND/RECV calls back X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" backend apis to support partially: OPAL_IPMI_SEND: send an IPMI message to the service processor OPAL_IPMI_RECV: read an ipmi message of type ``ipmi_msg`` from ipmi message queue ``msgq`` into host OS structure ``opal_ipmi_msg`` Signed-off-by: Christophe Lombard --- core/pldm/Makefile.inc | 2 +- core/pldm/pldm-opal.c | 298 +++++++++++++++++++++++++++++++++++++++++ include/pldm.h | 5 + 3 files changed, 304 insertions(+), 1 deletion(-) create mode 100644 core/pldm/pldm-opal.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index 14aa105b7..4484fac32 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -11,7 +11,7 @@ PLDM_OBJS = pldm-mctp.o pldm-responder.o pldm-requester.o PLDM_OBJS += pldm-base-requests.o pldm-platform-requests.o PLDM_OBJS += pldm-bios-requests.o pldm-fru-requests.o PLDM_OBJS += pldm-file-io-requests.o pldm-lid-files.o -PLDM_OBJS += pldm-watchdog.o pldm-rtc.o +PLDM_OBJS += pldm-watchdog.o pldm-rtc.o pldm-opal.o PLDM = $(PLDM_DIR)/built-in.a $(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%) diff --git a/core/pldm/pldm-opal.c b/core/pldm/pldm-opal.c new file mode 100644 index 000000000..c99509565 --- /dev/null +++ b/core/pldm/pldm-opal.c @@ -0,0 +1,298 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +// Copyright 2022 IBM Corp. + +#define pr_fmt(fmt) "PLDM: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include "pldm.h" + +#define BMC_VERSION_LENGTH 100 + +/* + * Response data from IPMI Get device ID command (As defined in + * Section 20.1 Get Device ID Command - IPMI standard spec). + */ +struct ipmi_dev_id { + uint8_t dev_id; + uint8_t dev_revision; + uint8_t fw_rev1; + uint8_t fw_rev2; + uint8_t ipmi_ver; + uint8_t add_dev_support; + uint8_t manufactur_id[3]; + uint8_t product_id[2]; + uint8_t aux_fw_rev[4]; +}; + +static struct lock msgq_lock = LOCK_UNLOCKED; +static struct list_head msgq = LIST_HEAD_INIT(msgq); +uint64_t opal_event_ipmi_recv; + +static void opal_send_complete(struct ipmi_msg *msg) +{ + lock(&msgq_lock); + list_add_tail(&msgq, &msg->link); + opal_update_pending_evt(opal_event_ipmi_recv, + opal_event_ipmi_recv); + unlock(&msgq_lock); +} + +#define GUID_SIZE 16 + +static int opal_get_tid_req(struct opal_ipmi_msg *opal_ipmi_msg, + uint64_t msg_len __unused) +{ + struct ipmi_msg *opal_ipmi_response = NULL; + uint8_t guid[GUID_SIZE]; + int bmc_tid; + + opal_ipmi_response = zalloc(sizeof(struct ipmi_msg) + GUID_SIZE); + opal_ipmi_response->netfn = IPMI_NETFN_RETURN_CODE(opal_ipmi_msg->netfn); + opal_ipmi_response->cmd = opal_ipmi_msg->cmd; + + memset(&guid, 0, GUID_SIZE); + + /* First byte of guid contains bmc tid */ + bmc_tid = pldm_base_get_bmc_tid(); + if (bmc_tid == -1) { + opal_ipmi_response->resp_size = 0; + opal_ipmi_response->cc = IPMI_ERR_UNSPECIFIED; + goto out; + } + + guid[0] = (uint8_t)bmc_tid; + memcpy(opal_ipmi_response->data, guid, GUID_SIZE); + + opal_ipmi_response->resp_size = GUID_SIZE; + opal_ipmi_response->cc = IPMI_CC_NO_ERROR; + +out: + opal_send_complete(opal_ipmi_response); + return OPAL_SUCCESS; +} + +static int parse_bmc_version(uint8_t *bmc_version, + struct ipmi_dev_id *devid) +{ + uint8_t *ptr; + uint8_t temp; + + prlog(PR_TRACE, "%s - bmc version: %s len=%d\n", __func__, + bmc_version, (int)strlen(bmc_version)); + + /* + * parse bmc version string to find fw_rev1 and fw_rev2 + * Firmware Name is in format : + * fw1030.00-2.8-1030.2233.20220819a (NL1030_007) + * so fw_rev1 = 10 + * fw_rev2 = 20 + * aux_fw_rev = "007" + */ + ptr = strstr(bmc_version, "NL"); + if (ptr == NULL || strlen(ptr) < 8) + return OPAL_PARAMETER; + + ptr += 2; + /* + * Convert first two byte to + * fw_rev1 and net 2byte to fw_rev2 + */ + temp = ptr[2]; + ptr[2] = '\0'; + devid->fw_rev1 = (uint8_t)atoi(ptr); + ptr += 2; + ptr[0] = temp; + + temp = ptr[2]; + ptr[2] = '\0'; + devid->fw_rev2 = (uint8_t)atoi(ptr); + ptr += 2; + ptr[0] = temp; + + /* Aux version is truncated to 4 char only */ + if (*ptr == '_') + strncpy(devid->aux_fw_rev, ptr + 1, 3); + + prlog(PR_TRACE, "BMC Version major->%d minor->%d aux->%.4s\n", + devid->fw_rev1, devid->fw_rev2, devid->aux_fw_rev); + + return OPAL_SUCCESS; +} + +static int opal_get_bmc_info(struct opal_ipmi_msg *opal_ipmi_msg, + uint64_t msg_len __unused) +{ + struct ipmi_msg *opal_ipmi_response = NULL; + char bmc_version[BMC_VERSION_LENGTH]; + struct ipmi_dev_id devid; + int rc; + + opal_ipmi_response = zalloc(sizeof(struct ipmi_msg) + + sizeof(struct ipmi_dev_id)); + opal_ipmi_response->resp_size = sizeof(struct ipmi_dev_id); + opal_ipmi_response->netfn = IPMI_NETFN_RETURN_CODE(opal_ipmi_msg->netfn); + opal_ipmi_response->cmd = opal_ipmi_msg->cmd; + opal_ipmi_response->cc = IPMI_CC_NO_ERROR; + + memset(&devid, 0, sizeof(devid)); + devid.ipmi_ver = OPAL_IPMI_MSG_FORMAT_VERSION_1; + + /* retrieve bmc version */ + rc = pldm_fru_get_bmc_version(bmc_version, BMC_VERSION_LENGTH); + if (rc) { + opal_ipmi_response->resp_size = 0; + opal_ipmi_response->cc = IPMI_ERR_UNSPECIFIED; + goto out; + } + + /* parse the bmc version */ + rc = parse_bmc_version(bmc_version, &devid); + if (rc) { + prlog(PR_ERR, "%s: Failed to parse BMC version, bmc version: %s\n", + __func__, bmc_version); + opal_ipmi_response->resp_size = 0; + opal_ipmi_response->cc = IPMI_ERR_UNSPECIFIED; + goto out; + } + + memcpy(opal_ipmi_response->data, &devid, sizeof(devid)); + +out: + opal_send_complete(opal_ipmi_response); + return OPAL_SUCCESS; +} + +static int64_t opal_ipmi_send(uint64_t interface __unused, + struct opal_ipmi_msg *opal_ipmi_msg, + uint64_t msg_len) +{ + int16_t ipmi_code; + + if (opal_ipmi_msg->version != OPAL_IPMI_MSG_FORMAT_VERSION_1) { + prerror("OPAL IPMI: Incorrect version\n"); + return OPAL_UNSUPPORTED; + } + + msg_len -= sizeof(struct opal_ipmi_msg); + if (msg_len > IPMI_MAX_REQ_SIZE) { + prerror("OPAL IPMI: Invalid request length\n"); + return OPAL_PARAMETER; + } + + ipmi_code = IPMI_CODE(opal_ipmi_msg->netfn >> 2, opal_ipmi_msg->cmd); + if ((ipmi_code == IPMI_CHASSIS_GET_SYS_BOOT_OPT_CMD) || + (opal_ipmi_msg->cmd == IPMI_CODE(opal_ipmi_msg->netfn >> 2, 0x1a)) || + (opal_ipmi_msg->cmd == IPMI_CODE(opal_ipmi_msg->netfn >> 2, 0x42))) { + prerror("OPAL IPMI: Command not supported, code: %d, " + "cmd: 0x%x netfn: 0x%x\n", + ipmi_code, opal_ipmi_msg->cmd, opal_ipmi_msg->netfn >> 2); + return OPAL_UNSUPPORTED; + } + + prlog(PR_TRACE, "%s - cmd: 0x%02x netfn: 0x%02x len: 0x%02llx\n", + __func__, opal_ipmi_msg->cmd, opal_ipmi_msg->netfn >> 2, + msg_len); + + switch (opal_ipmi_msg->cmd) { + case IPMI_GET_DEVICE_ID_CMD: + return opal_get_bmc_info(opal_ipmi_msg, msg_len); + + case IPMI_GET_DEVICE_GUID_CMD: + return opal_get_tid_req(opal_ipmi_msg, msg_len); + } + + prerror("OPAL IPMI: Command not supported, cmd: 0x%x netfn: 0x%x\n", + opal_ipmi_msg->cmd, opal_ipmi_msg->netfn >> 2); + + return OPAL_UNSUPPORTED; +} + +static int64_t opal_ipmi_recv(uint64_t interface, + struct opal_ipmi_msg *opal_ipmi_msg, + __be64 *msg_len) +{ + struct ipmi_msg *msg; + int64_t rc; + + lock(&msgq_lock); + msg = list_top(&msgq, struct ipmi_msg, link); + + if (!msg) { + rc = OPAL_EMPTY; + goto out_unlock; + } + + if (opal_ipmi_msg->version != OPAL_IPMI_MSG_FORMAT_VERSION_1) { + prerror("OPAL IPMI: Incorrect version\n"); + rc = OPAL_UNSUPPORTED; + goto out_del_msg; + } + + if (interface != IPMI_DEFAULT_INTERFACE) { + prerror("IPMI: Invalid interface 0x%llx in %s\n", interface, __func__); + rc = OPAL_PARAMETER; + goto out_del_msg; + } + + if (be64_to_cpu(*msg_len) - sizeof(struct opal_ipmi_msg) < msg->resp_size + 1) { + rc = OPAL_RESOURCE; + goto out_del_msg; + } + + list_del(&msg->link); + if (list_empty(&msgq)) + opal_update_pending_evt(opal_event_ipmi_recv, 0); + unlock(&msgq_lock); + + opal_ipmi_msg->cmd = msg->cmd; + opal_ipmi_msg->netfn = msg->netfn; + opal_ipmi_msg->data[0] = msg->cc; + memcpy(&opal_ipmi_msg->data[1], msg->data, msg->resp_size); + + prlog(PR_TRACE, "%s - cmd: 0x%02x netfn: 0x%02x resp_size: 0x%02x\n", + __func__, msg->cmd, msg->netfn >> 2, msg->resp_size); + + /* Add one as the completion code is returned in the message data */ + *msg_len = cpu_to_be64(msg->resp_size + sizeof(struct opal_ipmi_msg) + 1); + free(msg); + + return OPAL_SUCCESS; + +out_del_msg: + list_del(&msg->link); + if (list_empty(&msgq)) + opal_update_pending_evt(opal_event_ipmi_recv, 0); + free(msg); + +out_unlock: + unlock(&msgq_lock); + return rc; +} + +void pldm_opal_init(void) +{ + struct dt_node *opal_ipmi, *opal_event = NULL; + + opal_ipmi = dt_new(opal_node, "ipmi"); + dt_add_property_strings(opal_ipmi, "compatible", "ibm,opal-ipmi"); + dt_add_property_cells(opal_ipmi, "ibm,ipmi-interface-id", + IPMI_DEFAULT_INTERFACE); + opal_event_ipmi_recv = opal_dynamic_event_alloc(); + dt_add_property_cells(opal_ipmi, "interrupts", + ilog2(opal_event_ipmi_recv)); + + opal_event = dt_find_by_name(opal_node, "event"); + if (opal_event) + dt_add_property_cells(opal_ipmi, "interrupt-parent", + opal_event->phandle); + + opal_register(OPAL_IPMI_SEND, opal_ipmi_send, 3); + opal_register(OPAL_IPMI_RECV, opal_ipmi_recv, 3); +} diff --git a/include/pldm.h b/include/pldm.h index 7f944e7e4..54c9bd4bc 100644 --- a/include/pldm.h +++ b/include/pldm.h @@ -70,4 +70,9 @@ int pldm_platform_send_progress_state_change( */ void pldm_rtc_init(void); +/** + * Register ipmi host interface access callbacks + */ +void pldm_opal_init(void); + #endif /* __PLDM_H__ */