2022-04-12 19:45:58 +08:00
/*
2023-04-18 15:51:09 +08:00
* Copyright ( C ) 2022 - 2023 Intel Corporation
2022-04-12 19:45:58 +08:00
*
* SPDX - License - Identifier : MIT
*
*/
# include "level_zero/tools/source/sysman/ecc/ecc_imp.h"
2023-04-18 15:51:09 +08:00
# include "shared/source/debug_settings/debug_settings_manager.h"
2022-06-24 19:20:48 +08:00
# include "level_zero/tools/source/sysman/firmware_util/firmware_util.h"
2022-04-12 19:45:58 +08:00
namespace L0 {
2022-06-24 19:20:48 +08:00
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 ) {
2023-04-18 15:51:09 +08:00
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 ) ;
2022-06-24 19:20:48 +08:00
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE ;
}
return ZE_RESULT_SUCCESS ;
}
2022-04-12 19:45:58 +08:00
ze_result_t EccImp : : deviceEccAvailable ( ze_bool_t * pAvailable ) {
2022-06-24 19:20:48 +08:00
if ( pFwInterface = = nullptr ) {
ze_result_t result = getEccFwUtilInterface ( pFwInterface ) ;
if ( result ! = ZE_RESULT_SUCCESS ) {
2023-04-18 15:51:09 +08:00
NEO : : printDebugString ( NEO : : DebugManager . flags . PrintDebugMessages . get ( ) , stderr , " Error@ %s(): Failed while getting EccFwUtilInterface() and returning error:0x%x \n " , __FUNCTION__ , ZE_RESULT_ERROR_UNSUPPORTED_FEATURE ) ;
2022-06-24 19:20:48 +08:00
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE ;
}
}
* pAvailable = false ;
uint8_t currentState = 0 ;
uint8_t pendingState = 0 ;
ze_result_t result = pFwInterface - > fwGetEccConfig ( & currentState , & pendingState ) ;
if ( ZE_RESULT_SUCCESS = = result ) {
if ( ( currentState ! = eccStateNone ) & & ( pendingState ! = eccStateNone ) ) {
* pAvailable = true ;
}
}
return result ;
2022-04-12 19:45:58 +08:00
}
ze_result_t EccImp : : deviceEccConfigurable ( ze_bool_t * pConfigurable ) {
2022-06-24 19:20:48 +08:00
return deviceEccAvailable ( pConfigurable ) ;
2022-04-12 19:45:58 +08:00
}
ze_result_t EccImp : : getEccState ( zes_device_ecc_properties_t * pState ) {
2022-06-24 19:20:48 +08:00
if ( pFwInterface = = nullptr ) {
ze_result_t result = getEccFwUtilInterface ( pFwInterface ) ;
if ( result ! = ZE_RESULT_SUCCESS ) {
2023-04-18 15:51:09 +08:00
NEO : : printDebugString ( NEO : : DebugManager . flags . PrintDebugMessages . get ( ) , stderr , " Error@ %s(): Failed while getting EccFwUtilInterface() and returning error \n " , __FUNCTION__ , ZE_RESULT_ERROR_UNSUPPORTED_FEATURE ) ;
2022-06-24 19:20:48 +08:00
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE ;
}
}
uint8_t currentState = 0 ;
uint8_t pendingState = 0 ;
ze_result_t result = pFwInterface - > fwGetEccConfig ( & currentState , & pendingState ) ;
if ( result ! = ZE_RESULT_SUCCESS ) {
2023-04-18 15:51:09 +08:00
NEO : : printDebugString ( NEO : : DebugManager . flags . PrintDebugMessages . get ( ) , stderr , " Error@ %s(): Failed to get ecc configuration and returning error:0x%x \n " , __FUNCTION__ , result ) ;
2022-06-24 19:20:48 +08:00
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 ;
2022-04-12 19:45:58 +08:00
}
ze_result_t EccImp : : setEccState ( const zes_device_ecc_desc_t * newState , zes_device_ecc_properties_t * pState ) {
2022-06-24 19:20:48 +08:00
if ( pFwInterface = = nullptr ) {
ze_result_t result = getEccFwUtilInterface ( pFwInterface ) ;
if ( result ! = ZE_RESULT_SUCCESS ) {
2023-04-18 15:51:09 +08:00
NEO : : printDebugString ( NEO : : DebugManager . flags . PrintDebugMessages . get ( ) , stderr , " Error@ %s(): Failed while getting EccFwUtilInterface() and returning error:0x%x \n " , __FUNCTION__ , ZE_RESULT_ERROR_UNSUPPORTED_FEATURE ) ;
2022-06-24 19:20:48 +08:00
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE ;
}
}
2022-04-12 19:45:58 +08:00
2022-06-24 19:20:48 +08:00
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 {
2023-04-18 15:51:09 +08:00
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 ) ;
2022-06-24 19:20:48 +08:00
return ZE_RESULT_ERROR_INVALID_ENUMERATION ;
2022-04-12 19:45:58 +08:00
}
2022-06-24 19:20:48 +08:00
ze_result_t result = pFwInterface - > fwSetEccConfig ( state , & currentState , & pendingState ) ;
if ( result ! = ZE_RESULT_SUCCESS ) {
2023-04-18 15:51:09 +08:00
NEO : : printDebugString ( NEO : : DebugManager . flags . PrintDebugMessages . get ( ) , stderr , " Error@ %s(): Failed to set ecc configuration and returning error:0x%x \n " , __FUNCTION__ , result ) ;
2022-06-24 19:20:48 +08:00
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 ;
2022-04-12 19:45:58 +08:00
}
2022-06-24 19:20:48 +08:00
return result ;
2022-04-12 19:45:58 +08:00
}
} // namespace L0