From patchwork Tue Jun 20 15:00:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1797444 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=r9qvGCE7; 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 4QlrKb26F2z20Wk for ; Wed, 21 Jun 2023 01:34:43 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=r9qvGCE7; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QlrKZ6hLVz30fd for ; Wed, 21 Jun 2023 01:34:42 +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=r9qvGCE7; 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 4QlrKV5hq0z2yLP for ; Wed, 21 Jun 2023 01:34:38 +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 35KFKlq5030092 for ; Tue, 20 Jun 2023 15:34:36 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=gOWV1/QepDmD/5OFREBBggqqDLxUon5EwYmELFhpiH8=; b=r9qvGCE70vEi7TOFjH/FOTelvLAVyQxdeFdv+8kWWFIczAb8PZ9eP1PtklLW91oyKmF8 1SnyZ7ZZPmWkSPaLiEnoWiqHXAFmRO+a92Ev71ovsgu19Q0LADnmrSct9DWQkNvcHACp wb650pcICrwqD8nJypk8bWHL557qxPL4Tw03dmWjCGVktuOQuG6sor+ebe6fqTL4Qwyq 46Nkp1t1u65AsUhK/H4JJFvvy30ITpTdGp1kaWSUfe/Sr6MHtsM3Sxi6rAXhTSG668e2 WFGHhAOpduN4FMfad99YFSOY0CZaYzR+OG9l8VPoIhIHlQU4NWmgp5/kFqEWRy3dfcF3 Cg== Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rbep30fsa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:34:35 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35K10Nih003953 for ; Tue, 20 Jun 2023 15:01:05 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3r943e256u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:01:05 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35KF13H624052084 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Jun 2023 15:01:03 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 56C3320043 for ; Tue, 20 Jun 2023 15:01:03 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2F60C2004B for ; Tue, 20 Jun 2023 15:01:03 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.biot.fr.ibm.com (unknown [9.144.62.191]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 20 Jun 2023 15:01:03 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 20 Jun 2023 17:00:54 +0200 Message-ID: <20230620150101.88802-9-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620150101.88802-1-clombard@linux.ibm.com> References: <20230620150101.88802-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 7ymmpcBgSmK8UdENFvJt0Gbbne2znNqm X-Proofpoint-ORIG-GUID: 7ymmpcBgSmK8UdENFvJt0Gbbne2znNqm 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-06-20_10,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 clxscore=1015 spamscore=0 malwarescore=0 bulkscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306200140 Subject: [Skiboot] [PATCH V4 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 | 180 +++++++++++++++++++++++++++++ core/pldm/pldm.h | 15 +++ 2 files changed, 195 insertions(+) diff --git a/core/pldm/pldm-platform-requests.c b/core/pldm/pldm-platform-requests.c index 141ffe96..9a9779b1 100644 --- a/core/pldm/pldm-platform-requests.c +++ b/core/pldm/pldm-platform-requests.c @@ -28,6 +28,7 @@ struct pldm_pdrs { }; struct pldm_pdrs *pdrs; +static int state_sensor_id = 1; static void pdr_init_complete(bool success) { @@ -258,6 +259,153 @@ int pldm_platform_restart(void) return set_state_effecter_states_req(effecter_id, &field, true); } +static int add_states_sensor_pdr(pldm_pdr *repo, + uint32_t *record_handle, + uint16_t state_set_id, + uint32_t states) +{ + + struct state_sensor_possible_states *possible_states; + struct pldm_state_sensor_pdr *pdr; + uint8_t DEFAULT_CONTAINER_ID = 0; + size_t state_size, pdr_size, actual_pdr_size = 0; + uint8_t *state_storage; + uint32_t swapped; + int rc; + + /* fill in possible states structure */ + state_size = sizeof(struct state_sensor_possible_states) + + sizeof(states) + - sizeof(bitfield8_t); + state_storage = zalloc(state_size); + 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 = state_sensor_id++; + pdr->entity_type = PLDM_ENTITY_SYS_BOARD; + pdr->entity_instance = 1; + pdr->container_id = DEFAULT_CONTAINER_ID; + pdr->sensor_init = PLDM_NO_INIT; + pdr->sensor_auxiliary_names_pdr = false; + pdr->composite_sensor_count = 1; + + rc = encode_state_sensor_pdr(pdr, pdr_size, + possible_states, + state_size, + &actual_pdr_size); + + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "%s - Failed to encode state sensor PDR, rc: %d\n", + __func__, rc); + free(state_storage); + free(pdr); + return rc; + } + + *record_handle = pldm_pdr_add(repo, + (const uint8_t *) pdr, + actual_pdr_size, + 0, false, HOST_TID); + + free(state_storage); + free(pdr); + + return OPAL_SUCCESS; +} + +/* + * Add boot progress record in the repository. + */ +static uint32_t add_boot_progress_pdr(pldm_pdr *repo, + uint32_t *record_handle) +{ + int rc; + + rc = add_states_sensor_pdr( + repo, + record_handle, + PLDM_STATE_SET_BOOT_PROGRESS, + enum_bit(PLDM_STATE_SET_BOOT_PROG_STATE_COMPLETED) | + enum_bit(PLDM_STATE_SET_BOOT_PROG_STATE_PCI_RESORUCE_CONFIG) | + enum_bit(PLDM_STATE_SET_BOOT_PROG_STATE_STARTING_OP_SYS)); + if (rc) { + prlog(PR_ERR, "%s - Failed to add states sensor PDR, rc: %d\n", + __func__, rc); + return rc; + } + + prlog(PR_DEBUG, "Add boot progress pdr (record handle: %d)\n", + *record_handle); + + return OPAL_SUCCESS; +} + +/* + * Add terminus locator record in the repository. + */ +static int add_terminus_locator_pdr(pldm_pdr *repo, + uint32_t *record_handle) +{ + struct pldm_terminus_locator_type_mctp_eid *locator_value; + struct pldm_terminus_locator_pdr pdr; + uint8_t DEFAULT_CONTAINER_ID = 0; + uint32_t size; + + pdr.hdr.record_handle = 0; /* record_handle will be generated for us */ + pdr.hdr.version = 1; + pdr.hdr.type = PLDM_TERMINUS_LOCATOR_PDR; + pdr.hdr.record_change_num = 0; + pdr.hdr.length = htole16(sizeof(struct pldm_terminus_locator_pdr) - + sizeof(struct pldm_pdr_hdr)); + pdr.terminus_handle = htole16(HOST_TID); + pdr.validity = PLDM_TL_PDR_VALID; + pdr.tid = HOST_TID; + pdr.container_id = DEFAULT_CONTAINER_ID; + pdr.terminus_locator_type = PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID; + pdr.terminus_locator_value_size = sizeof(struct pldm_terminus_locator_type_mctp_eid); + locator_value = (struct pldm_terminus_locator_type_mctp_eid *)pdr.terminus_locator_value; + locator_value->eid = HOST_EID; + + size = sizeof(struct pldm_terminus_locator_pdr) + + sizeof(struct pldm_terminus_locator_type_mctp_eid); + + *record_handle = pldm_pdr_add(repo, + (const uint8_t *)(&pdr), size, + 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) { @@ -382,6 +530,33 @@ 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_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; @@ -627,6 +802,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 */