From patchwork Wed May 18 07:42:57 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: 1632639 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=kKI6eGXh; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L34k718Jrz9sGC for ; Wed, 18 May 2022 17:43:59 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4L34k70L7Wz3c1K for ; Wed, 18 May 2022 17:43:59 +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=kKI6eGXh; 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.156.1; 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=kKI6eGXh; dkim-atps=neutral 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 4L34jq28Mlz3bjq for ; Wed, 18 May 2022 17:43:43 +1000 (AEST) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24I7g0Uf012611 for ; Wed, 18 May 2022 07:43:41 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=we36Z+6fPtl3MBr6ua2kKr9ND/ItO7k64d2FoYOpQKQ=; b=kKI6eGXhUJ9Tv8lbUyKHdrp8ouod3hGYCXhGiqGmKBjzwHbwzWAtlO4Dn6OU7+qk23Ix EB8oh6pjReBlMQYk+wbC2oWYNkH2gqgtB4oCj2+EVRvkeELpwJNLStG7N3NN3+efuvS5 BtsqIoXQBsKfbtwBnnjTd6lmPvoCA29OJIBP7TY5X0zOGOvmhQ9azWzo5yhyut//OzYp 8jI1UnAsCGrvcEeGRtUEsvcgeE6lqhbVkf6XeNANZlLIbUrRJdYl8oqjZOn+yr/BV92w 4FqLXoiycrzAEjdNYQGI4x5NbXGbZy3syxB+l99FN9/beGVQzlFDRoUmg5QsrxO6fuAk wA== Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3g4vms80tm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 18 May 2022 07:43:40 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 24I7grCr001572 for ; Wed, 18 May 2022 07:43:38 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma01fra.de.ibm.com with ESMTP id 3g2428vafg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 18 May 2022 07:43:38 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 24I7h0Hh34537960 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 18 May 2022 07:43:01 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8802E11C050; Wed, 18 May 2022 07:43:35 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CCC8411C04C; Wed, 18 May 2022 07:43:34 +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:34 +0000 (GMT) From: Abhishek Singh Tomar To: skiboot@lists.ozlabs.org Date: Wed, 18 May 2022 13:12:57 +0530 Message-Id: <20220518074304.42497-3-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: uKUqtWGWUwb9njRxD-Vn85SqDP5LynBE X-Proofpoint-ORIG-GUID: uKUqtWGWUwb9njRxD-Vn85SqDP5LynBE 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 mlxscore=0 suspectscore=0 adultscore=0 bulkscore=0 mlxlogscore=999 phishscore=0 clxscore=1015 lowpriorityscore=0 spamscore=0 impostorscore=0 priorityscore=1501 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205180037 Subject: [Skiboot] [PATCH v3 2/9] core/pldm/test : Initialize pldm file I/O 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" The patch contains a self-test implementation for PLDM_OEM type message support that is used for inband file I/O. This patch tests code flow for the PLDM command PLDM_GET_FILE_TABLE that is used to retrieve the file table which contains the list of lid files available and their attributes. Signed-off-by: Abhishek Singh Tomar --- core/pldm/pldm.h | 2 +- core/pldm/test/Makefile.check | 43 ++++++++ core/pldm/test/test-pldm-fileio.c | 174 ++++++++++++++++++++++++++++++ 3 files changed, 218 insertions(+), 1 deletion(-) create mode 100644 core/pldm/test/Makefile.check create mode 100644 core/pldm/test/test-pldm-fileio.c diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 81df9f8b..5ac9c443 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -45,7 +45,7 @@ extern int watchdog_period_sec; * @example enum_bit(1) = 0x00000002 * @example enum_bit(4) = 0x00000010 */ -inline uint32_t enum_bit(unsigned int enumeration) +extern inline uint32_t enum_bit(unsigned int enumeration) { return 1 << enumeration; } diff --git a/core/pldm/test/Makefile.check b/core/pldm/test/Makefile.check new file mode 100644 index 00000000..7af66ccf --- /dev/null +++ b/core/pldm/test/Makefile.check @@ -0,0 +1,43 @@ +# -*-Makefile-*- +PLDM_TEST := core/pldm/test/test-pldm-fileio \ + +LCOV_EXCLUDE += $(PLDM_TEST:%=%.c) + +.PHONY : core-pldm-check core-pldm-coverage +core-pldm-check: $(PLDM_TEST:%=%-check) +core-pldm-coverage: $(PLDM_TEST:%=%-gcov-run) +HOSTCFLAG_PLDM:= $(filter-out -Wdeclaration-after-statement,$(HOSTCFLAGS)) +HOSTCFLAG_PLDM:= $(filter-out -Wstrict-prototypes,$(HOSTCFLAG_PLDM)) +HOSTCFLAG_PLDM:= $(filter-out -Wjump-misses-init,$(HOSTCFLAG_PLDM)) +HOSTCFLAG_PLDM:= $(filter-out -Wmissing-prototypes,$(HOSTCFLAG_PLDM)) +HOSTCFLAG_PLDM:= $(filter-out -Wmissing-declarations,$(HOSTCFLAG_PLDM)) +HOSTCFLAG_PLDM += -Wno-format + +check: core-pldm-check +coverage: core-pldm-coverage + +$(PLDM_TEST:%=%-gcov-run) : %-run: % + $(call Q, TEST-COVERAGE ,$< , $<) + +$(PLDM_TEST:%=%-check) : %-check: % + $(call Q, RUN-TEST ,$(VALGRIND) $<, $<) + +core/test/stubs.o: core/test/stubs.c + $(call Q, HOSTCC ,$(HOSTCC) $(HOSTCFLAGS) -I . -I include -Wno-error=attributes -g -c -o core/test/stubs.o core/test/stubs.c, $<) + +$(PLDM_TEST) : % : %.c core/test/stubs.o + $(call Q, HOSTCC ,$(HOSTCC) $(HOSTCFLAG_PLDM) -O0 -g -I include -I . -I pldm/libpldm/ -I libfdt -o $@ $< core/test/stubs.o -g, $<) + +$(PLDM_TEST:%=%-gcov): %-gcov : %.c % + $(call Q, HOSTCC ,$(HOSTCC) $(HOSTFLAG_PLDM) $(HOSTGCOVCFLAGS) -I include -I . -I pldm/libpldm/ -I libfdt -lgcov -o $@ $<, $<) + +$(PLDM_TEST:%=%-gcov): % : $(%.d:-gcov=) + +-include $(wildcard core/pldm/test/*.d) + +clean: pldm-test-clean + +pldm-test-clean: + $(RM) -f core/pldm/test/*.[od] $(PLDM_TEST) $(PLDM_TEST:%=%-gcov) + $(RM) -f *.gcda *.gcno skiboot.info + $(RM) -rf coverage-report diff --git a/core/pldm/test/test-pldm-fileio.c b/core/pldm/test/test-pldm-fileio.c new file mode 100644 index 00000000..e14f6df7 --- /dev/null +++ b/core/pldm/test/test-pldm-fileio.c @@ -0,0 +1,174 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +// Copyright 2022 IBM Corp. + + +#include "common/test-pldm-common.c" +#define TEST_FILE_IO_NAME "81e0066b.lid" +#define TEST_FILE_IO_HANDLE 11 +#define TEST_FILE_IO_LENGTH 50 +#define TEST_FILE_IO_BUF1 "This is Test buffer Open power Foundation" + +uint32_t get_test_filetable_entry(uint8_t **file_attr_table, int *size); +int pldm_test_reply_request_file_io(void *request_msg, size_t request_len, + void **response_msg, size_t *response_len); + +int pldm_test_reply_request(void *request_msg, size_t request_len, + void **response_msg, size_t *response_len); + + +/* + * 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; + +} + +/* + * This function duplicates BMC functionality for Pldm self test + * This Genrate Filetable entry for self test + * The file table contains the list of files available and + * their attributes. + * + * Ex: + * { + * "FileHandle": "11", + * "FileNameLength": 12, + * "FileName": "81e0066b.lid", + * "FileSize": 589824, + * "FileTraits": 6 + * } + */ +uint32_t get_test_filetable_entry(uint8_t **file_attr_table, int *size) +{ + struct pldm_file_attr_table_entry *pldm_file_attr_table_entry; + uint8_t FileName[] = TEST_FILE_IO_NAME; + uint32_t file_length = TEST_FILE_IO_LENGTH; + + /* calculate sizeof whole struct */ + *size = sizeof(struct pldm_file_attr_table_entry *) + strlen(FileName) + + sizeof(file_length) - 1; + *file_attr_table = malloc(*size); + if (*file_attr_table == NULL) + return OPAL_RESOURCE; + + pldm_file_attr_table_entry = (struct pldm_file_attr_table_entry *)*file_attr_table; + pldm_file_attr_table_entry->file_handle = TEST_FILE_IO_HANDLE; + pldm_file_attr_table_entry->file_name_length = strlen(FileName); + memcpy(pldm_file_attr_table_entry->file_attr_table_nst, FileName, + strlen(FileName)); + + memcpy(pldm_file_attr_table_entry->file_attr_table_nst + strlen(FileName), + (uint8_t *)&file_length, sizeof(file_length)); + + return OPAL_SUCCESS; +} + +/* + * This function duplicates BMC functionality for Pldm self test + * It will only handle PLDM_OEM type request + * As fileio test will have only pldm request of type = PLDM_OEM + */ +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_OEM: + return pldm_test_reply_request_file_io(request_msg, request_len, + response_msg, response_len); + default: + printf("PLDM_TEST : 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 tries to handle PLDM_REQUEST for fileio and reply with appropriate PLDM_RESPONSE + * message + */ +int pldm_test_reply_request_file_io(void *request_msg, size_t request_len, + void **response_msg, size_t *response_len) +{ + int rc; + int payload_len = 0; + uint32_t transfer_handle; + uint8_t transfer_opflag; + uint8_t table_type; + uint8_t *file_attr_table; + uint32_t table_size; + + + /* check command received and reply with appropriate pldm response message */ + switch (((struct pldm_msg *)request_msg)->hdr.command) { + case PLDM_GET_FILE_TABLE: + + payload_len = request_len - sizeof(struct pldm_msg_hdr); + + rc = decode_get_file_table_req(request_msg, payload_len, &transfer_handle, + &transfer_opflag, &table_type); + if (rc != PLDM_SUCCESS) + return OPAL_PARAMETER; + + /* Get Filetable entry for self test */ + rc = get_test_filetable_entry(&file_attr_table, &table_size); + if (rc != OPAL_SUCCESS) + return OPAL_PARAMETER; + + *response_len = sizeof(struct pldm_msg_hdr) + + sizeof(struct pldm_get_file_table_resp) + + table_size - 1; + *response_msg = malloc(*response_len); + if (*response_msg == NULL) + return OPAL_RESOURCE; + + + rc = encode_get_file_table_resp(((struct pldm_msg *)request_msg)->hdr.instance_id, + PLDM_SUCCESS, PLDM_GET_NEXTPART, PLDM_START_AND_END, + file_attr_table, table_size, *response_msg); + if (rc != PLDM_SUCCESS) + return OPAL_PARAMETER; + + free(file_attr_table); + + break; + + default: + return OPAL_PARAMETER; + + } + + return OPAL_SUCCESS; + + + +} + + +int main(void) +{ + size_t rc; + + + /* Init PLDM File IO */ + rc = pldm_file_io_init(); + if (rc != OPAL_SUCCESS) { + printf("PLDM_TEST : pldm_file_io_init failed"); + return rc; + } + + return OPAL_SUCCESS; +} + +