Skip to content

Commit

Permalink
TSP Add 2nd session support.
Browse files Browse the repository at this point in the history
Signed-off-by: Jiewen Yao <[email protected]>
  • Loading branch information
jyao1 committed Oct 15, 2024
1 parent af7991d commit 8a46384
Show file tree
Hide file tree
Showing 11 changed files with 339 additions and 81 deletions.
12 changes: 12 additions & 0 deletions include/library/cxl_tsp_device_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include "library/cxl_tsp_responder_lib.h"

typedef struct {
bool session_id_primary_valid;
uint32_t session_id_primary;
bool session_id_secondary_valid[4];
uint32_t session_id_secondary[4];
uint8_t supported_tsp_versions[1];
uint8_t supported_tsp_versions_count;
/* provision info from device */
Expand All @@ -33,6 +37,14 @@ libcxltsp_device_context *libcxltsp_get_device_context (
const void *pci_doe_context
);

void libcxltsp_initialize_session_id (
void *spdm_context,
uint32_t session_id
);

bool libcxltsp_is_session_primary (uint32_t session_id);
bool libcxltsp_is_session_secondary (uint32_t session_id);

typedef uint32_t libcxltsp_error_code_t;
#define CXL_TSP_ERROR_CODE_SUCCESS 0

Expand Down
71 changes: 71 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 @@ -6,16 +6,87 @@

#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"

libcxltsp_device_context g_cxltsp_device_context;

extern uint8_t m_cxl_tsp_current_psk_session_index;

bool libcxltsp_is_session_primary (uint32_t session_id)
{
if (g_cxltsp_device_context.session_id_primary_valid &&
(g_cxltsp_device_context.session_id_primary == session_id)) {
return true;
}
return false;
}

bool libcxltsp_is_session_secondary (uint32_t session_id)
{
size_t index;

for (index = 0; index < 4; index++) {
if (g_cxltsp_device_context.session_id_secondary_valid[index] &&
(g_cxltsp_device_context.session_id_secondary[index] == session_id)) {
return true;
}
}
return false;
}

void libcxltsp_set_session_id (uint32_t session_id, bool is_secondary, size_t session_index)
{
if (!is_secondary) {
g_cxltsp_device_context.session_id_primary_valid = true;
g_cxltsp_device_context.session_id_primary = session_id;
} else {
LIBSPDM_ASSERT (session_index < 4);
g_cxltsp_device_context.session_id_secondary_valid[session_index] = true;
g_cxltsp_device_context.session_id_secondary[session_index] = session_id;
}
}

void libcxltsp_initialize_session_id (
void *spdm_context,
uint32_t session_id
)
{
libspdm_data_parameter_t parameter;
bool is_psk;
size_t data_size;

if (!g_cxltsp_device_context.session_id_primary_valid) {
libcxltsp_set_session_id (session_id, false, 0);
return ;
}

is_psk = false;
data_size = sizeof(is_psk);
libspdm_zero_mem(&parameter, sizeof(parameter));
parameter.location = LIBSPDM_DATA_LOCATION_SESSION;
*(uint32_t *)parameter.additional_data = session_id;
libspdm_get_data (spdm_context, LIBSPDM_DATA_SESSION_USE_PSK, &parameter, &is_psk, &data_size);
if (!is_psk) {
return ;
}
if (m_cxl_tsp_current_psk_session_index >= 4) {
return ;
}
libcxltsp_set_session_id (session_id, true, m_cxl_tsp_current_psk_session_index);
return ;
}

libcxltsp_device_context *libcxltsp_initialize_device_context (
const void *pci_doe_context
)
{
if (g_cxltsp_device_context.session_id_primary_valid) {
return &g_cxltsp_device_context;
}

libspdm_zero_mem (
&g_cxltsp_device_context,
sizeof(g_cxltsp_device_context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ libcxltsp_error_code_t cxl_tsp_device_get_version (
if (device_context == NULL) {
return CXL_TSP_ERROR_CODE_UNSPECIFIED;
}

libcxltsp_initialize_session_id ((void *)spdm_context, *session_id);

libspdm_copy_mem (version_number_entry,
sizeof(cxl_tsp_version_number_t) * (*version_number_entry_count),
device_context->supported_tsp_versions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "library/spdm_transport_pcidoe_lib.h"
#include "library/cxl_tsp_device_lib.h"

extern uint8_t m_cxl_tsp_2nd_session_psk[4][0x20];

/**
* Process the TSP request and return the response.
*
Expand All @@ -28,6 +30,7 @@ libcxltsp_error_code_t cxl_tsp_device_set_configuration (
const libcxltsp_device_2nd_session_info_t *device_2nd_session_info)
{
libcxltsp_device_context *device_context;
size_t index;

device_context = libcxltsp_get_device_context (pci_doe_context);
if (device_context == NULL) {
Expand All @@ -42,5 +45,14 @@ libcxltsp_error_code_t cxl_tsp_device_set_configuration (
device_2nd_session_info,
sizeof(libcxltsp_device_2nd_session_info_t));

for (index = 0; index < 4; index++) {
if ((device_context->device_2nd_session_info.configuration_validity_flags & (0x1 << index)) != 0) {
libspdm_copy_mem(
m_cxl_tsp_2nd_session_psk[index],
sizeof(m_cxl_tsp_2nd_session_psk[index]),
&device_context->device_2nd_session_info.secondary_session_psk_key_material[index],
sizeof(device_context->device_2nd_session_info.secondary_session_psk_key_material[index]));
}
}
return CXL_TSP_ERROR_CODE_SUCCESS;
}
4 changes: 4 additions & 0 deletions library/cxl_tsp_responder_lib/cxl_tsp_rsp_get_capabilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ libspdm_return_t cxl_tsp_get_response_get_capabilities (
libcxltsp_error_code_t error_code;
libcxltsp_device_capabilities_t device_capabilities;

if (session_id == NULL) {
return CXL_TSP_ERROR_CODE_NO_PRIVILEGE;
}

tsp_request = request;
tsp_response = response;
if (request_size != sizeof(cxl_tsp_get_target_capabilities_req_t)) {
Expand Down
7 changes: 7 additions & 0 deletions library/cxl_tsp_responder_lib/cxl_tsp_rsp_get_configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ libspdm_return_t cxl_tsp_get_response_get_configuration (
libcxltsp_device_configuration_t device_configuration;
uint8_t current_tsp_state;

if (session_id == NULL) {
return CXL_TSP_ERROR_CODE_NO_PRIVILEGE;
}
if ((!libcxltsp_is_session_primary(*session_id)) && (!libcxltsp_is_session_secondary(*session_id))) {
return CXL_TSP_ERROR_CODE_NO_PRIVILEGE;
}

tsp_request = request;
tsp_response = response;
if (request_size != sizeof(cxl_tsp_get_target_configuration_req_t)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ libspdm_return_t cxl_tsp_get_response_get_configuration_report (
uint16_t offset;
uint8_t current_tsp_state;

if (session_id == NULL) {
return CXL_TSP_ERROR_CODE_NO_PRIVILEGE;
}
if ((!libcxltsp_is_session_primary(*session_id)) && (!libcxltsp_is_session_secondary(*session_id))) {
return CXL_TSP_ERROR_CODE_NO_PRIVILEGE;
}

tsp_request = request;
tsp_response = response;
if (request_size != sizeof(cxl_tsp_get_target_configuration_report_req_t)) {
Expand Down
4 changes: 4 additions & 0 deletions library/cxl_tsp_responder_lib/cxl_tsp_rsp_get_version.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ libspdm_return_t cxl_tsp_get_response_get_version (
cxl_tsp_get_target_tsp_version_rsp_mine_t *tsp_response;
libcxltsp_error_code_t error_code;

if (session_id == NULL) {
return CXL_TSP_ERROR_CODE_NO_PRIVILEGE;
}

tsp_request = request;
tsp_response = response;
if (request_size != sizeof(cxl_tsp_get_target_tsp_version_req_t)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ libspdm_return_t cxl_tsp_get_response_lock_configuration (
libcxltsp_error_code_t error_code;
uint8_t current_tsp_state;

if (session_id == NULL) {
return CXL_TSP_ERROR_CODE_NO_PRIVILEGE;
}
if (!libcxltsp_is_session_primary(*session_id)) {
return CXL_TSP_ERROR_CODE_NO_PRIVILEGE;
}

tsp_request = request;
tsp_response = response;
if (request_size != sizeof(cxl_tsp_lock_target_configuration_req_t)) {
Expand Down
7 changes: 7 additions & 0 deletions library/cxl_tsp_responder_lib/cxl_tsp_rsp_set_configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ libspdm_return_t cxl_tsp_get_response_set_configuration (
libcxltsp_device_capabilities_t device_capabilities;
uint8_t current_tsp_state;

if (session_id == NULL) {
return CXL_TSP_ERROR_CODE_NO_PRIVILEGE;
}
if (!libcxltsp_is_session_primary(*session_id)) {
return CXL_TSP_ERROR_CODE_NO_PRIVILEGE;
}

tsp_request = request;
tsp_response = response;
if (request_size != sizeof(cxl_tsp_set_target_configuration_req_t)) {
Expand Down
Loading

0 comments on commit 8a46384

Please sign in to comment.