From patchwork Wed May 18 07:43:04 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: 1632646 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=HWOErj4U; 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 4L34l76JPcz9sBB for ; Wed, 18 May 2022 17:44:51 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4L34l73Ln1z3c9V for ; Wed, 18 May 2022 17:44:51 +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=HWOErj4U; 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=HWOErj4U; 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 4L34jy6cxpz3c9M for ; Wed, 18 May 2022 17:43:50 +1000 (AEST) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24I7TrsY029435 for ; Wed, 18 May 2022 07:43:48 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=KlWmCWUmNlvXlXGV2OYgVRfMocBoUglgcEG9/+l2Fqo=; b=HWOErj4U2Ip8kLwki0V6ZA2DQE5SQ9U+9Y+UyAjhaH8urPVW4doBkTggSfIpqjJzKMN4 UeK6l38IF/GSptXIQ4LC3ngxcWTuExb9WgBs+MQ3YcGbEQApVn+0ZYJDhrRTUSyD8x7Q 6Ojj/97Y5S2dZkJ2GRGGlb5v/dat3G1jL+FH2b5t9HtQsq+Bu2FihISQjnbUPSfSYxz0 dDJHj5B9Qpj3oO0JGEbdWsRpw+UsWshkZri2OrIGQbY3RWhNdMEiT5KXCsZ2oLpUySdD diwfRqNd44S+SEhmYaVj+VBpsPmHrnrzYYEKgppolXZCJZ4hRGO87Kq1uVB+xHJSHcsj zw== Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3g4vf0rarr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 18 May 2022 07:43:48 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 24I7gQpC002845 for ; Wed, 18 May 2022 07:43:46 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma03ams.nl.ibm.com with ESMTP id 3g2429db03-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 18 May 2022 07:43:46 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 24I7TpEL27197948 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 18 May 2022 07:29:51 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 52D7D11C052; Wed, 18 May 2022 07:43:43 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 707CA11C04C; Wed, 18 May 2022 07:43:42 +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:42 +0000 (GMT) From: Abhishek Singh Tomar To: skiboot@lists.ozlabs.org Date: Wed, 18 May 2022 13:13:04 +0530 Message-Id: <20220518074304.42497-10-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: KiCtAy93tfkmRWApp48qsRCH5IwhhG8e X-Proofpoint-ORIG-GUID: KiCtAy93tfkmRWApp48qsRCH5IwhhG8e 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 priorityscore=1501 bulkscore=0 spamscore=0 adultscore=0 suspectscore=0 mlxscore=0 phishscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205180037 Subject: [Skiboot] [PATCH v3 9/9] core/pldm/test : Retrieve the BMC information with the FRU PLDM message 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" This patch test PLDM command PLDM_GET_FRU_RECORD_BY_OPTION codeflow by retrieving BMC version information Signed-off-by: Abhishek Singh Tomar --- core/pldm/test/test-pldm-fru.c | 144 +++++++++++++++++++++++++++++++-- 1 file changed, 139 insertions(+), 5 deletions(-) diff --git a/core/pldm/test/test-pldm-fru.c b/core/pldm/test/test-pldm-fru.c index 2893248e..56cf59e5 100644 --- a/core/pldm/test/test-pldm-fru.c +++ b/core/pldm/test/test-pldm-fru.c @@ -10,6 +10,10 @@ bool get_fru_record_table_in_progress; int pldm_test_verify_response(void *response_msg, size_t response_len); int pldm_test_verify_response_fru(void *response_msg, size_t response_len); int test_fru_table_metadata_request(void); +int pldm_test_reply_request_fru(void *request_msg, size_t request_len, + void **response_msg, size_t *response_len); +int pldm_test_generate_reply_field_type_version(uint8_t record_type, uint8_t field_type, + uint8_t **fru_table, size_t *fru_table_size); /* @@ -94,7 +98,69 @@ int pldm_test_verify_response_fru(void *response_msg, size_t response_len) } +int pldm_test_reply_request_fru(void *request_msg, size_t request_len, + void **response_msg, size_t *response_len) +{ + int rc, payload_len = 0; + uint32_t transfer_handle; + uint16_t fru_table_handle; + uint16_t record_set_identifier; + uint8_t record_type; + uint8_t field_type; + uint8_t transfer_op_flag; + uint8_t *fru_ds; + size_t fru_ds_size; + + /* Check PLDM command and reply with appropriate reply */ + switch (((struct pldm_msg *)request_msg)->hdr.command) { + case PLDM_GET_FRU_RECORD_BY_OPTION: + payload_len = request_len - sizeof(struct pldm_msg_hdr); + rc = decode_get_fru_record_by_option_req(request_msg, payload_len, + &transfer_handle, &fru_table_handle, &record_set_identifier, + &record_type, &field_type, &transfer_op_flag); + if (rc != PLDM_SUCCESS) + return OPAL_PARAMETER; + /* + * Test if field type and record type is as expected i.e. + * field type = PLDM_FRU_FIELD_TYPE_VERSION and + * record_type == PLDM_FRU_RECORD_TYPE_GENERAL + * else return error + */ + if (field_type == PLDM_FRU_FIELD_TYPE_VERSION && + record_type == PLDM_FRU_RECORD_TYPE_GENERAL) { + + /* + * generate the fru data structure to reply request + * on behalf on BMC for PLDM self test + */ + rc = pldm_test_generate_reply_field_type_version( + PLDM_FRU_RECORD_TYPE_GENERAL, + PLDM_FRU_FIELD_TYPE_VERSION, &fru_ds, &fru_ds_size); + if (rc != OPAL_SUCCESS) + return rc; + + payload_len = fru_ds_size + + sizeof(struct pldm_get_fru_record_by_option_resp) - 1; + *response_len = sizeof(struct pldm_msg_hdr) + payload_len; + *response_msg = malloc(*response_len); + + rc = encode_get_fru_record_by_option_resp( + ((struct pldm_msg *)request_msg)->hdr.instance_id, + PLDM_SUCCESS, PLDM_GET_NEXTPART, PLDM_START_AND_END, + fru_ds, fru_ds_size, *response_msg, payload_len); + if (rc != PLDM_SUCCESS) + return rc; + free(fru_ds); + return OPAL_SUCCESS; + } else + return OPAL_PARAMETER; + break; + default: + return PLDM_ERROR_INVALID_DATA; + + } +} /* * This function duplicates BMC functionality for Pldm self test @@ -104,12 +170,15 @@ int pldm_test_verify_response_fru(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) { - if (request_msg != NULL && response_msg != NULL) { - (void)request_len; - (void)*response_len; + switch (((struct pldm_msg *)request_msg)->hdr.type) { + case PLDM_FRU: + return pldm_test_reply_request_fru(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; } - return OPAL_PARAMETER; - } /* @@ -156,12 +225,64 @@ int test_fru_table_metadata_request(void) } +/* + * This function duplicates BMC functionality for Pldm self test + * It generate reply for PLDM_GET_FRU_RECORD_BY_OPTION for self test. + * It generates fru Dta structure with BMC version tlv + */ +int pldm_test_generate_reply_field_type_version(uint8_t record_type, uint8_t field_type, + uint8_t **fru_table, size_t *fru_table_size) +{ + struct pldm_fru_record_tlv *tlv; + int tlv_size, rc; + size_t curr_size = 0; + size_t pad_bytes = 0; + uint32_t checksum; + + if (field_type == PLDM_FRU_FIELD_TYPE_VERSION && + record_type == PLDM_FRU_RECORD_TYPE_GENERAL) { + + tlv_size = sizeof(struct pldm_fru_record_tlv) + strlen(TEST_BMC_VERSION) - 1; + tlv = malloc(tlv_size); + tlv->type = PLDM_FRU_FIELD_TYPE_VERSION; + tlv->length = strlen(TEST_BMC_VERSION); + memcpy(tlv->value, TEST_BMC_VERSION, tlv->length); + + *fru_table_size = sizeof(struct pldm_fru_record_data_format) + tlv->length - 1; + /* Culculate pad bytes in fru */ + if (*fru_table_size % 4) + pad_bytes = 4 - (*fru_table_size % 4); + else + pad_bytes = 0; + + *fru_table = malloc(*fru_table_size + pad_bytes + sizeof(uint32_t)); + rc = encode_fru_record(*fru_table, *fru_table_size, &curr_size, 0, + PLDM_FRU_RECORD_TYPE_GENERAL, 1, 1, (uint8_t *)tlv, tlv_size); + if (rc != PLDM_SUCCESS) + return OPAL_PARAMETER; + *fru_table_size += pad_bytes + sizeof(uint32_t); + + /* Pad with 0 */ + memset(*fru_table + curr_size, 0, pad_bytes); + + checksum = htole32(pldm_crc32(*fru_table, *fru_table_size - sizeof(uint32_t))); + memcpy(*fru_table + curr_size + pad_bytes, (void *)&checksum, sizeof(uint32_t)); + free(tlv); + } else + return OPAL_PARAMETER; + + return OPAL_SUCCESS; +} + + + int main(void) { int rc; void *fru_record_table; uint32_t fru_record_table_size; + struct variable_field fru_structure_data; /* * Get fru table when fru table not created @@ -188,6 +309,19 @@ int main(void) return rc; } + + /* retrieve the bmc information with + * "FRU Field Type": Version + * "FRU Record Set Identifier": 1, + * "FRU Record Type": "General(1)" + */ + rc = pldm_fru_get_record_by_option(0, 1, PLDM_FRU_RECORD_TYPE_GENERAL, + PLDM_FRU_FIELD_TYPE_VERSION, &fru_structure_data); + if (rc != OPAL_SUCCESS) { + printf("PLDM_TEST Failed : pldm_fru_get_record_by_option return=%d\n", rc); + return rc; + } + return OPAL_SUCCESS; }