From patchwork Tue Sep 13 10:27:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677249 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=tOQTBAXm; 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 4MRfrv1lCJz1ync for ; Tue, 13 Sep 2022 20:31:27 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfrv0zsJz3dps for ; Tue, 13 Sep 2022 20:31:27 +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=tOQTBAXm; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) 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=tOQTBAXm; dkim-atps=neutral Received: from mx0a-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 4MRfmR2Nw7z3c6C for ; Tue, 13 Sep 2022 20:27:34 +1000 (AEST) Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28DALgO5027308 for ; Tue, 13 Sep 2022 10:27:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=fcj6S0hH9Z+4l32zobhl4zw6NAnRejF2WoycH+Rqccg=; b=tOQTBAXmJg+uMJTD6tculS97XQJFavbkxNslvcj7ZZsEyoTEwK7H8b+kryTFCmr7lPwz HmqF4NZnbF1NZJKeE0chh+h9Ce1Y1unAy4e/R4w/1pGk/YzVjMgejrn0Egymkb7qMyfe hGOY/pLO2QZrzunF4yxq6sPqzna/rG8sUVPttn0viZkgvHlQaqGY6101/ZcgmOik5wFy dHs37Zw1ttKIQnK3U0zOlQTzTSzBschzqmexrsrKN8UMSJq62Nl4PRzvdj2wm0gGq1D4 zvGRCtJF/A5nCmYFMoVbfN766t5TUDdrayk2VVsSkPyXyJ3dCqkAh44LznPNE/hpgZ2O og== Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjmxtqvnf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:14 +0000 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAKcUH016206 for ; Tue, 13 Sep 2022 10:27:12 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma02fra.de.ibm.com with ESMTP id 3jgj792pcd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:12 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DANQ0v15925730 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:23:27 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 495B6A404D for ; Tue, 13 Sep 2022 10:27:10 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2182DA4040 for ; Tue, 13 Sep 2022 10:27:10 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:10 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:27:00 +0200 Message-Id: <20220913102705.65506-17-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> References: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Lqiorj8-I-dF_7CQu1d0vYIE5xzrZq0X X-Proofpoint-ORIG-GUID: Lqiorj8-I-dF_7CQu1d0vYIE5xzrZq0X X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-13_03,2022-09-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 phishscore=0 adultscore=0 spamscore=0 clxscore=1015 malwarescore=0 impostorscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V6 16/21] core/pldm: PLDM for FRU data Specification 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" Specification, defines a FRU data format that provides platform asset information including part number, serial number and manufacturer. Use the GetFruRecordByOptionReq command to get specific FRU (Field Replaceable Unit) record according the Record Set Identifier, the Record Type and the field Type. Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- core/pldm/Makefile.inc | 2 +- core/pldm/pldm-fru-requests.c | 136 ++++++++++++++++++++++++++++++++++ core/pldm/pldm-mctp.c | 9 ++- core/pldm/pldm.h | 2 + 4 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 core/pldm/pldm-fru-requests.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index 42645427..4d08e371 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -12,7 +12,7 @@ CFLAGS_$(PLDM_DIR)/pldm-bios-requests.o = -Wno-strict-prototypes 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_OBJS += pldm-bios-requests.o pldm-fru-requests.o PLDM = $(PLDM_DIR)/built-in.a $(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%) diff --git a/core/pldm/pldm-fru-requests.c b/core/pldm/pldm-fru-requests.c new file mode 100644 index 00000000..02c9b968 --- /dev/null +++ b/core/pldm/pldm-fru-requests.c @@ -0,0 +1,136 @@ +// 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 "pldm.h" + +static void *fru_record_table; +static size_t fru_record_length; + +static bool fru_ready; + +static void fru_init_complete(bool success) +{ + /* Read not successful, error out and free the buffer */ + if (!success) { + fru_ready = false; + + if (fru_record_table != NULL) { + free(fru_record_table); + fru_record_length = 0; + } + return; + } + + /* Mark ready */ + fru_ready = true; +} + +static int get_fru_record_table_req(void **record_table_data, + size_t *record_table_length) +{ + char request_msg[PKT_SIZE(struct pldm_get_fru_record_table_req)]; + uint8_t transfer_flag, completion_code; + size_t response_len, payload_len; + uint32_t next_transfer_handle; + uint8_t *table_data; + size_t table_length; + void *response_msg; + int rc; + + struct pldm_get_fru_record_table_req fru_record_table_req = { + .data_transfer_handle = 0, /* (0 if operation op is FIRSTPART) */ + .transfer_operation_flag = PLDM_GET_FIRSTPART, + }; + payload_len = sizeof(struct pldm_get_fru_record_table_req); + + /* Encode the file table request */ + rc = encode_get_fru_record_table_req( + DEFAULT_INSTANCE_ID, + fru_record_table_req.data_transfer_handle, + fru_record_table_req.transfer_operation_flag, + (struct pldm_msg *)request_msg, + payload_len); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetFruRecordTableReq Error, rc: %d\n", rc); + return OPAL_PARAMETER; + } + + /* Send and get the response message bytes */ + rc = pldm_requester_queue_and_wait(request_msg, sizeof(request_msg), + &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: GetFruRecordTableReq, rc: %d\n", rc); + return rc; + } + + /* Decode the message */ + payload_len = response_len - sizeof(struct pldm_msg_hdr); + table_data = zalloc(payload_len); + + rc = decode_get_fru_record_table_resp( + response_msg, + payload_len, + &completion_code, + &next_transfer_handle, + &transfer_flag, + table_data, + &table_length); + if (rc != PLDM_SUCCESS || completion_code != PLDM_SUCCESS) { + prlog(PR_ERR, "Decode GetFruRecordTableReq Error, rc: %d, cc: %d\n", + rc, completion_code); + + free(table_data); + free(response_msg); + return OPAL_PARAMETER; + } + + /* we do not support multipart transfer */ + if ((next_transfer_handle != PLDM_GET_NEXTPART) || + (transfer_flag != PLDM_START_AND_END)) { + prlog(PR_ERR, "Transfert GetFruRecordTableReq not complete, " + "transfer_hndl: %d, transfer_flag: %d\n", + next_transfer_handle, + transfer_flag); + + free(table_data); + free(response_msg); + return OPAL_PARAMETER; + } + + *record_table_length = table_length; + *record_table_data = zalloc(table_length); + memcpy(*record_table_data, table_data, table_length); + + free(table_data); + free(response_msg); + + return OPAL_SUCCESS; +} + +int pldm_fru_init(void) +{ + int rc; + + /* get fru record table */ + rc = get_fru_record_table_req(&fru_record_table, + &fru_record_length); + if (rc) + goto err; + + fru_init_complete(true); + prlog(PR_DEBUG, "%s - done\n", __func__); + + return OPAL_SUCCESS; + +err: + fru_init_complete(false); + return rc; +} diff --git a/core/pldm/pldm-mctp.c b/core/pldm/pldm-mctp.c index ff4f71c3..542edc27 100644 --- a/core/pldm/pldm-mctp.c +++ b/core/pldm/pldm-mctp.c @@ -148,8 +148,15 @@ int pldm_mctp_init(uint8_t mode) /* Get Bios data */ rc = pldm_bios_init(); - if (rc) + if (rc) { prlog(PR_ERR, "Failed to retrieve Bios data\n"); + goto out; + } + + /* Get Fru data */ + rc = pldm_fru_init(); + if (rc) + prlog(PR_ERR, "Failed to retrieve Fru data\n"); out: prlog(PR_NOTICE, "%s - done, rc: %d\n", __func__, rc); diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index db2f9dcd..f9e9db40 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -47,6 +47,8 @@ int pldm_responder_handle_request(struct pldm_rx_data *rx); int pldm_responder_init(void); /* Requester support */ +int pldm_fru_init(void); + int pldm_bios_find_lid_by_attr_name(const char *name, char **lid); int pldm_bios_get_lids_id(char **lid_ids_string); int pldm_bios_init(void);