Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cxl key refresh #161

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion teeio-validator/include/cxl_ide.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))))))

Expand Down
1 change: 1 addition & 0 deletions teeio-validator/library/cxl_ide_test_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions teeio-validator/library/cxl_ide_test_lib/cxl_ide_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 5 additions & 17 deletions teeio-validator/library/cxl_ide_test_lib/test_case/ide_km_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,25 +150,15 @@ bool cxl_stop_ide_stream(void *doe_context, void *spdm_context,
return true;
}

static void dump_cxl_ide_status(ide_common_test_port_context_t* upper_port, ide_common_test_port_context_t* lower_port)
{
TEEIO_PRINT(("\n"));
TEEIO_PRINT(("Print host cxl ide status\n"));
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 cxl ide status.\n"));
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);
}

// 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 skip_ksetgo, uint32_t config_bitmap,
bool set_link_enc_enable)
{
bool result;
uint8_t kp_ack_status;
Expand Down Expand Up @@ -303,7 +293,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);
Expand All @@ -324,9 +316,5 @@ 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);

dump_cxl_ide_status(upper_port, lower_port);

printf("cxl_setup_ide_stream is done. Press any key to continue.\n");
getchar();
return true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -57,7 +58,7 @@ bool cxl_ide_test_full_ide_stream_setup(void *test_context)
return cxl_setup_ide_stream(group_context->spdm_doe.doe_context, group_context->spdm_doe.spdm_context,
&group_context->spdm_doe.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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/**
* Copyright Notice:
* Copyright 2023-2024 Intel. All rights reserved.
* License: BSD 3-Clause License.
**/

#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>

#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_common_test_group_context_t *common = &group_context->common;
TEEIO_ASSERT(common->signature == GROUP_CONTEXT_SIGNATURE);
spdm_doe_context_t* spdm_doe = &group_context->spdm_doe;
TEEIO_ASSERT(spdm_doe);

ide_common_test_port_context_t* upper_port = &common->upper_port;
ide_common_test_port_context_t* lower_port = &common->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(common->suite_context->test_config, common->config_id);
TEEIO_ASSERT(configuration);

return cxl_setup_ide_stream(spdm_doe->doe_context, spdm_doe->spdm_context,
&spdm_doe->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_common_test_group_context_t *common = &group_context->common;
TEEIO_ASSERT(common->signature == GROUP_CONTEXT_SIGNATURE);
spdm_doe_context_t* spdm_doe = &group_context->spdm_doe;
TEEIO_ASSERT(spdm_doe);

ide_common_test_port_context_t* upper_port = &common->upper_port;
ide_common_test_port_context_t* lower_port = &common->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(common->suite_context->test_config, common->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(spdm_doe->doe_context, spdm_doe->spdm_context,
&spdm_doe->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 = (cxl_ide_test_group_context_t *)case_context->group_context;
TEEIO_ASSERT(group_context);
teeio_common_test_group_context_t *common = &group_context->common;
TEEIO_ASSERT(common->signature == GROUP_CONTEXT_SIGNATURE);
spdm_doe_context_t* spdm_doe = &group_context->spdm_doe;
TEEIO_ASSERT(spdm_doe);

ide_common_test_port_context_t* upper_port = &common->upper_port;
ide_common_test_port_context_t* lower_port = &common->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(spdm_doe->doe_context, spdm_doe->spdm_context,
&spdm_doe->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;
}