diff --git a/teeio-validator/include/cxl_ide.h b/teeio-validator/include/cxl_ide.h index 56ac877..561c848 100644 --- a/teeio-validator/include/cxl_ide.h +++ b/teeio-validator/include/cxl_ide.h @@ -18,7 +18,7 @@ #define MAX_CXL_KSETGO_CASE_ID 1 #define MAX_CXL_KSETSTOP_CASE_ID 1 #define MAX_CXL_GETKEY_CASE_ID 1 -#define MAX_CXL_FULL_CASE_ID 1 +#define MAX_CXL_FULL_CASE_ID 2 #define MAX_CXL_CASE_ID \ (MAX(MAX_CXL_QUERY_CASE_ID, MAX(MAX_CXL_KEYPROG_CASE_ID, MAX(MAX_CXL_KSETGO_CASE_ID, MAX(MAX_CXL_KSETSTOP_CASE_ID, MAX(MAX_CXL_GETKEY_CASE_ID, MAX_CXL_FULL_CASE_ID)))))) diff --git a/teeio-validator/library/cxl_ide_test_lib/CMakeLists.txt b/teeio-validator/library/cxl_ide_test_lib/CMakeLists.txt index c10cb44..5a7b92b 100644 --- a/teeio-validator/library/cxl_ide_test_lib/CMakeLists.txt +++ b/teeio-validator/library/cxl_ide_test_lib/CMakeLists.txt @@ -22,6 +22,7 @@ SET(src_cxl_ide_test_lib # test_case test_case/ide_km_common.c test_case/test_case_full.c + test_case/test_case_keyrefresh.c test_case/test_case_query.c test_case/test_case_key_prog.c test_case/test_case_kset_go.c diff --git a/teeio-validator/library/cxl_ide_test_lib/cxl_ide_common.c b/teeio-validator/library/cxl_ide_test_lib/cxl_ide_common.c index 0093ce5..64a8647 100644 --- a/teeio-validator/library/cxl_ide_test_lib/cxl_ide_common.c +++ b/teeio-validator/library/cxl_ide_test_lib/cxl_ide_common.c @@ -75,7 +75,7 @@ ide_test_group_funcs_t m_cxl_ide_group_funcs = { cxl_ide_test_group_teardown }; -#define CXL_IDE_TEST_CLASS_CASE_NAMES "IdeStream" +#define CXL_IDE_TEST_CLASS_CASE_NAMES "IdeStream,KeyRefresh" ide_test_case_name_t m_cxl_ide_test_case_names[] = { {"Query", "1,2", CXL_MEM_IDE_TEST_CASE_QUERY }, {"KeyProg", "1,2,3,4,5,6,7,8,9", CXL_MEM_IDE_TEST_CASE_KEYPROG }, @@ -116,7 +116,8 @@ ide_test_case_funcs_t m_cxl_ide_get_key_cases[MAX_CXL_GETKEY_CASE_ID] = { }; ide_test_case_funcs_t m_cxl_ide_test_full_cases[MAX_CXL_FULL_CASE_ID] = { - { cxl_ide_test_full_ide_stream_setup, cxl_ide_test_full_ide_stream_run, cxl_ide_test_full_ide_stream_teardown, true }, // IdeStream + { cxl_ide_test_full_ide_stream_setup, cxl_ide_test_full_ide_stream_run, cxl_ide_test_full_ide_stream_teardown, false }, // IdeStream + { cxl_ide_test_keyrefresh_setup, cxl_ide_test_keyrefresh_run, cxl_ide_test_keyrefresh_teardown, false }, // KeyRefresh }; TEEIO_TEST_CASES m_cxl_ide_test_case_funcs[CXL_MEM_IDE_TEST_CASE_NUM] = { diff --git a/teeio-validator/library/cxl_ide_test_lib/include/cxl_ide_test_common.h b/teeio-validator/library/cxl_ide_test_lib/include/cxl_ide_test_common.h index 6c880cd..6e43492 100644 --- a/teeio-validator/library/cxl_ide_test_lib/include/cxl_ide_test_common.h +++ b/teeio-validator/library/cxl_ide_test_lib/include/cxl_ide_test_common.h @@ -15,6 +15,11 @@ bool cxl_ide_test_full_ide_stream_setup(void *test_context); bool cxl_ide_test_full_ide_stream_run(void *test_context); bool cxl_ide_test_full_ide_stream_teardown(void *test_context); +// Key Refresh +bool cxl_ide_test_keyrefresh_setup(void *test_context); +bool cxl_ide_test_keyrefresh_run(void *test_context); +bool cxl_ide_test_keyrefresh_teardown(void *test_context); + // Query bool cxl_ide_test_query_1_setup(void *test_context); bool cxl_ide_test_query_1_run(void *test_context); diff --git a/teeio-validator/library/cxl_ide_test_lib/test_case/ide_km_common.c b/teeio-validator/library/cxl_ide_test_lib/test_case/ide_km_common.c index 2ce3787..142a408 100644 --- a/teeio-validator/library/cxl_ide_test_lib/test_case/ide_km_common.c +++ b/teeio-validator/library/cxl_ide_test_lib/test_case/ide_km_common.c @@ -164,7 +164,8 @@ bool cxl_setup_ide_stream(void *doe_context, void *spdm_context, uint8_t port_index, ide_common_test_port_context_t *upper_port, ide_common_test_port_context_t *lower_port, - bool skip_ksetgo, uint32_t config_bitmap) + bool skip_ksetgo, uint32_t config_bitmap, + bool set_link_enc_enable) { bool result; uint8_t kp_ack_status; @@ -299,7 +300,9 @@ bool cxl_setup_ide_stream(void *doe_context, void *spdm_context, TEEIO_DEBUG((TEEIO_DEBUG_INFO, "key_set_go RX\n")); // Set LinkEncEnable bit - cxl_cfg_rp_linkenc_enable(kcbar_ptr, true); + if(set_link_enc_enable) { + cxl_cfg_rp_linkenc_enable(kcbar_ptr, true); + } // Set StartTrigger bit cxl_cfg_rp_start_trigger(kcbar_ptr, true); @@ -320,9 +323,8 @@ bool cxl_setup_ide_stream(void *doe_context, void *spdm_context, // wait for 10 ms for device to get ide ready libspdm_sleep(10 * 1000); + printf("cxl_setup_ide_stream is done.\n"); dump_cxl_ide_status(upper_port, lower_port); - printf("cxl_setup_ide_stream is done. Press any key to continue.\n"); - getchar(); return true; } \ No newline at end of file diff --git a/teeio-validator/library/cxl_ide_test_lib/test_case/test_case_full.c b/teeio-validator/library/cxl_ide_test_lib/test_case/test_case_full.c index e0d57f7..393b5c9 100644 --- a/teeio-validator/library/cxl_ide_test_lib/test_case/test_case_full.c +++ b/teeio-validator/library/cxl_ide_test_lib/test_case/test_case_full.c @@ -27,7 +27,8 @@ bool cxl_setup_ide_stream(void *doe_context, void *spdm_context, uint8_t stream_id, uint8_t port_index, ide_common_test_port_context_t *upper_port, ide_common_test_port_context_t *lower_port, - bool skip_ksetgo, uint32_t config_bitmap); + bool skip_ksetgo, uint32_t config_bitmap, + bool set_link_enc_enable); bool cxl_stop_ide_stream(void *doe_context, void *spdm_context, uint32_t *session_id, uint8_t *kcbar_addr, uint8_t stream_id, @@ -57,7 +58,7 @@ bool cxl_ide_test_full_ide_stream_setup(void *test_context) return cxl_setup_ide_stream(group_context->doe_context, group_context->spdm_context, &group_context->session_id, upper_port->mapped_kcbar_addr, group_context->stream_id, 0, - upper_port, lower_port, false, configuration->bit_map); + upper_port, lower_port, false, configuration->bit_map, true); } bool cxl_ide_test_full_ide_stream_run(void *test_context) diff --git a/teeio-validator/library/cxl_ide_test_lib/test_case/test_case_keyrefresh.c b/teeio-validator/library/cxl_ide_test_lib/test_case/test_case_keyrefresh.c new file mode 100644 index 0000000..c820d7d --- /dev/null +++ b/teeio-validator/library/cxl_ide_test_lib/test_case/test_case_keyrefresh.c @@ -0,0 +1,153 @@ +/** + * Copyright Notice: + * Copyright 2023-2024 Intel. All rights reserved. + * License: BSD 3-Clause License. + **/ + +#include +#include +#include + +#include "assert.h" +#include "hal/base.h" +#include "hal/library/debuglib.h" + +#include "hal/library/memlib.h" +#include "library/spdm_requester_lib.h" +#include "library/cxl_ide_km_requester_lib.h" +#include "ide_test.h" +#include "helperlib.h" +#include "teeio_debug.h" +#include "cxl_ide_lib.h" +#include "cxl_ide_test_common.h" + +// setup cxl ide stream +bool cxl_setup_ide_stream(void *doe_context, void *spdm_context, + uint32_t *session_id, uint8_t *kcbar_addr, + uint8_t stream_id, uint8_t port_index, + ide_common_test_port_context_t *upper_port, + ide_common_test_port_context_t *lower_port, + bool skip_ksetgo, uint32_t config_bitmap, + bool set_link_enc_enable); +// stop cxl ide stream +bool cxl_stop_ide_stream(void *doe_context, void *spdm_context, + uint32_t *session_id, uint8_t *kcbar_addr, + uint8_t stream_id, + uint8_t port_index, + ide_common_test_port_context_t *upper_port, + ide_common_test_port_context_t *lower_port); + +bool cxl_ide_test_keyrefresh_setup(void *test_context) +{ + ide_common_test_case_context_t *case_context = (ide_common_test_case_context_t *)test_context; + TEEIO_ASSERT(case_context); + TEEIO_ASSERT(case_context->signature == CASE_CONTEXT_SIGNATURE); + + cxl_ide_test_group_context_t *group_context = (cxl_ide_test_group_context_t *)case_context->group_context; + TEEIO_ASSERT(group_context); + TEEIO_ASSERT(group_context->signature == GROUP_CONTEXT_SIGNATURE); + + ide_common_test_port_context_t* upper_port = &group_context->upper_port; + ide_common_test_port_context_t* lower_port = &group_context->lower_port; + + // An ide_stream is first setup so that key_refresh can be tested in run. + IDE_TEST_CONFIGURATION *configuration = get_configuration_by_id(group_context->suite_context->test_config, group_context->config_id); + TEEIO_ASSERT(configuration); + + return cxl_setup_ide_stream(group_context->doe_context, group_context->spdm_context, + &group_context->session_id, upper_port->mapped_kcbar_addr, + group_context->stream_id, 0, + upper_port, lower_port, false, configuration->bit_map, true); +} + +bool cxl_ide_test_keyrefresh_run(void *test_context) +{ + ide_common_test_case_context_t *case_context = (ide_common_test_case_context_t *)test_context; + TEEIO_ASSERT(case_context); + TEEIO_ASSERT(case_context->signature == CASE_CONTEXT_SIGNATURE); + + cxl_ide_test_group_context_t *group_context = (cxl_ide_test_group_context_t *)case_context->group_context; + TEEIO_ASSERT(group_context); + TEEIO_ASSERT(group_context->signature == GROUP_CONTEXT_SIGNATURE); + + ide_common_test_port_context_t* upper_port = &group_context->upper_port; + ide_common_test_port_context_t* lower_port = &group_context->lower_port; + INTEL_KEYP_CXL_ROOT_COMPLEX_KCBAR *kcbar_ptr = (INTEL_KEYP_CXL_ROOT_COMPLEX_KCBAR *)upper_port->mapped_kcbar_addr; + + IDE_TEST_CONFIGURATION *configuration = get_configuration_by_id(group_context->suite_context->test_config, group_context->config_id); + TEEIO_ASSERT(configuration); + + int cmd = 0; + bool res = true; + + while(true){ + TEEIO_PRINT(("\n")); + TEEIO_PRINT(("Print host registers.\n")); + cxl_dump_kcbar(kcbar_ptr); + // dump CXL IDE Capability in memcache reg block + cxl_dump_ide_status(upper_port->cxl_data.memcache.cap_headers, upper_port->cxl_data.memcache.cap_headers_cnt, upper_port->cxl_data.memcache.mapped_memcache_reg_block); + + TEEIO_PRINT(("\n")); + TEEIO_PRINT(("Print device registers.\n")); + // dump CXL IDE Capability in memcache reg block + cxl_dump_ide_status(lower_port->cxl_data.memcache.cap_headers, lower_port->cxl_data.memcache.cap_headers_cnt, lower_port->cxl_data.memcache.mapped_memcache_reg_block); + + TEEIO_PRINT(("Press 'q' to quit test or any other keys to key_refresh.\n")); + cmd = getchar(); + if(cmd == 'q' || cmd == 'Q') { + break; + } else { + res = cxl_setup_ide_stream(group_context->doe_context, group_context->spdm_context, + &group_context->session_id, upper_port->mapped_kcbar_addr, + group_context->stream_id, 0, + upper_port, lower_port, false, configuration->bit_map, false); + + if(!res) { + break; + } + } + } + + case_context->result = res ? IDE_COMMON_TEST_CASE_RESULT_SUCCESS : IDE_COMMON_TEST_CASE_RESULT_FAILED; + + return res; +} + +bool cxl_ide_test_keyrefresh_teardown(void *test_context) +{ + bool ret = false; + + ide_common_test_case_context_t *case_context = (ide_common_test_case_context_t *)test_context; + TEEIO_ASSERT(case_context); + TEEIO_ASSERT(case_context->signature == CASE_CONTEXT_SIGNATURE); + + cxl_ide_test_group_context_t *group_context = case_context->group_context; + TEEIO_ASSERT(group_context); + TEEIO_ASSERT(group_context->signature == GROUP_CONTEXT_SIGNATURE); + + ide_common_test_port_context_t *upper_port = &group_context->upper_port; + ide_common_test_port_context_t *lower_port = &group_context->lower_port; + + CXL_QUERY_RESP_CAPS dev_caps = {.raw = lower_port->cxl_data.query_resp.caps}; + TEEIO_DEBUG((TEEIO_DEBUG_INFO, "dev_caps.k_set_stop_capable = %d\n", dev_caps.k_set_stop_capable)); + + // send KSetStop if supported. + if(dev_caps.k_set_stop_capable == 1) { + ret = cxl_stop_ide_stream(group_context->doe_context, group_context->spdm_context, + &group_context->session_id, upper_port->mapped_kcbar_addr, + group_context->stream_id, 0, + upper_port, lower_port); + if(!ret) { + TEEIO_DEBUG((TEEIO_DEBUG_ERROR, "cxl_stop_ide_stream failed.\n")); + return false; + } + } else { + TEEIO_DEBUG((TEEIO_DEBUG_INFO, "KSetStop is not supported.\n")); + } + + // clear LinkEncEnable on the RootPort side + INTEL_KEYP_CXL_ROOT_COMPLEX_KCBAR *kcbar_ptr = (INTEL_KEYP_CXL_ROOT_COMPLEX_KCBAR *)upper_port->mapped_kcbar_addr; + cxl_cfg_rp_linkenc_enable(kcbar_ptr, false); + + return true; +}