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

Tsp add set_te_state #381

Merged
merged 2 commits into from
Oct 16, 2024
Merged
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
6 changes: 6 additions & 0 deletions include/library/cxl_tsp_common_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 19 additions & 2 deletions include/library/cxl_tsp_device_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
18 changes: 18 additions & 0 deletions include/library/cxl_tsp_requester_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
17 changes: 17 additions & 0 deletions include/library/cxl_tsp_responder_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions library/cxl_tsp_device_lib_sample/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
10 changes: 10 additions & 0 deletions library/cxl_tsp_device_lib_sample/cxl_tsp_device_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
41 changes: 41 additions & 0 deletions library/cxl_tsp_device_lib_sample/cxl_tsp_device_set_te_state.c
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions library/cxl_tsp_requester_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
82 changes: 82 additions & 0 deletions library/cxl_tsp_requester_lib/cxl_tsp_req_set_te_state.c
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions library/cxl_tsp_responder_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
1 change: 1 addition & 0 deletions library/cxl_tsp_responder_lib/cxl_tsp_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading
Loading