|
| 1 | +/* |
| 2 | + * Copyright (C) 2022 Intel Corporation |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: MIT |
| 5 | + * |
| 6 | + */ |
| 7 | + |
| 8 | +#include "level_zero/tools/source/sysman/ecc/linux/os_ecc_imp.h" |
| 9 | + |
| 10 | +#include "level_zero/tools/source/sysman/ecc/ecc_imp.h" |
| 11 | + |
| 12 | +namespace L0 { |
| 13 | + |
| 14 | +zes_device_ecc_state_t LinuxEccImp::getEccState(uint8_t state) { |
| 15 | + switch (state) { |
| 16 | + case eccStateEnable: |
| 17 | + return ZES_DEVICE_ECC_STATE_ENABLED; |
| 18 | + case eccStateDisable: |
| 19 | + return ZES_DEVICE_ECC_STATE_DISABLED; |
| 20 | + default: |
| 21 | + return ZES_DEVICE_ECC_STATE_UNAVAILABLE; |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +ze_result_t LinuxEccImp::deviceEccAvailable(ze_bool_t *pAvailable) { |
| 26 | + FirmwareUtil *pFwInterface = pLinuxSysmanImp->getFwUtilInterface(); |
| 27 | + if (pFwInterface == nullptr) { |
| 28 | + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; |
| 29 | + } |
| 30 | + |
| 31 | + *pAvailable = false; |
| 32 | + uint8_t currentState = 0; |
| 33 | + uint8_t pendingState = 0; |
| 34 | + ze_result_t result = pFwInterface->fwGetEccConfig(¤tState, &pendingState); |
| 35 | + if (ZE_RESULT_SUCCESS == result) { |
| 36 | + if ((currentState != eccStateNone) && (pendingState != eccStateNone)) { |
| 37 | + *pAvailable = true; |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + return result; |
| 42 | +} |
| 43 | + |
| 44 | +ze_result_t LinuxEccImp::deviceEccConfigurable(ze_bool_t *pConfigurable) { |
| 45 | + return deviceEccAvailable(pConfigurable); |
| 46 | +} |
| 47 | + |
| 48 | +ze_result_t LinuxEccImp::getEccState(zes_device_ecc_properties_t *pState) { |
| 49 | + FirmwareUtil *pFwInterface = pLinuxSysmanImp->getFwUtilInterface(); |
| 50 | + if (pFwInterface == nullptr) { |
| 51 | + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; |
| 52 | + } |
| 53 | + |
| 54 | + uint8_t currentState = 0; |
| 55 | + uint8_t pendingState = 0; |
| 56 | + ze_result_t result = pFwInterface->fwGetEccConfig(¤tState, &pendingState); |
| 57 | + if (result != ZE_RESULT_SUCCESS) { |
| 58 | + return result; |
| 59 | + } |
| 60 | + pState->currentState = getEccState(currentState); |
| 61 | + pState->pendingState = getEccState(pendingState); |
| 62 | + |
| 63 | + pState->pendingAction = ZES_DEVICE_ACTION_WARM_CARD_RESET; |
| 64 | + if (pState->currentState == pState->pendingState) { |
| 65 | + pState->pendingAction = ZES_DEVICE_ACTION_NONE; |
| 66 | + } |
| 67 | + |
| 68 | + return result; |
| 69 | +} |
| 70 | + |
| 71 | +ze_result_t LinuxEccImp::setEccState(const zes_device_ecc_desc_t *newState, zes_device_ecc_properties_t *pState) { |
| 72 | + FirmwareUtil *pFwInterface = pLinuxSysmanImp->getFwUtilInterface(); |
| 73 | + if (pFwInterface == nullptr) { |
| 74 | + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; |
| 75 | + } |
| 76 | + |
| 77 | + uint8_t state = 0; |
| 78 | + uint8_t currentState = 0; |
| 79 | + uint8_t pendingState = 0; |
| 80 | + if (newState->state == ZES_DEVICE_ECC_STATE_ENABLED) { |
| 81 | + state = eccStateEnable; |
| 82 | + } else if (newState->state == ZES_DEVICE_ECC_STATE_DISABLED) { |
| 83 | + state = eccStateDisable; |
| 84 | + } else { |
| 85 | + return ZE_RESULT_ERROR_INVALID_ENUMERATION; |
| 86 | + } |
| 87 | + |
| 88 | + ze_result_t result = pFwInterface->fwSetEccConfig(state, ¤tState, &pendingState); |
| 89 | + if (result != ZE_RESULT_SUCCESS) { |
| 90 | + return result; |
| 91 | + } |
| 92 | + |
| 93 | + pState->currentState = getEccState(currentState); |
| 94 | + pState->pendingState = getEccState(pendingState); |
| 95 | + |
| 96 | + pState->pendingAction = ZES_DEVICE_ACTION_WARM_CARD_RESET; |
| 97 | + if (pState->currentState == pState->pendingState) { |
| 98 | + pState->pendingAction = ZES_DEVICE_ACTION_NONE; |
| 99 | + } |
| 100 | + |
| 101 | + return result; |
| 102 | +} |
| 103 | + |
| 104 | +LinuxEccImp::LinuxEccImp(OsSysman *pOsSysman) { |
| 105 | + pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman); |
| 106 | +} |
| 107 | + |
| 108 | +OsEcc *OsEcc::create(OsSysman *pOsSysman) { |
| 109 | + LinuxEccImp *pLinuxEccImp = new LinuxEccImp(pOsSysman); |
| 110 | + return static_cast<OsEcc *>(pLinuxEccImp); |
| 111 | +} |
| 112 | + |
| 113 | +} // namespace L0 |
0 commit comments