diff --git a/include/library/cxl_tsp_common_lib.h b/include/library/cxl_tsp_common_lib.h index b1bb8b7..5010cb8 100644 --- a/include/library/cxl_tsp_common_lib.h +++ b/include/library/cxl_tsp_common_lib.h @@ -44,4 +44,10 @@ typedef struct { cxl_tsp_secondary_session_psk_key_material_t secondary_session_psk_key_material[4]; } libcxltsp_device_2nd_session_info_t; +typedef enum { + LIB_CXL_TSP_SESSION_TYPE_PRIMARY, + LIB_CXL_TSP_SESSION_TYPE_SECONDARY, + LIB_CXL_TSP_SESSION_TYPE_OTHER, +} libcxltsp_session_type; + #endif diff --git a/include/library/cxl_tsp_device_lib.h b/include/library/cxl_tsp_device_lib.h index f2d5573..c7602fb 100644 --- a/include/library/cxl_tsp_device_lib.h +++ b/include/library/cxl_tsp_device_lib.h @@ -42,8 +42,7 @@ void libcxltsp_initialize_session_id ( uint32_t session_id ); -bool libcxltsp_is_session_primary (uint32_t session_id); -bool libcxltsp_is_session_secondary (uint32_t session_id); +libcxltsp_session_type libcxltsp_get_session_type (uint32_t session_id); typedef uint32_t libcxltsp_error_code_t; #define CXL_TSP_ERROR_CODE_SUCCESS 0 @@ -146,4 +145,22 @@ libcxltsp_error_code_t cxl_tsp_device_lock_configuration ( const void *pci_doe_context, const void *spdm_context, const uint32_t *session_id); +/** + * Process the TSP request and return the response. + * + * @param request the TSP request message, start from cxl_tsp_header_t. + * @param request_size size in bytes of request. + * @param response the TSP response message, start from cxl_tsp_header_t. + * @param response_size size in bytes of response. + * + * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. + * @return ERROR The request is not processed. + **/ +libcxltsp_error_code_t cxl_tsp_device_set_te_state ( + const void *pci_doe_context, + const void *spdm_context, const uint32_t *session_id, + uint8_t te_state, + uint8_t number_of_memory_ranges, + const cxl_tsp_memory_range_t *memory_ranges); + #endif diff --git a/include/library/cxl_tsp_requester_lib.h b/include/library/cxl_tsp_requester_lib.h index 5b5c5ed..89a5391 100644 --- a/include/library/cxl_tsp_requester_lib.h +++ b/include/library/cxl_tsp_requester_lib.h @@ -106,6 +106,24 @@ libspdm_return_t cxl_tsp_lock_configuration( const void *pci_doe_context, void *spdm_context, const uint32_t *session_id); +/** + * Send and receive an TSP message + * + * @param spdm_context A pointer to the SPDM context. + * @param session_id Indicates if it is a secured message protected via SPDM session. + * If session_id is NULL, it is a normal message. + * If session_id is NOT NULL, it is a secured message. + * + * @retval LIBSPDM_STATUS_SUCCESS The IDM_KM request is sent and response is received. + * @return ERROR The IDM_KM response is not received correctly. + **/ +libspdm_return_t cxl_tsp_set_te_state( + const void *pci_doe_context, + void *spdm_context, const uint32_t *session_id, + uint8_t te_state, + uint8_t number_of_memory_ranges, + const cxl_tsp_memory_range_t *memory_ranges); + /** * Send and receive an TSP message * diff --git a/include/library/cxl_tsp_responder_lib.h b/include/library/cxl_tsp_responder_lib.h index e990036..9d681e6 100644 --- a/include/library/cxl_tsp_responder_lib.h +++ b/include/library/cxl_tsp_responder_lib.h @@ -166,4 +166,21 @@ libspdm_return_t cxl_tsp_get_response_lock_configuration ( const void *request, size_t request_size, void *response, size_t *response_size); +/** + * Process the TSP request and return the response. + * + * @param request the TSP request message, start from cxl_tsp_header_t. + * @param request_size size in bytes of request. + * @param response the TSP response message, start from cxl_tsp_header_t. + * @param response_size size in bytes of response. + * + * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. + * @return ERROR The request is not processed. + **/ +libspdm_return_t cxl_tsp_get_response_set_te_state ( + const void *pci_doe_context, + const void *spdm_context, const uint32_t *session_id, + const void *request, size_t request_size, + void *response, size_t *response_size); + #endif diff --git a/library/cxl_tsp_device_lib_sample/CMakeLists.txt b/library/cxl_tsp_device_lib_sample/CMakeLists.txt index 55a16d1..fab71ce 100644 --- a/library/cxl_tsp_device_lib_sample/CMakeLists.txt +++ b/library/cxl_tsp_device_lib_sample/CMakeLists.txt @@ -12,6 +12,7 @@ set(src_cxl_tsp_device_lib_sample cxl_tsp_device_get_configuration.c cxl_tsp_device_get_configuration_report.c cxl_tsp_device_lock_configuration.c + cxl_tsp_device_set_te_state.c ) add_library(cxl_tsp_device_lib_sample STATIC ${src_cxl_tsp_device_lib_sample}) diff --git a/library/cxl_tsp_device_lib_sample/cxl_tsp_device_context.c b/library/cxl_tsp_device_lib_sample/cxl_tsp_device_context.c index c8b7113..50ebb2b 100644 --- a/library/cxl_tsp_device_lib_sample/cxl_tsp_device_context.c +++ b/library/cxl_tsp_device_lib_sample/cxl_tsp_device_context.c @@ -37,6 +37,16 @@ bool libcxltsp_is_session_secondary (uint32_t session_id) return false; } +libcxltsp_session_type libcxltsp_get_session_type (uint32_t session_id) +{ + if (libcxltsp_is_session_primary(session_id)) { + return LIB_CXL_TSP_SESSION_TYPE_PRIMARY; + } else if (libcxltsp_is_session_secondary(session_id)) { + return LIB_CXL_TSP_SESSION_TYPE_SECONDARY; + } + return LIB_CXL_TSP_SESSION_TYPE_OTHER; +} + void libcxltsp_set_session_id (uint32_t session_id, bool is_secondary, size_t session_index) { if (!is_secondary) { diff --git a/library/cxl_tsp_device_lib_sample/cxl_tsp_device_set_te_state.c b/library/cxl_tsp_device_lib_sample/cxl_tsp_device_set_te_state.c new file mode 100644 index 0000000..749f1fb --- /dev/null +++ b/library/cxl_tsp_device_lib_sample/cxl_tsp_device_set_te_state.c @@ -0,0 +1,41 @@ +/** + * Copyright Notice: + * Copyright 2024 DMTF. All rights reserved. + * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md + **/ + +#include "hal/base.h" +#include "hal/library/memlib.h" +#include "library/spdm_requester_lib.h" +#include "library/spdm_transport_pcidoe_lib.h" +#include "library/cxl_tsp_device_lib.h" + +/** + * Process the TSP request and return the response. + * + * @param request the TSP request message, start from cxl_tsp_header_t. + * @param request_size size in bytes of request. + * @param response the TSP response message, start from cxl_tsp_header_t. + * @param response_size size in bytes of response. + * + * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. + * @return ERROR The request is not processed. + **/ +libcxltsp_error_code_t cxl_tsp_device_set_te_state ( + const void *pci_doe_context, + const void *spdm_context, const uint32_t *session_id, + uint8_t te_state, + uint8_t number_of_memory_ranges, + const cxl_tsp_memory_range_t *memory_ranges) +{ + libcxltsp_device_context *device_context; + + device_context = libcxltsp_get_device_context (pci_doe_context); + if (device_context == NULL) { + return CXL_TSP_ERROR_CODE_UNSPECIFIED; + } + + // TBD: need to set hardware state + + return CXL_TSP_ERROR_CODE_SUCCESS; +} diff --git a/library/cxl_tsp_requester_lib/CMakeLists.txt b/library/cxl_tsp_requester_lib/CMakeLists.txt index ecf171c..f966a36 100644 --- a/library/cxl_tsp_requester_lib/CMakeLists.txt +++ b/library/cxl_tsp_requester_lib/CMakeLists.txt @@ -12,6 +12,7 @@ set(src_cxl_tsp_requester_lib cxl_tsp_req_get_configuration.c cxl_tsp_req_get_configuration_report.c cxl_tsp_req_lock_configuration.c + cxl_tsp_req_set_te_state.c ) add_library(cxl_tsp_requester_lib STATIC ${src_cxl_tsp_requester_lib}) diff --git a/library/cxl_tsp_requester_lib/cxl_tsp_req_set_te_state.c b/library/cxl_tsp_requester_lib/cxl_tsp_req_set_te_state.c new file mode 100644 index 0000000..766efb6 --- /dev/null +++ b/library/cxl_tsp_requester_lib/cxl_tsp_req_set_te_state.c @@ -0,0 +1,82 @@ +/** + * Copyright Notice: + * Copyright 2021-2022 DMTF. All rights reserved. + * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md + **/ + +#include "hal/base.h" +#include "hal/library/memlib.h" +#include "library/spdm_requester_lib.h" +#include "library/spdm_transport_pcidoe_lib.h" +#include "library/cxl_tsp_requester_lib.h" + +#pragma pack(1) +typedef struct { + cxl_tsp_header_t header; + uint8_t te_state; + uint8_t number_of_memory_ranges; + uint8_t reserved[0xc]; + cxl_tsp_memory_range_t memory_ranges[32]; +} cxl_tsp_set_target_te_state_req_mine_t; +#pragma pack() + +/** + * Send and receive an TSP message + * + * @param spdm_context A pointer to the SPDM context. + * @param session_id Indicates if it is a secured message protected via SPDM session. + * If session_id is NULL, it is a normal message. + * If session_id is NOT NULL, it is a secured message. + * + * @retval LIBSPDM_STATUS_SUCCESS The TSP request is sent and response is received. + * @return ERROR The TSP response is not received correctly. + **/ +libspdm_return_t cxl_tsp_set_te_state( + const void *pci_doe_context, + void *spdm_context, const uint32_t *session_id, + uint8_t te_state, + uint8_t number_of_memory_ranges, + const cxl_tsp_memory_range_t *memory_ranges) +{ + libspdm_return_t status; + cxl_tsp_set_target_te_state_req_mine_t request; + size_t request_size; + cxl_tsp_set_target_te_state_rsp_t response; + size_t response_size; + + libspdm_zero_mem (&request, sizeof(request)); + request.header.tsp_version = CXL_TSP_MESSAGE_VERSION_10; + request.header.op_code = CXL_TSP_OPCODE_SET_TARGET_TE_STATE; + request.te_state = te_state; + request.number_of_memory_ranges = number_of_memory_ranges; + if (number_of_memory_ranges > 32) { + return LIBSPDM_STATUS_INVALID_STATE_LOCAL; + } + libspdm_copy_mem ( + request.memory_ranges, + sizeof(request.memory_ranges), + memory_ranges, + sizeof(cxl_tsp_memory_range_t) * number_of_memory_ranges); + + request_size = sizeof(cxl_tsp_set_target_te_state_req_t) + + number_of_memory_ranges * sizeof(cxl_tsp_memory_range_t); + response_size = sizeof(response); + status = cxl_tsp_send_receive_data(spdm_context, session_id, + &request, request_size, + &response, &response_size); + if (LIBSPDM_STATUS_IS_ERROR(status)) { + return status; + } + + if (response_size != sizeof(cxl_tsp_set_target_te_state_rsp_t)) { + return LIBSPDM_STATUS_INVALID_MSG_SIZE; + } + if (response.header.tsp_version != request.header.tsp_version) { + return LIBSPDM_STATUS_INVALID_MSG_FIELD; + } + if (response.header.op_code != CXL_TSP_OPCODE_SET_TARGET_TE_STATE_RSP) { + return LIBSPDM_STATUS_INVALID_MSG_FIELD; + } + + return LIBSPDM_STATUS_SUCCESS; +} diff --git a/library/cxl_tsp_responder_lib/CMakeLists.txt b/library/cxl_tsp_responder_lib/CMakeLists.txt index 7b16cf0..fcd4d83 100644 --- a/library/cxl_tsp_responder_lib/CMakeLists.txt +++ b/library/cxl_tsp_responder_lib/CMakeLists.txt @@ -12,6 +12,7 @@ set(src_cxl_tsp_responder_lib cxl_tsp_rsp_get_configuration.c cxl_tsp_rsp_get_configuration_report.c cxl_tsp_rsp_lock_configuration.c + cxl_tsp_rsp_set_te_state.c cxl_tsp_rsp_error.c ) diff --git a/library/cxl_tsp_responder_lib/cxl_tsp_dispatch.c b/library/cxl_tsp_responder_lib/cxl_tsp_dispatch.c index 4eb9ef4..8e60151 100644 --- a/library/cxl_tsp_responder_lib/cxl_tsp_dispatch.c +++ b/library/cxl_tsp_responder_lib/cxl_tsp_dispatch.c @@ -22,6 +22,7 @@ cxl_tsp_dispatch_struct_t m_cxl_tsp_dispatch[] = { {CXL_TSP_OPCODE_GET_TARGET_CONFIGURATION, cxl_tsp_get_response_get_configuration}, {CXL_TSP_OPCODE_GET_TARGET_CONFIGURATION_REPORT, cxl_tsp_get_response_get_configuration_report}, {CXL_TSP_OPCODE_LOCK_TARGET_CONFIGURATION, cxl_tsp_get_response_lock_configuration}, + {CXL_TSP_OPCODE_SET_TARGET_TE_STATE, cxl_tsp_get_response_set_te_state}, }; /** diff --git a/library/cxl_tsp_responder_lib/cxl_tsp_rsp_get_configuration.c b/library/cxl_tsp_responder_lib/cxl_tsp_rsp_get_configuration.c index 4163f8f..f85288b 100644 --- a/library/cxl_tsp_responder_lib/cxl_tsp_rsp_get_configuration.c +++ b/library/cxl_tsp_responder_lib/cxl_tsp_rsp_get_configuration.c @@ -37,7 +37,7 @@ libspdm_return_t cxl_tsp_get_response_get_configuration ( if (session_id == NULL) { return CXL_TSP_ERROR_CODE_NO_PRIVILEGE; } - if ((!libcxltsp_is_session_primary(*session_id)) && (!libcxltsp_is_session_secondary(*session_id))) { + if (libcxltsp_get_session_type(*session_id) == LIB_CXL_TSP_SESSION_TYPE_OTHER) { return CXL_TSP_ERROR_CODE_NO_PRIVILEGE; } diff --git a/library/cxl_tsp_responder_lib/cxl_tsp_rsp_get_configuration_report.c b/library/cxl_tsp_responder_lib/cxl_tsp_rsp_get_configuration_report.c index b3fbf40..6ddefb3 100644 --- a/library/cxl_tsp_responder_lib/cxl_tsp_rsp_get_configuration_report.c +++ b/library/cxl_tsp_responder_lib/cxl_tsp_rsp_get_configuration_report.c @@ -40,7 +40,7 @@ libspdm_return_t cxl_tsp_get_response_get_configuration_report ( if (session_id == NULL) { return CXL_TSP_ERROR_CODE_NO_PRIVILEGE; } - if ((!libcxltsp_is_session_primary(*session_id)) && (!libcxltsp_is_session_secondary(*session_id))) { + if (libcxltsp_get_session_type(*session_id) == LIB_CXL_TSP_SESSION_TYPE_OTHER) { return CXL_TSP_ERROR_CODE_NO_PRIVILEGE; } diff --git a/library/cxl_tsp_responder_lib/cxl_tsp_rsp_lock_configuration.c b/library/cxl_tsp_responder_lib/cxl_tsp_rsp_lock_configuration.c index 1f61120..3c58072 100644 --- a/library/cxl_tsp_responder_lib/cxl_tsp_rsp_lock_configuration.c +++ b/library/cxl_tsp_responder_lib/cxl_tsp_rsp_lock_configuration.c @@ -36,7 +36,7 @@ libspdm_return_t cxl_tsp_get_response_lock_configuration ( if (session_id == NULL) { return CXL_TSP_ERROR_CODE_NO_PRIVILEGE; } - if (!libcxltsp_is_session_primary(*session_id)) { + if (libcxltsp_get_session_type(*session_id) != LIB_CXL_TSP_SESSION_TYPE_PRIMARY) { return CXL_TSP_ERROR_CODE_NO_PRIVILEGE; } diff --git a/library/cxl_tsp_responder_lib/cxl_tsp_rsp_set_configuration.c b/library/cxl_tsp_responder_lib/cxl_tsp_rsp_set_configuration.c index daec3be..47e1b8a 100644 --- a/library/cxl_tsp_responder_lib/cxl_tsp_rsp_set_configuration.c +++ b/library/cxl_tsp_responder_lib/cxl_tsp_rsp_set_configuration.c @@ -241,7 +241,7 @@ libspdm_return_t cxl_tsp_get_response_set_configuration ( if (session_id == NULL) { return CXL_TSP_ERROR_CODE_NO_PRIVILEGE; } - if (!libcxltsp_is_session_primary(*session_id)) { + if (libcxltsp_get_session_type(*session_id) != LIB_CXL_TSP_SESSION_TYPE_PRIMARY) { return CXL_TSP_ERROR_CODE_NO_PRIVILEGE; } diff --git a/library/cxl_tsp_responder_lib/cxl_tsp_rsp_set_te_state.c b/library/cxl_tsp_responder_lib/cxl_tsp_rsp_set_te_state.c new file mode 100644 index 0000000..ab4523a --- /dev/null +++ b/library/cxl_tsp_responder_lib/cxl_tsp_rsp_set_te_state.c @@ -0,0 +1,113 @@ +/** + * Copyright Notice: + * Copyright 2021-2022 DMTF. All rights reserved. + * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md + **/ + +#include "hal/base.h" +#include "hal/library/memlib.h" +#include "hal/library/debuglib.h" +#include "library/spdm_requester_lib.h" +#include "library/spdm_transport_pcidoe_lib.h" +#include "library/cxl_tsp_device_lib.h" + +/** + * Process the TSP request and return the response. + * + * @param request the TSP request message, start from cxl_tsp_header_t. + * @param request_size size in bytes of request. + * @param response the TSP response message, start from cxl_tsp_header_t. + * @param response_size size in bytes of response. + * + * @retval LIBSPDM_STATUS_SUCCESS The request is processed and the response is returned. + * @return ERROR The request is not processed. + **/ +libspdm_return_t cxl_tsp_get_response_set_te_state ( + const void *pci_doe_context, + const void *spdm_context, const uint32_t *session_id, + const void *request, size_t request_size, + void *response, size_t *response_size) +{ + const cxl_tsp_set_target_te_state_req_t *tsp_request; + cxl_tsp_set_target_te_state_rsp_t *tsp_response; + libcxltsp_error_code_t error_code; + uint8_t current_tsp_state; + + if (session_id == NULL) { + return CXL_TSP_ERROR_CODE_NO_PRIVILEGE; + } + if (libcxltsp_get_session_type(*session_id) == LIB_CXL_TSP_SESSION_TYPE_OTHER) { + return CXL_TSP_ERROR_CODE_NO_PRIVILEGE; + } + + tsp_request = request; + tsp_response = response; + if (request_size < sizeof(cxl_tsp_set_target_te_state_req_t)) { + return cxl_tsp_get_response_error ( + pci_doe_context, + spdm_context, session_id, + request, CXL_TSP_ERROR_CODE_INVALID_REQUEST, 0, + response, response_size); + } + if (tsp_request->number_of_memory_ranges == 0 || tsp_request->number_of_memory_ranges > 32) { + return cxl_tsp_get_response_error ( + pci_doe_context, + spdm_context, session_id, + request, CXL_TSP_ERROR_CODE_INVALID_REQUEST, 0, + response, response_size); + } + if (request_size != sizeof(cxl_tsp_set_target_te_state_req_t) + + tsp_request->number_of_memory_ranges * sizeof(cxl_tsp_memory_range_t)) { + return cxl_tsp_get_response_error ( + pci_doe_context, + spdm_context, session_id, + request, CXL_TSP_ERROR_CODE_INVALID_REQUEST, 0, + response, response_size); + } + + if (tsp_request->header.tsp_version != CXL_TSP_MESSAGE_VERSION_10) { + return cxl_tsp_get_response_error ( + pci_doe_context, spdm_context, session_id, + request, CXL_TSP_ERROR_CODE_VERSION_MISMATCH, 0, + response, response_size); + } + + error_code = cxl_tsp_device_get_configuration ( + pci_doe_context, spdm_context, session_id, + NULL, + ¤t_tsp_state); + if (error_code != CXL_TSP_ERROR_CODE_SUCCESS) { + return cxl_tsp_get_response_error ( + pci_doe_context, spdm_context, session_id, + request, error_code, 0, + response, response_size); + } + if (current_tsp_state != CXL_TSP_STATE_CONFIG_LOCKED) { + return cxl_tsp_get_response_error ( + pci_doe_context, spdm_context, session_id, + request, CXL_TSP_ERROR_CODE_INVALID_SECURITY_STATE, 0, + response, response_size); + } + + LIBSPDM_ASSERT (*response_size >= sizeof(cxl_tsp_set_target_te_state_rsp_t)); + libspdm_zero_mem (response, *response_size); + + error_code = cxl_tsp_device_set_te_state ( + pci_doe_context, spdm_context, session_id, + tsp_request->te_state, + tsp_request->number_of_memory_ranges, + (cxl_tsp_memory_range_t *)(tsp_request + 1)); + if (error_code != CXL_TSP_ERROR_CODE_SUCCESS) { + return cxl_tsp_get_response_error ( + pci_doe_context, spdm_context, session_id, + request, error_code, 0, + response, response_size); + } + + *response_size = sizeof(cxl_tsp_set_target_te_state_rsp_t); + + tsp_response->header.tsp_version = tsp_request->header.tsp_version; + tsp_response->header.op_code = CXL_TSP_OPCODE_SET_TARGET_TE_STATE_RSP; + + return LIBSPDM_STATUS_SUCCESS; +} diff --git a/spdm_emu/spdm_requester_emu/spdm_requester_pci_doe.c b/spdm_emu/spdm_requester_emu/spdm_requester_pci_doe.c index 44ad1f0..13583c3 100644 --- a/spdm_emu/spdm_requester_emu/spdm_requester_pci_doe.c +++ b/spdm_emu/spdm_requester_emu/spdm_requester_pci_doe.c @@ -383,7 +383,7 @@ libspdm_return_t cxl_ide_km_process_session_message(void *spdm_context, uint32_t return LIBSPDM_STATUS_SUCCESS; } -libspdm_return_t cxl_tsp_process_session_message(void *spdm_context, uint32_t session_id, bool is_primary, bool is_secondary) +libspdm_return_t cxl_tsp_process_session_message(void *spdm_context, uint32_t session_id, libcxltsp_session_type session_type) { libspdm_return_t status; libcxltsp_device_capabilities_t device_capabilities; @@ -396,12 +396,14 @@ libspdm_return_t cxl_tsp_process_session_message(void *spdm_context, uint32_t se uint32_t configuration_report_size; cxl_tsp_target_configuration_report_t *configuration_report; bool result; + uint8_t te_state; + cxl_tsp_memory_range_t memory_range[1]; status = cxl_tsp_get_version (m_pci_doe_context, spdm_context, &session_id); if (LIBSPDM_STATUS_IS_ERROR(status)) { return status; } - LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "cxl_tsp_get_version(%d) done\n", is_secondary)); + LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "cxl_tsp_get_version(%d) done\n", session_type)); libspdm_zero_mem (&device_capabilities, sizeof(device_capabilities)); status = cxl_tsp_get_capabilities (m_pci_doe_context, spdm_context, &session_id, @@ -409,7 +411,7 @@ libspdm_return_t cxl_tsp_process_session_message(void *spdm_context, uint32_t se if (LIBSPDM_STATUS_IS_ERROR(status)) { return status; } - LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "device_capabilities(%d):\n", is_secondary)); + LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "device_capabilities(%d):\n", session_type)); LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " memory_encryption_features_supported - 0x%04x\n", device_capabilities.memory_encryption_features_supported)); LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " memory_encryption_algorithms_supported - 0x%08x\n", @@ -429,7 +431,7 @@ libspdm_return_t cxl_tsp_process_session_message(void *spdm_context, uint32_t se LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " number_of_secondary_sessions - 0x%02x\n", device_capabilities.number_of_secondary_sessions)); - if (is_primary) { + if (session_type == LIB_CXL_TSP_SESSION_TYPE_PRIMARY) { libspdm_zero_mem (&device_configuration, sizeof(device_configuration)); device_configuration.memory_encryption_features_enable = CXL_TSP_MEMORY_ENCRYPTION_FEATURES_ENABLE_ENCRYPTION; @@ -493,10 +495,10 @@ libspdm_return_t cxl_tsp_process_session_message(void *spdm_context, uint32_t se if (LIBSPDM_STATUS_IS_ERROR(status)) { return status; } - LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "cxl_tsp_set_configuration(%d) done\n", is_secondary)); + LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "cxl_tsp_set_configuration(%d) done\n", session_type)); } - if (is_primary || is_secondary) { + if (session_type != LIB_CXL_TSP_SESSION_TYPE_OTHER) { libspdm_zero_mem (¤t_device_configuration, sizeof(current_device_configuration)); current_tsp_state = CXL_TSP_STATE_CONFIG_UNLOCKED; status = cxl_tsp_get_configuration (m_pci_doe_context, spdm_context, &session_id, @@ -504,7 +506,7 @@ libspdm_return_t cxl_tsp_process_session_message(void *spdm_context, uint32_t se if (LIBSPDM_STATUS_IS_ERROR(status)) { return status; } - LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "current_device_configuration(%d):\n", is_secondary)); + LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "current_device_configuration(%d):\n", session_type)); LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " memory_encryption_features_enable - 0x%04x\n", current_device_configuration.memory_encryption_features_enable)); LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " memory_encryption_algorithm_select - 0x%08x\n", @@ -531,10 +533,10 @@ libspdm_return_t cxl_tsp_process_session_message(void *spdm_context, uint32_t se LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " number_of_ckids - 0x%02x\n", current_device_configuration.explicit_ib_te_state_granularity_entry[index].length_index)); } - LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "current_tsp_state(%d) - 0x%02x\n", is_secondary, current_tsp_state)); + LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "current_tsp_state(%d) - 0x%02x\n", session_type, current_tsp_state)); } - if (is_primary || is_secondary) { + if (session_type != LIB_CXL_TSP_SESSION_TYPE_OTHER) { configuration_report_size = sizeof(configuration_report_buffer); status = cxl_tsp_get_configuration_report ( m_pci_doe_context, spdm_context, &session_id, @@ -543,29 +545,53 @@ libspdm_return_t cxl_tsp_process_session_message(void *spdm_context, uint32_t se return status; } configuration_report = (cxl_tsp_target_configuration_report_t *)configuration_report_buffer; - LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "configuration_report(%d):\n", is_secondary)); + LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "configuration_report(%d):\n", session_type)); LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " valid_tsp_report_fields - 0x%02x\n", configuration_report->valid_tsp_report_fields)); } - if (is_primary) { + if (session_type == LIB_CXL_TSP_SESSION_TYPE_PRIMARY) { status = cxl_tsp_lock_configuration (m_pci_doe_context, spdm_context, &session_id); if (LIBSPDM_STATUS_IS_ERROR(status)) { return status; } - LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "cxl_tsp_lock_configuration(%d) done\n", is_secondary)); + LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "cxl_tsp_lock_configuration(%d) done\n", session_type)); } - if (is_primary || is_secondary) { + if (session_type != LIB_CXL_TSP_SESSION_TYPE_OTHER) { current_tsp_state = CXL_TSP_STATE_CONFIG_UNLOCKED; status = cxl_tsp_get_configuration (m_pci_doe_context, spdm_context, &session_id, NULL, ¤t_tsp_state); if (LIBSPDM_STATUS_IS_ERROR(status)) { return status; } - LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "current_tsp_state(%d) - 0x%02x\n", is_secondary, current_tsp_state)); + LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "current_tsp_state(%d) - 0x%02x\n", session_type, current_tsp_state)); } - if (is_primary) { + if (session_type != LIB_CXL_TSP_SESSION_TYPE_OTHER) { + memory_range[0].length = 0x10000; + memory_range[0].starting_address = 0x100000; + te_state = 0x1; + status = cxl_tsp_set_te_state (m_pci_doe_context, spdm_context, &session_id, + te_state, + LIBSPDM_ARRAY_SIZE(memory_range), + memory_range); + if (LIBSPDM_STATUS_IS_ERROR(status)) { + return status; + } + LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "set_te_state(%d) - 0x%02x\n", session_type, te_state)); + + te_state = 0x0; + status = cxl_tsp_set_te_state (m_pci_doe_context, spdm_context, &session_id, + te_state, + LIBSPDM_ARRAY_SIZE(memory_range), + memory_range); + if (LIBSPDM_STATUS_IS_ERROR(status)) { + return status; + } + LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "set_te_state(%d) - 0x%02x\n", session_type, te_state)); + } + + if (session_type == LIB_CXL_TSP_SESSION_TYPE_PRIMARY) { /* test CXL_TSP 2nd session */ if ((device_capabilities.configuration_features_supported & CXL_TSP_CONFIGURATION_FEATURES_SUPPORT_TARGET_SUPPORT_ADDITIONAL_SPDM_SESSIONS) != 0) { @@ -626,7 +652,7 @@ libspdm_return_t do_cxl_tsp_2nd_session_via_spdm(void *spdm_context, size_t inde return status; } - status = cxl_tsp_process_session_message (spdm_context, session_id, false, true); + status = cxl_tsp_process_session_message (spdm_context, session_id, LIB_CXL_TSP_SESSION_TYPE_SECONDARY); if (LIBSPDM_STATUS_IS_ERROR(status)) { printf("do_app_session_via_spdm(2nd) - %x\n", (uint32_t)status); return status; @@ -662,7 +688,8 @@ libspdm_return_t pci_doe_process_session_message(void *spdm_context, uint32_t se return status; } - status = cxl_tsp_process_session_message (spdm_context, session_id, is_first, false); + status = cxl_tsp_process_session_message (spdm_context, session_id, + is_first ? LIB_CXL_TSP_SESSION_TYPE_PRIMARY : LIB_CXL_TSP_SESSION_TYPE_OTHER); if (LIBSPDM_STATUS_IS_ERROR(status)) { return status; }