1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
/*
* Copyright (C) 2023-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "level_zero/sysman/source/api/ecc/sysman_ecc_imp.h"
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/helpers/debug_helpers.h"
#include "level_zero/sysman/source/shared/firmware_util/sysman_firmware_util.h"
namespace L0 {
namespace Sysman {
zes_device_ecc_state_t EccImp::getEccState(uint8_t state) {
switch (state) {
case eccStateEnable:
return ZES_DEVICE_ECC_STATE_ENABLED;
case eccStateDisable:
return ZES_DEVICE_ECC_STATE_DISABLED;
default:
return ZES_DEVICE_ECC_STATE_UNAVAILABLE;
}
}
ze_result_t EccImp::getEccFwUtilInterface(FirmwareUtil *&pFwUtil) {
pFwUtil = getFirmwareUtilInterface(pOsSysman);
if (pFwUtil == nullptr) {
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed while getting FirmwareUtilInterface() and returning error:0x%x \n", __FUNCTION__, ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t EccImp::deviceEccAvailable(ze_bool_t *pAvailable) {
if (pFwInterface == nullptr) {
ze_result_t result = getEccFwUtilInterface(pFwInterface);
if (result != ZE_RESULT_SUCCESS) {
return result;
}
UNRECOVERABLE_IF(pFwInterface == nullptr);
}
return pFwInterface->fwGetEccAvailable(pAvailable);
}
ze_result_t EccImp::deviceEccConfigurable(ze_bool_t *pConfigurable) {
if (pFwInterface == nullptr) {
ze_result_t result = getEccFwUtilInterface(pFwInterface);
if (result != ZE_RESULT_SUCCESS) {
return result;
}
UNRECOVERABLE_IF(pFwInterface == nullptr);
}
return pFwInterface->fwGetEccConfigurable(pConfigurable);
}
ze_result_t EccImp::getEccState(zes_device_ecc_properties_t *pState) {
if (pFwInterface == nullptr) {
ze_result_t result = getEccFwUtilInterface(pFwInterface);
if (result != ZE_RESULT_SUCCESS) {
return result;
}
UNRECOVERABLE_IF(pFwInterface == nullptr);
}
uint8_t currentState = 0xff;
uint8_t pendingState = 0xff;
uint8_t defaultState = 0xff;
ze_result_t result = pFwInterface->fwGetEccConfig(¤tState, &pendingState, &defaultState);
pState->currentState = getEccState(currentState);
pState->pendingState = getEccState(pendingState);
if (result != ZE_RESULT_SUCCESS) {
return result;
}
void *pNext = pState->pNext;
while (pNext) {
zes_device_ecc_default_properties_ext_t *pExtProps = reinterpret_cast<zes_device_ecc_default_properties_ext_t *>(pNext);
if (pExtProps->stype == ZES_STRUCTURE_TYPE_DEVICE_ECC_DEFAULT_PROPERTIES_EXT) {
pExtProps->defaultState = getEccState(defaultState);
break;
}
pNext = pExtProps->pNext;
}
pState->pendingAction = ZES_DEVICE_ACTION_WARM_CARD_RESET;
if (pState->currentState == pState->pendingState) {
pState->pendingAction = ZES_DEVICE_ACTION_NONE;
}
return result;
}
ze_result_t EccImp::setEccState(const zes_device_ecc_desc_t *newState, zes_device_ecc_properties_t *pState) {
if (pFwInterface == nullptr) {
ze_result_t result = getEccFwUtilInterface(pFwInterface);
if (result != ZE_RESULT_SUCCESS) {
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed while getting EccFwUtilInterface() and returning error:0x%x \n", __FUNCTION__, result);
return result;
}
UNRECOVERABLE_IF(pFwInterface == nullptr);
}
uint8_t state = 0;
uint8_t currentState = 0;
uint8_t pendingState = 0;
if (newState->state == ZES_DEVICE_ECC_STATE_ENABLED) {
state = eccStateEnable;
} else if (newState->state == ZES_DEVICE_ECC_STATE_DISABLED) {
state = eccStateDisable;
} else if (newState->state == ZES_DEVICE_ECC_STATE_UNAVAILABLE) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
} else {
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Invalid ecc enumeration and returning error:0x%x \n", __FUNCTION__, ZE_RESULT_ERROR_INVALID_ENUMERATION);
return ZE_RESULT_ERROR_INVALID_ENUMERATION;
}
ze_result_t result = pFwInterface->fwSetEccConfig(state, ¤tState, &pendingState);
if (result != ZE_RESULT_SUCCESS) {
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to set ecc configuration and returning error:0x%x \n", __FUNCTION__, result);
return result;
}
pState->currentState = getEccState(currentState);
pState->pendingState = getEccState(pendingState);
pState->pendingAction = ZES_DEVICE_ACTION_WARM_CARD_RESET;
if (pState->currentState == pState->pendingState) {
pState->pendingAction = ZES_DEVICE_ACTION_NONE;
}
return result;
}
} // namespace Sysman
} // namespace L0
|