From patchwork Wed May 18 07:43:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Singh Tomar X-Patchwork-Id: 1632642 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=Wneza18z; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L34kX64f7z9sBB for ; Wed, 18 May 2022 17:44:20 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4L34kX5GRsz3bpT for ; Wed, 18 May 2022 17:44: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=Wneza18z; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=abhishek@linux.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=Wneza18z; 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 4L34jt3P9hz3bw6 for ; Wed, 18 May 2022 17:43:46 +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 24I7hZXD016572 for ; Wed, 18 May 2022 07:43:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=ztk6S4u0+1cFeiPcfptQEnNQxb7A6pX9h7EXRswGaks=; b=Wneza18zT94nBzou9TEqMzuQHSbmF5MjvgkhTJefarwr7juBcL4jmf7tTevb9L2nPmaE BVpxumscFkMNVKt5FPA/aZkXO6Sq4/1A2y4EOE7oasjJqAaLx33Ap6TJSEVCGds3Romy zRV/N86ssLtx9p8fP8qX6nNfy3fxQIGBqJI2nAdzLOKysmVhLBE1giv30SVFStg34Jpv 809699STnQhBBAYar590IeXh/eEXax2ecnDkeKWHmJgfBILzEe7PSihtsttBjs0D0ECp asU8oX3qSsXsFIvJVBU2DYA1C3XCGVQBRGc7mIkknwNn0RA8ux0+gKcjnC9xBmpNxg/E FA== Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3g4vnf8058-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 18 May 2022 07:43:43 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 24I7hfwb001359 for ; Wed, 18 May 2022 07:43:41 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma04ams.nl.ibm.com with ESMTP id 3g2429db8w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 18 May 2022 07:43:41 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 24I7hck158720678 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 18 May 2022 07:43:38 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B280111C054; Wed, 18 May 2022 07:43:38 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EF97411C052; Wed, 18 May 2022 07:43:37 +0000 (GMT) Received: from li-22421c4c-355e-11b2-a85c-fdc6c782cba9.in.ibm.com (unknown [9.109.222.255]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 18 May 2022 07:43:37 +0000 (GMT) From: Abhishek Singh Tomar To: skiboot@lists.ozlabs.org Date: Wed, 18 May 2022 13:13:00 +0530 Message-Id: <20220518074304.42497-6-abhishek@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220518074304.42497-1-abhishek@linux.ibm.com> References: <20220518074304.42497-1-abhishek@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Fu-QHehFGuXy9zXU4l0dtfmsDvH37w1q X-Proofpoint-ORIG-GUID: Fu-QHehFGuXy9zXU4l0dtfmsDvH37w1q X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-18_02,2022-05-17_02,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 bulkscore=0 suspectscore=0 phishscore=0 spamscore=0 priorityscore=1501 lowpriorityscore=0 clxscore=1015 adultscore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205180037 Subject: [Skiboot] [PATCH v3 5/9] core/pldm/test : Implement pldm bios specification test 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: , Cc: Abhishek Singh Tomar Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" PLDM BIOS specification defines the data structures and messages for communicating BIOS settings, BIOS attributes, boot configurations, and boot order settings. The patch contains test for PLDM_GET_BIOS_TABLE implementation to get string table, attribute table and value table. It also contains test for implementaion to find lid. Signed-off-by: Abhishek Singh Tomar --- core/pldm/test/Makefile.check | 1 + core/pldm/test/common/test-pldm-common.c | 1 + core/pldm/test/test-pldm-bios.c | 289 +++++++++++++++++++++++ 3 files changed, 291 insertions(+) create mode 100644 core/pldm/test/test-pldm-bios.c diff --git a/core/pldm/test/Makefile.check b/core/pldm/test/Makefile.check index 7af66ccf..c63b3eeb 100644 --- a/core/pldm/test/Makefile.check +++ b/core/pldm/test/Makefile.check @@ -1,5 +1,6 @@ # -*-Makefile-*- PLDM_TEST := core/pldm/test/test-pldm-fileio \ + core/pldm/test/test-pldm-bios LCOV_EXCLUDE += $(PLDM_TEST:%=%.c) diff --git a/core/pldm/test/common/test-pldm-common.c b/core/pldm/test/common/test-pldm-common.c index 4acbfd35..8b138454 100644 --- a/core/pldm/test/common/test-pldm-common.c +++ b/core/pldm/test/common/test-pldm-common.c @@ -49,6 +49,7 @@ static inline unsigned long mftb(void); #include "../../pldm-watchdog.c" #include "../../pldm-fru-requests.c" #include "../../pldm-platform-requests.c" +#include "../../pldm-lid-files.c" #include "../../../device.c" diff --git a/core/pldm/test/test-pldm-bios.c b/core/pldm/test/test-pldm-bios.c new file mode 100644 index 00000000..53ee5a32 --- /dev/null +++ b/core/pldm/test/test-pldm-bios.c @@ -0,0 +1,289 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +// Copyright 2022 IBM Corp. + +#include "common/test-pldm-common.c" + + +#define TEST_BIOS_STRING "hb_lid_ids" +#define TEST_BIOS_STRING_HANDLE 60 +#define TEST_ATTR_HANDLE 0 +#define TEST_ATTR_STRING_MIN_LEN 0 +#define TEST_ATTR_STRING_MAX_LEN 0 +#define TEST_ATTR_STRING_DEFAULT_LEN 0 +#define TEST_ATTR_STRING_DEFAULT "" +#define TEST_VALUE_TABLE_CURRENT_STR "ATTR_PERM=81e00663,ATTR_TMP=81e00664,NVRAM=81e0066b" +#define TEST_VALID_ATTR_NAME "ATTR_TMP" + + +/* + * This function duplicates BMC functionality for Pldm self test + * It will handle pldm response message + * For now we don't have any response + */ +int pldm_test_verify_response(void *response_msg, size_t response_len) +{ + if (response_len > 0 || response_msg != NULL) + return OPAL_PARAMETER; + + return OPAL_PARAMETER; + +} + + +int pldm_test_reply_request_bios(void *request_msg, size_t request_len, + void **response_msg, size_t *response_len); + +/* + * This function duplicates BMC functionality for Pldm self test + * It generate bios table for self test based on input parameter tabletype + */ +uint32_t get_test_table_entry(uint8_t tableType, uint8_t **bios_table, + uint32_t *bios_table_length) +{ + int pad_len = 0; + uint32_t checksum = 0; + struct pldm_bios_string_table_entry *string_entry; + struct pldm_bios_table_attr_entry_string_info info; + + switch (tableType) { + + case PLDM_BIOS_STRING_TABLE: + *bios_table_length = sizeof(struct pldm_bios_string_table_entry) + + strlen(TEST_BIOS_STRING) - 1; + + /* calculate padding length */ + if (*bios_table_length % 4) + pad_len = 4 - (*bios_table_length % 4); + else + pad_len = 0; + *bios_table_length += sizeof(uint32_t) + pad_len; + + *bios_table = malloc(*bios_table_length); + if (*bios_table == NULL) + return OPAL_RESOURCE; + + memset(*bios_table, 0, *bios_table_length); + + string_entry = (struct pldm_bios_string_table_entry *)(*bios_table); + string_entry->string_handle = htole16(TEST_BIOS_STRING_HANDLE); + string_entry->string_length = htole16(strlen(TEST_BIOS_STRING)); + memcpy(string_entry->name, TEST_BIOS_STRING, string_entry->string_length); + break; + + case PLDM_BIOS_ATTR_TABLE: + + *bios_table_length = sizeof(struct pldm_bios_attr_table_entry) + + sizeof(struct attr_table_string_entry_fields) + + strlen(TEST_ATTR_STRING_DEFAULT); + + /* calculate padding length */ + if (*bios_table_length % 4) + pad_len = 4 - (*bios_table_length % 4); + else + pad_len = 0; + *bios_table_length += sizeof(uint32_t) + pad_len; + + *bios_table = malloc(*bios_table_length); + if (*bios_table == NULL) + return OPAL_RESOURCE; + + memset(*bios_table, 0, *bios_table_length); + + info.name_handle = TEST_BIOS_STRING_HANDLE; + info.read_only = 0; + info.string_type = PLDM_BIOS_STRING; + info.min_length = TEST_ATTR_STRING_MIN_LEN; + info.max_length = TEST_ATTR_STRING_MAX_LEN; + info.def_length = TEST_ATTR_STRING_DEFAULT_LEN; + info.def_string = malloc(strlen(TEST_ATTR_STRING_DEFAULT)); + if (info.def_string == NULL) + return OPAL_RESOURCE; + + memcpy((uint8_t *)info.def_string, TEST_ATTR_STRING_DEFAULT, + strlen(TEST_ATTR_STRING_DEFAULT)); + pldm_bios_table_attr_entry_string_encode(*bios_table, *bios_table_length, &info); + + free((uint8_t *)info.def_string); + break; + + case PLDM_BIOS_ATTR_VAL_TABLE: + *bios_table_length = sizeof(struct pldm_bios_attr_val_table_entry) + + sizeof(uint16_t) + sizeof(TEST_VALUE_TABLE_CURRENT_STR) - 1; + + /* calculate padding length */ + if (*bios_table_length % 4) + pad_len = 4 - (*bios_table_length % 4); + else + pad_len = 0; + *bios_table_length += sizeof(uint32_t) + pad_len; + + *bios_table = malloc(*bios_table_length); + if (*bios_table == NULL) + return OPAL_RESOURCE; + + memset(*bios_table, 0, *bios_table_length); + + pldm_bios_table_attr_value_entry_encode_string(*bios_table, *bios_table_length, + TEST_ATTR_HANDLE, PLDM_BIOS_STRING, + sizeof(TEST_VALUE_TABLE_CURRENT_STR), + TEST_VALUE_TABLE_CURRENT_STR); + break; + default: + printf("PLDM_TEST Failed: INvalid Table type"); + return OPAL_PARAMETER; + + } + + /* Add padding data */ + memset(*bios_table + *bios_table_length - sizeof(uint32_t) - pad_len, 0, pad_len); + + + checksum = htole32(pldm_crc32(*bios_table, *bios_table_length - sizeof(uint32_t) + - pad_len)); + memcpy(*bios_table + *bios_table_length - sizeof(uint32_t), (void *)&checksum, + sizeof(uint32_t)); + + return OPAL_SUCCESS; + +} + +/* + * This function duplicates BMC functionality for Pldm self test + * It will only handle PLDM_BIOS type request + * As bios test will have only pldm request of type = PLDM_BIOS + */ +int pldm_test_reply_request(void *request_msg, size_t request_len, + void **response_msg, size_t *response_len) +{ + switch (((struct pldm_msg *)request_msg)->hdr.type) { + case PLDM_BIOS: + return pldm_test_reply_request_bios(request_msg, request_len, + response_msg, response_len); + + default: + printf("PLDM_TEST Failed : hdr type %d not expected\n", + ((struct pldm_msg *)request_msg)->hdr.type); + return OPAL_PARAMETER; + } + +} + +/* + * This function duplicates BMC functionality for Pldm self test + * it handle PLDM_REQUEST for PLDM_BIOS and reply with appropriate + * PLDM_RESPONSE message + */ +int pldm_test_reply_request_bios(void *request_msg, size_t request_len, + void **response_msg, size_t *response_len) +{ + int rc; + uint32_t transfer_handle; + uint8_t transfer_op_flag, table_type; + uint8_t *bios_table; + uint32_t bios_table_length = 0; + size_t payload_length; + + + + /* + * check if command send is PLDM_GET_BIOS_TABLE then only + * reply response message and return PLDM_SUCCESS + * else return error + */ + if (((struct pldm_msg *)request_msg)->hdr.command == PLDM_GET_BIOS_TABLE) { + payload_length = request_len - sizeof(struct pldm_msg_hdr); + rc = decode_get_bios_table_req(request_msg, payload_length, &transfer_handle, + &transfer_op_flag, &table_type); + if (rc != PLDM_SUCCESS) + return OPAL_PARAMETER; + + /* get table entry to reply request on behalf on BMC for PLDM self test */ + rc = get_test_table_entry(table_type, &bios_table, &bios_table_length); + if (rc != OPAL_SUCCESS) + return rc; + + payload_length = bios_table_length + sizeof(struct pldm_get_bios_table_resp) - 1; + + *response_len = sizeof(struct pldm_msg_hdr) + + payload_length - 1; + + *response_msg = malloc(*response_len); + if (*response_msg == NULL) + return OPAL_RESOURCE; + + rc = encode_get_bios_table_resp(((struct pldm_msg *)request_msg)->hdr.instance_id, + PLDM_SUCCESS, PLDM_GET_NEXTPART, PLDM_START_AND_END, + bios_table, payload_length, *response_msg); + if (rc != PLDM_SUCCESS) + return OPAL_PARAMETER; + + free(bios_table); + return OPAL_SUCCESS; + } else + return OPAL_PARAMETER; + + return OPAL_SUCCESS; +} + + +int main(void) +{ + size_t rc; + char *lid; + char name[] = "Error"; + struct blocklevel_device *bl; + + /* + * Attempt to call pldm_bios_find_lid_by_attr_name() + * before pldm_bios_init() return error OPAL_HARDWARE + */ + rc = pldm_bios_find_lid_by_attr_name(TEST_VALID_ATTR_NAME, &lid); + if (rc != OPAL_HARDWARE) { + printf("PLDM_TEST Failed: pldm_bios_find_lid_by_attr_name", + " called before pldm_bios_init.", + " expected=%d received=%d\n", OPAL_HARDWARE, rc); + return rc; + } + + /* Init Pldm bios */ + rc = pldm_bios_init(); + if (rc != OPAL_SUCCESS) { + printf("PLDM_TEST Failed : pldm_bios_init failed received=%d\n", rc); + return rc; + } + + /* + * Attempt to call pldm_bios_find_lid_by_attr_name() + * when name argument not present return error OPAL_PARAMETER + */ + rc = pldm_bios_find_lid_by_attr_name(name, &lid); + if (rc != OPAL_PARAMETER) { + + printf("PLDM_TEST Failed : pldm_bios_find_lid_by_attr_name", + " called when name argument that is not present.", + " expected=%d received=%d\n", OPAL_PARAMETER, rc); + return rc; + } + + /* + * Attempt to call pldm_bios_find_lid_by_attr_name() + * when name argument present return OPAL_SUCCESS + */ + rc = pldm_bios_find_lid_by_attr_name(TEST_VALID_ATTR_NAME, &lid); + if (rc != OPAL_SUCCESS) { + printf("PLDM_TEST Failed : pldm_bios_find_lid_by_attr_name", + " called when name argument that is present.", + " expected=%d received=%d\n", OPAL_PARAMETER, rc); + return rc; + } + + + /* Init pldm_lid_files_init */ + rc = pldm_lid_files_init(&bl); + if (rc != OPAL_SUCCESS) { + printf("PLDM_TEST Failed : pldm_lid_files_init received=%d\n", rc); + return rc; + } + return 0; +} +