diff --git a/level_zero/sysman/source/api/firmware/linux/sysman_os_firmware_imp.cpp b/level_zero/sysman/source/api/firmware/linux/sysman_os_firmware_imp.cpp index 4a909a2d65..0fa929e2ca 100644 --- a/level_zero/sysman/source/api/firmware/linux/sysman_os_firmware_imp.cpp +++ b/level_zero/sysman/source/api/firmware/linux/sysman_os_firmware_imp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -59,6 +59,10 @@ ze_result_t LinuxFirmwareImp::osFirmwareFlash(void *pImage, uint32_t size) { return pFwInterface->flashFirmware(osFwType, pImage, size); } +ze_result_t LinuxFirmwareImp::osGetFirmwareFlashProgress(uint32_t *pCompletionPercent) { + return pFwInterface->getFlashFirmwareProgress(pCompletionPercent); +} + LinuxFirmwareImp::LinuxFirmwareImp(OsSysman *pOsSysman, const std::string &fwType) : osFwType(fwType) { LinuxSysmanImp *pLinuxSysmanImp = static_cast(pOsSysman); pSysfsAccess = &pLinuxSysmanImp->getSysfsAccess(); diff --git a/level_zero/sysman/source/api/firmware/linux/sysman_os_firmware_imp.h b/level_zero/sysman/source/api/firmware/linux/sysman_os_firmware_imp.h index 3401300246..79ba053e9d 100644 --- a/level_zero/sysman/source/api/firmware/linux/sysman_os_firmware_imp.h +++ b/level_zero/sysman/source/api/firmware/linux/sysman_os_firmware_imp.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -22,6 +22,7 @@ class LinuxFirmwareImp : public OsFirmware, NEO::NonCopyableOrMovableClass { public: void osGetFwProperties(zes_firmware_properties_t *pProperties) override; ze_result_t osFirmwareFlash(void *pImage, uint32_t size) override; + ze_result_t osGetFirmwareFlashProgress(uint32_t *pCompletionPercent) override; ze_result_t getFirmwareVersion(std::string fwType, zes_firmware_properties_t *pProperties); LinuxFirmwareImp() = default; LinuxFirmwareImp(OsSysman *pOsSysman, const std::string &fwType); diff --git a/level_zero/sysman/source/api/firmware/sysman_firmware_imp.cpp b/level_zero/sysman/source/api/firmware/sysman_firmware_imp.cpp index a08346f962..1c2ab698b7 100644 --- a/level_zero/sysman/source/api/firmware/sysman_firmware_imp.cpp +++ b/level_zero/sysman/source/api/firmware/sysman_firmware_imp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -29,7 +29,7 @@ ze_result_t FirmwareImp::firmwareFlash(void *pImage, uint32_t size) { } ze_result_t FirmwareImp::firmwareGetFlashProgress(uint32_t *pCompletionPercent) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; + return pOsFirmware->osGetFirmwareFlashProgress(pCompletionPercent); } FirmwareImp::FirmwareImp(OsSysman *pOsSysman, const std::string &initalizedFwType) { diff --git a/level_zero/sysman/source/api/firmware/sysman_os_firmware.h b/level_zero/sysman/source/api/firmware/sysman_os_firmware.h index 5b4ddae46c..6b5b4f5ac2 100644 --- a/level_zero/sysman/source/api/firmware/sysman_os_firmware.h +++ b/level_zero/sysman/source/api/firmware/sysman_os_firmware.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -20,6 +20,7 @@ class OsFirmware { public: virtual void osGetFwProperties(zes_firmware_properties_t *pProperties) = 0; virtual ze_result_t osFirmwareFlash(void *pImage, uint32_t size) = 0; + virtual ze_result_t osGetFirmwareFlashProgress(uint32_t *pCompletionPercent) = 0; static std::unique_ptr create(OsSysman *pOsSysman, const std::string &fwType); static ze_result_t getSupportedFwTypes(std::vector &supportedFwTypes, OsSysman *pOsSysman); virtual ~OsFirmware() {} diff --git a/level_zero/sysman/source/api/firmware/windows/sysman_os_firmware_imp.cpp b/level_zero/sysman/source/api/firmware/windows/sysman_os_firmware_imp.cpp index 9120fd64ee..dfad2c15cb 100644 --- a/level_zero/sysman/source/api/firmware/windows/sysman_os_firmware_imp.cpp +++ b/level_zero/sysman/source/api/firmware/windows/sysman_os_firmware_imp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -36,6 +36,10 @@ ze_result_t WddmFirmwareImp::osFirmwareFlash(void *pImage, uint32_t size) { return pFwInterface->flashFirmware(osFwType, pImage, size); } +ze_result_t WddmFirmwareImp::osGetFirmwareFlashProgress(uint32_t *pCompletionPercent) { + return pFwInterface->getFlashFirmwareProgress(pCompletionPercent); +} + WddmFirmwareImp::WddmFirmwareImp(OsSysman *pOsSysman, const std::string &fwType) : osFwType(fwType) { WddmSysmanImp *pWddmSysmanImp = static_cast(pOsSysman); pFwInterface = pWddmSysmanImp->getFwUtilInterface(); diff --git a/level_zero/sysman/source/api/firmware/windows/sysman_os_firmware_imp.h b/level_zero/sysman/source/api/firmware/windows/sysman_os_firmware_imp.h index d39864f7d9..cccbf0fb69 100644 --- a/level_zero/sysman/source/api/firmware/windows/sysman_os_firmware_imp.h +++ b/level_zero/sysman/source/api/firmware/windows/sysman_os_firmware_imp.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -17,6 +17,7 @@ class WddmFirmwareImp : public OsFirmware { public: void osGetFwProperties(zes_firmware_properties_t *pProperties) override; ze_result_t osFirmwareFlash(void *pImage, uint32_t size) override; + ze_result_t osGetFirmwareFlashProgress(uint32_t *pCompletionPercent) override; ze_result_t getFirmwareVersion(std::string fwType, zes_firmware_properties_t *pProperties); WddmFirmwareImp() = default; WddmFirmwareImp(OsSysman *pOsSysman, const std::string &fwType); diff --git a/level_zero/sysman/source/shared/firmware_util/sysman_firmware_util.h b/level_zero/sysman/source/shared/firmware_util/sysman_firmware_util.h index f70a3da73e..232a9a694a 100644 --- a/level_zero/sysman/source/shared/firmware_util/sysman_firmware_util.h +++ b/level_zero/sysman/source/shared/firmware_util/sysman_firmware_util.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Intel Corporation + * Copyright (C) 2022-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -23,6 +23,7 @@ class FirmwareUtil { virtual ze_result_t fwDeviceInit() = 0; virtual ze_result_t getFwVersion(std::string fwType, std::string &firmwareVersion) = 0; virtual ze_result_t flashFirmware(std::string fwType, void *pImage, uint32_t size) = 0; + virtual ze_result_t getFlashFirmwareProgress(uint32_t *pCompletionPercent) = 0; virtual ze_result_t fwIfrApplied(bool &ifrStatus) = 0; virtual ze_result_t fwSupportedDiagTests(std::vector &supportedDiagTests) = 0; virtual ze_result_t fwRunDiagTests(std::string &osDiagType, zes_diag_result_t *pDiagResult) = 0; diff --git a/level_zero/sysman/source/shared/firmware_util/sysman_firmware_util_imp.cpp b/level_zero/sysman/source/shared/firmware_util/sysman_firmware_util_imp.cpp index 712d0bd485..1e03a746d9 100644 --- a/level_zero/sysman/source/shared/firmware_util/sysman_firmware_util_imp.cpp +++ b/level_zero/sysman/source/shared/firmware_util/sysman_firmware_util_imp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Intel Corporation + * Copyright (C) 2022-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -57,13 +57,24 @@ bool FirmwareUtilImp::loadEntryPoints() { return ok; } -static void progressFunc(uint32_t done, uint32_t total, void *ctx) { - uint32_t percent = (done * 100) / total; - PRINT_DEBUG_STRING(NEO::debugManager.flags.PrintDebugMessages.get(), stdout, "Progess: %d/%d:%d/%\n", done, total, percent); +void firmwareFlashProgressFunc(uint32_t done, uint32_t total, void *ctx) { + if (ctx != nullptr) { + uint32_t percent = (done * 100) / total; + FlashProgressInfo *pFlashProgress = static_cast(ctx); + const std::lock_guard lock(pFlashProgress->fwProgressLock); + pFlashProgress->completionPercent = percent; + PRINT_DEBUG_STRING(NEO::debugManager.flags.PrintDebugMessages.get(), stdout, "Progess: %d/%d:%d/%\n", done, total, percent); + } } FirmwareUtilImp::OsLibraryLoadPtr FirmwareUtilImp::osLibraryLoadFunction(NEO::OsLibrary::load); +ze_result_t FirmwareUtilImp::getFlashFirmwareProgress(uint32_t *pCompletionPercent) { + const std::lock_guard lock(flashProgress.fwProgressLock); + *pCompletionPercent = flashProgress.completionPercent; + return ZE_RESULT_SUCCESS; +} + ze_result_t FirmwareUtilImp::getFirstDevice(igsc_device_info *info) { igsc_device_iterator *iter; int ret = deviceIteratorCreate(&iter); @@ -148,7 +159,7 @@ ze_result_t FirmwareUtilImp::opromGetVersion(std::string &fwVersion) { ze_result_t FirmwareUtilImp::fwFlashGSC(void *pImage, uint32_t size) { const std::lock_guard lock(this->fwLock); - int ret = deviceFwUpdate(&fwDeviceHandle, static_cast(pImage), size, progressFunc, nullptr); + int ret = deviceFwUpdate(&fwDeviceHandle, static_cast(pImage), size, firmwareFlashProgressFunc, &flashProgress); if (ret != IGSC_SUCCESS) { return ZE_RESULT_ERROR_UNINITIALIZED; } @@ -169,10 +180,10 @@ ze_result_t FirmwareUtilImp::fwFlashOprom(void *pImage, uint32_t size) { return ZE_RESULT_ERROR_UNINITIALIZED; } if (opromImgType & IGSC_OPROM_DATA) { - retData = deviceOpromUpdate(&fwDeviceHandle, IGSC_OPROM_DATA, opromImg, progressFunc, nullptr); + retData = deviceOpromUpdate(&fwDeviceHandle, IGSC_OPROM_DATA, opromImg, firmwareFlashProgressFunc, &flashProgress); } if (opromImgType & IGSC_OPROM_CODE) { - retCode = deviceOpromUpdate(&fwDeviceHandle, IGSC_OPROM_CODE, opromImg, progressFunc, nullptr); + retCode = deviceOpromUpdate(&fwDeviceHandle, IGSC_OPROM_CODE, opromImg, firmwareFlashProgressFunc, &flashProgress); } if ((retData != IGSC_SUCCESS) && (retCode != IGSC_SUCCESS)) { return ZE_RESULT_ERROR_UNINITIALIZED; diff --git a/level_zero/sysman/source/shared/firmware_util/sysman_firmware_util_imp.h b/level_zero/sysman/source/shared/firmware_util/sysman_firmware_util_imp.h index 3604bfde78..7579aeed4e 100644 --- a/level_zero/sysman/source/shared/firmware_util/sysman_firmware_util_imp.h +++ b/level_zero/sysman/source/shared/firmware_util/sysman_firmware_util_imp.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Intel Corporation + * Copyright (C) 2022-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -103,6 +103,13 @@ extern pIgscIfrRunMemPPRTest deviceIfrRunMemPPRTest; extern pIgscGetEccConfig getEccConfig; extern pIgscSetEccConfig setEccConfig; +extern void firmwareFlashProgressFunc(uint32_t done, uint32_t total, void *ctx); + +typedef struct { + uint32_t completionPercent; + std::mutex fwProgressLock; +} FlashProgressInfo; + class FirmwareUtilImp : public FirmwareUtil, NEO::NonCopyableOrMovableClass { public: FirmwareUtilImp(uint16_t domain, uint8_t bus, uint8_t device, uint8_t function); @@ -110,6 +117,7 @@ class FirmwareUtilImp : public FirmwareUtil, NEO::NonCopyableOrMovableClass { ze_result_t fwDeviceInit() override; ze_result_t getFwVersion(std::string fwType, std::string &firmwareVersion) override; ze_result_t flashFirmware(std::string fwType, void *pImage, uint32_t size) override; + ze_result_t getFlashFirmwareProgress(uint32_t *pCompletionPercent) override; ze_result_t fwIfrApplied(bool &ifrStatus) override; ze_result_t fwSupportedDiagTests(std::vector &supportedDiagTests) override; ze_result_t fwRunDiagTests(std::string &osDiagType, zes_diag_result_t *pDiagResult) override; @@ -126,6 +134,7 @@ class FirmwareUtilImp : public FirmwareUtil, NEO::NonCopyableOrMovableClass { bool loadEntryPointsExt(); NEO::OsLibrary *libraryHandle = nullptr; + FlashProgressInfo flashProgress{}; protected: ze_result_t getFirstDevice(igsc_device_info *); diff --git a/level_zero/sysman/source/shared/firmware_util/sysman_firmware_util_imp_helper.cpp b/level_zero/sysman/source/shared/firmware_util/sysman_firmware_util_imp_helper.cpp index 459e02b474..f51307c97c 100644 --- a/level_zero/sysman/source/shared/firmware_util/sysman_firmware_util_imp_helper.cpp +++ b/level_zero/sysman/source/shared/firmware_util/sysman_firmware_util_imp_helper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -203,11 +203,6 @@ ze_result_t FirmwareUtilImp::fwRunDiagTests(std::string &osDiagType, zes_diag_re return ZE_RESULT_SUCCESS; } -static void progressFunc(uint32_t done, uint32_t total, void *ctx) { - uint32_t percent = (done * 100) / total; - PRINT_DEBUG_STRING(NEO::debugManager.flags.PrintDebugMessages.get(), stdout, "Progess: %d/%d:%d/%\n", done, total, percent); -} - ze_result_t FirmwareUtilImp::pscGetVersion(std::string &fwVersion) { return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -219,7 +214,7 @@ ze_result_t FirmwareUtilImp::fwFlashIafPsc(void *pImage, uint32_t size) { if (iafPscUpdate == nullptr) { return ZE_RESULT_ERROR_UNINITIALIZED; } - int ret = iafPscUpdate(&fwDeviceHandle, static_cast(pImage), size, progressFunc, nullptr); + int ret = iafPscUpdate(&fwDeviceHandle, static_cast(pImage), size, firmwareFlashProgressFunc, &flashProgress); if (ret != IGSC_SUCCESS) { return ZE_RESULT_ERROR_UNINITIALIZED; } @@ -227,6 +222,10 @@ ze_result_t FirmwareUtilImp::fwFlashIafPsc(void *pImage, uint32_t size) { } ze_result_t FirmwareUtilImp::flashFirmware(std::string fwType, void *pImage, uint32_t size) { + flashProgress.fwProgressLock.lock(); + flashProgress.completionPercent = 0; + flashProgress.fwProgressLock.unlock(); + if (fwType == deviceSupportedFirmwareTypes[0]) { // GSC return fwFlashGSC(pImage, size); } diff --git a/level_zero/sysman/test/unit_tests/sources/diagnostics/linux/mock_zes_sysman_diagnostics.h b/level_zero/sysman/test/unit_tests/sources/diagnostics/linux/mock_zes_sysman_diagnostics.h index 9c6dbd1c67..3e12ad61b4 100644 --- a/level_zero/sysman/test/unit_tests/sources/diagnostics/linux/mock_zes_sysman_diagnostics.h +++ b/level_zero/sysman/test/unit_tests/sources/diagnostics/linux/mock_zes_sysman_diagnostics.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -57,6 +57,7 @@ struct MockDiagnosticsFwInterface : public L0::Sysman::FirmwareUtil { MockDiagnosticsFwInterface() = default; ADDMETHOD_NOBASE(getFwVersion, ze_result_t, ZE_RESULT_SUCCESS, (std::string fwType, std::string &firmwareVersion)); + ADDMETHOD_NOBASE(getFlashFirmwareProgress, ze_result_t, ZE_RESULT_SUCCESS, (uint32_t * pCompletionPercent)); ADDMETHOD_NOBASE(flashFirmware, ze_result_t, ZE_RESULT_SUCCESS, (std::string fwType, void *pImage, uint32_t size)); ADDMETHOD_NOBASE(fwIfrApplied, ze_result_t, ZE_RESULT_SUCCESS, (bool &ifrStatus)); ADDMETHOD_NOBASE(fwGetMemoryErrorCount, ze_result_t, ZE_RESULT_SUCCESS, (zes_ras_error_type_t category, uint32_t subDeviceCount, uint32_t subDeviceId, uint64_t &count)); @@ -261,4 +262,4 @@ class PublicLinuxDiagnosticsImp : public L0::Sysman::LinuxDiagnosticsImp { } // namespace ult } // namespace Sysman -} // namespace L0 \ No newline at end of file +} // namespace L0 diff --git a/level_zero/sysman/test/unit_tests/sources/ecc/linux/mock_ecc.h b/level_zero/sysman/test/unit_tests/sources/ecc/linux/mock_ecc.h index c897ee91e7..03f982cb6f 100644 --- a/level_zero/sysman/test/unit_tests/sources/ecc/linux/mock_ecc.h +++ b/level_zero/sysman/test/unit_tests/sources/ecc/linux/mock_ecc.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -51,6 +51,7 @@ struct MockEccFwInterface : public L0::Sysman::FirmwareUtil { } ADDMETHOD_NOBASE(getFwVersion, ze_result_t, ZE_RESULT_SUCCESS, (std::string fwType, std::string &firmwareVersion)); + ADDMETHOD_NOBASE(getFlashFirmwareProgress, ze_result_t, ZE_RESULT_SUCCESS, (uint32_t * pCompletionPercent)); ADDMETHOD_NOBASE(flashFirmware, ze_result_t, ZE_RESULT_SUCCESS, (std::string fwType, void *pImage, uint32_t size)); ADDMETHOD_NOBASE(fwIfrApplied, ze_result_t, ZE_RESULT_SUCCESS, (bool &ifrStatus)); ADDMETHOD_NOBASE(fwSupportedDiagTests, ze_result_t, ZE_RESULT_SUCCESS, (std::vector & supportedDiagTests)); diff --git a/level_zero/sysman/test/unit_tests/sources/ecc/windows/mock_ecc.h b/level_zero/sysman/test/unit_tests/sources/ecc/windows/mock_ecc.h index 98a2b7cb2f..9f10ca8019 100644 --- a/level_zero/sysman/test/unit_tests/sources/ecc/windows/mock_ecc.h +++ b/level_zero/sysman/test/unit_tests/sources/ecc/windows/mock_ecc.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -55,6 +55,7 @@ struct EccFwInterface : public L0::Sysman::FirmwareUtil { } ADDMETHOD_NOBASE(getFwVersion, ze_result_t, ZE_RESULT_SUCCESS, (std::string fwType, std::string &firmwareVersion)); + ADDMETHOD_NOBASE(getFlashFirmwareProgress, ze_result_t, ZE_RESULT_SUCCESS, (uint32_t * pCompletionPercent)); ADDMETHOD_NOBASE(flashFirmware, ze_result_t, ZE_RESULT_SUCCESS, (std::string fwType, void *pImage, uint32_t size)); ADDMETHOD_NOBASE(fwIfrApplied, ze_result_t, ZE_RESULT_SUCCESS, (bool &ifrStatus)); ADDMETHOD_NOBASE(fwSupportedDiagTests, ze_result_t, ZE_RESULT_SUCCESS, (std::vector & supportedDiagTests)); diff --git a/level_zero/sysman/test/unit_tests/sources/events/linux/mock_events.h b/level_zero/sysman/test/unit_tests/sources/events/linux/mock_events.h index a8f5b1a52c..d873709fca 100644 --- a/level_zero/sysman/test/unit_tests/sources/events/linux/mock_events.h +++ b/level_zero/sysman/test/unit_tests/sources/events/linux/mock_events.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -247,6 +247,7 @@ struct MockEventsFwInterface : public L0::Sysman::FirmwareUtil { ADDMETHOD_NOBASE(fwDeviceInit, ze_result_t, ZE_RESULT_SUCCESS, (void)); ADDMETHOD_NOBASE(getFwVersion, ze_result_t, ZE_RESULT_SUCCESS, (std::string fwType, std::string &firmwareVersion)); + ADDMETHOD_NOBASE(getFlashFirmwareProgress, ze_result_t, ZE_RESULT_SUCCESS, (uint32_t * pCompletionPercent)); ADDMETHOD_NOBASE(flashFirmware, ze_result_t, ZE_RESULT_SUCCESS, (std::string fwType, void *pImage, uint32_t size)); ADDMETHOD_NOBASE(fwSupportedDiagTests, ze_result_t, ZE_RESULT_SUCCESS, (std::vector & supportedDiagTests)); ADDMETHOD_NOBASE(fwRunDiagTests, ze_result_t, ZE_RESULT_SUCCESS, (std::string & osDiagType, zes_diag_result_t *pResult)); diff --git a/level_zero/sysman/test/unit_tests/sources/firmware/linux/mock_zes_sysman_firmware.h b/level_zero/sysman/test/unit_tests/sources/firmware/linux/mock_zes_sysman_firmware.h index 3ef8a03789..51661661d2 100644 --- a/level_zero/sysman/test/unit_tests/sources/firmware/linux/mock_zes_sysman_firmware.h +++ b/level_zero/sysman/test/unit_tests/sources/firmware/linux/mock_zes_sysman_firmware.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -70,6 +70,7 @@ struct MockFirmwareInterface : public L0::Sysman::FirmwareUtil { MockFirmwareInterface() = default; ADDMETHOD_NOBASE(fwDeviceInit, ze_result_t, ZE_RESULT_SUCCESS, ()); + ADDMETHOD_NOBASE(getFlashFirmwareProgress, ze_result_t, ZE_RESULT_SUCCESS, (uint32_t * pCompletionPercent)); ADDMETHOD_NOBASE(flashFirmware, ze_result_t, ZE_RESULT_SUCCESS, (std::string fwType, void *pImage, uint32_t size)); ADDMETHOD_NOBASE(fwIfrApplied, ze_result_t, ZE_RESULT_SUCCESS, (bool &ifrStatus)); ADDMETHOD_NOBASE(fwSupportedDiagTests, ze_result_t, ZE_RESULT_SUCCESS, (std::vector & supportedDiagTests)); diff --git a/level_zero/sysman/test/unit_tests/sources/firmware/linux/mock_zes_sysman_firmware_prelim.h b/level_zero/sysman/test/unit_tests/sources/firmware/linux/mock_zes_sysman_firmware_prelim.h index d1b8a13a30..ff6bae807c 100644 --- a/level_zero/sysman/test/unit_tests/sources/firmware/linux/mock_zes_sysman_firmware_prelim.h +++ b/level_zero/sysman/test/unit_tests/sources/firmware/linux/mock_zes_sysman_firmware_prelim.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Intel Corporation + * Copyright (C) 2022-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -118,6 +118,7 @@ struct MockFirmwareInterface : public FirmwareInterface { MockFirmwareInterface() = default; ADDMETHOD_NOBASE(fwDeviceInit, ze_result_t, ZE_RESULT_SUCCESS, ()); + ADDMETHOD_NOBASE(getFlashFirmwareProgress, ze_result_t, ZE_RESULT_SUCCESS, (uint32_t * pCompletionPercent)); ADDMETHOD_NOBASE(flashFirmware, ze_result_t, ZE_RESULT_SUCCESS, (std::string fwType, void *pImage, uint32_t size)); ADDMETHOD_NOBASE(fwIfrApplied, ze_result_t, ZE_RESULT_SUCCESS, (bool &ifrStatus)); ADDMETHOD_NOBASE(fwSupportedDiagTests, ze_result_t, ZE_RESULT_SUCCESS, (std::vector & supportedDiagTests)); diff --git a/level_zero/sysman/test/unit_tests/sources/firmware/linux/test_zes_sysman_firmware_prelim.cpp b/level_zero/sysman/test/unit_tests/sources/firmware/linux/test_zes_sysman_firmware_prelim.cpp index 116bb1e23e..79b487e430 100644 --- a/level_zero/sysman/test/unit_tests/sources/firmware/linux/test_zes_sysman_firmware_prelim.cpp +++ b/level_zero/sysman/test/unit_tests/sources/firmware/linux/test_zes_sysman_firmware_prelim.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Intel Corporation + * Copyright (C) 2022-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -281,7 +281,7 @@ TEST_F(ZesSysmanFirmwareFixture, GivenNewFirmwareContextWithHandleSizeZeroWhenFi EXPECT_EQ(3u, count); } -TEST_F(ZesSysmanFirmwareFixture, GivenValidFirmwareHandleWhenGettingFirmwareFlashProgressThenUnsupportedIsReturned) { +TEST_F(ZesSysmanFirmwareFixture, GivenValidFirmwareHandleWhenGettingFirmwareFlashProgressThenSuccessIsReturned) { initFirmware(); L0::Sysman::FirmwareImp *ptestFirmwareImp = new L0::Sysman::FirmwareImp(pSysmanDeviceImp->pFirmwareHandleContext->pOsSysman, mockSupportedFirmwareTypes[1]); @@ -290,7 +290,7 @@ TEST_F(ZesSysmanFirmwareFixture, GivenValidFirmwareHandleWhenGettingFirmwareFlas auto handles = getFirmwareHandles(mockFwHandlesCount); uint32_t completionPercent = 0; - EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesFirmwareGetFlashProgress(handles[1], &completionPercent)); + EXPECT_EQ(ZE_RESULT_SUCCESS, zesFirmwareGetFlashProgress(handles[1], &completionPercent)); } class ZesFirmwareUninitializedFixture : public SysmanDeviceFixture { diff --git a/level_zero/sysman/test/unit_tests/sources/firmware/windows/mock_zes_sysman_firmware.h b/level_zero/sysman/test/unit_tests/sources/firmware/windows/mock_zes_sysman_firmware.h index 4cccd9dbaf..e4579896f6 100644 --- a/level_zero/sysman/test/unit_tests/sources/firmware/windows/mock_zes_sysman_firmware.h +++ b/level_zero/sysman/test/unit_tests/sources/firmware/windows/mock_zes_sysman_firmware.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -54,6 +54,7 @@ struct FirmwareInterface : public L0::Sysman::FirmwareUtil { } ADDMETHOD_NOBASE(fwDeviceInit, ze_result_t, ZE_RESULT_SUCCESS, ()); + ADDMETHOD_NOBASE(getFlashFirmwareProgress, ze_result_t, ZE_RESULT_SUCCESS, (uint32_t * pCompletionPercent)); ADDMETHOD_NOBASE(flashFirmware, ze_result_t, ZE_RESULT_SUCCESS, (std::string fwType, void *pImage, uint32_t size)); ADDMETHOD_NOBASE(fwIfrApplied, ze_result_t, ZE_RESULT_SUCCESS, (bool &ifrStatus)); ADDMETHOD_NOBASE(fwSupportedDiagTests, ze_result_t, ZE_RESULT_SUCCESS, (std::vector & supportedDiagTests)); diff --git a/level_zero/sysman/test/unit_tests/sources/firmware/windows/test_zes_sysman_firmware.cpp b/level_zero/sysman/test/unit_tests/sources/firmware/windows/test_zes_sysman_firmware.cpp index b2c6a906dd..851199118c 100644 --- a/level_zero/sysman/test/unit_tests/sources/firmware/windows/test_zes_sysman_firmware.cpp +++ b/level_zero/sysman/test/unit_tests/sources/firmware/windows/test_zes_sysman_firmware.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -210,7 +210,7 @@ TEST_F(ZesFirmwareFixture, GivenValidFirmwareHandleFirmwareLibraryCallFailureWhe EXPECT_STREQ("unknown", properties.version); } -TEST_F(ZesFirmwareFixture, GivenValidFirmwareHandleWhenGettingFirmwareFlashProgressThenUnsupportedIsReturned) { +TEST_F(ZesFirmwareFixture, GivenValidFirmwareHandleWhenGettingFirmwareFlashProgressThenSuccessIsReturned) { initFirmware(); L0::Sysman::FirmwareImp *ptestFirmwareImp = new L0::Sysman::FirmwareImp(pSysmanDeviceImp->pFirmwareHandleContext->pOsSysman, mockSupportedFwTypes[0]); @@ -218,7 +218,7 @@ TEST_F(ZesFirmwareFixture, GivenValidFirmwareHandleWhenGettingFirmwareFlashProgr auto handles = getFirmwareHandles(mockHandleCount); uint32_t completionPercent = 0; - EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesFirmwareGetFlashProgress(handles[1], &completionPercent)); + EXPECT_EQ(ZE_RESULT_SUCCESS, zesFirmwareGetFlashProgress(handles[1], &completionPercent)); } } // namespace ult diff --git a/level_zero/sysman/test/unit_tests/sources/firmware_util/mock_fw_util_fixture.h b/level_zero/sysman/test/unit_tests/sources/firmware_util/mock_fw_util_fixture.h index 254f058134..820f1ec39f 100644 --- a/level_zero/sysman/test/unit_tests/sources/firmware_util/mock_fw_util_fixture.h +++ b/level_zero/sysman/test/unit_tests/sources/firmware_util/mock_fw_util_fixture.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Intel Corporation + * Copyright (C) 2022-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -25,6 +25,7 @@ struct MockFwUtilInterface : public L0::Sysman::FirmwareUtil { ADDMETHOD_NOBASE(fwDeviceInit, ze_result_t, ZE_RESULT_SUCCESS, ()); ADDMETHOD_NOBASE(getFwVersion, ze_result_t, ZE_RESULT_SUCCESS, (std::string fwType, std::string &firmwareVersion)); + ADDMETHOD_NOBASE(getFlashFirmwareProgress, ze_result_t, ZE_RESULT_SUCCESS, (uint32_t * pCompletionPercent)); ADDMETHOD_NOBASE(flashFirmware, ze_result_t, ZE_RESULT_SUCCESS, (std::string fwType, void *pImage, uint32_t size)); ADDMETHOD_NOBASE(fwIfrApplied, ze_result_t, ZE_RESULT_SUCCESS, (bool &ifrStatus)); ADDMETHOD_NOBASE(fwSupportedDiagTests, ze_result_t, ZE_RESULT_SUCCESS, (std::vector & supportedDiagTests)); diff --git a/level_zero/sysman/test/unit_tests/sources/firmware_util/test_fw_util_helper.cpp b/level_zero/sysman/test/unit_tests/sources/firmware_util/test_fw_util_helper.cpp index 280848fcf9..88e215a8ab 100644 --- a/level_zero/sysman/test/unit_tests/sources/firmware_util/test_fw_util_helper.cpp +++ b/level_zero/sysman/test/unit_tests/sources/firmware_util/test_fw_util_helper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Intel Corporation + * Copyright (C) 2022-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -437,6 +437,43 @@ TEST(FwGetMemHealthIndicatorTest, GivenFwGetHealthIndicatorProcAddrIsNullWhenMem delete pFwUtilImp; } +TEST(FwUtilImpProgressTest, GivenFirmwareUtilImpWhenSettingFirmwareProgressPercentThenCorrectProgressIsReturned) { + L0::Sysman::FirmwareUtilImp *pFwUtilImp = new L0::Sysman::FirmwareUtilImp(0, 0, 0, 0); + uint32_t mockProgressPercent = 55; + pFwUtilImp->flashProgress.completionPercent = mockProgressPercent; + uint32_t percent = 0; + EXPECT_EQ(ZE_RESULT_SUCCESS, pFwUtilImp->getFlashFirmwareProgress(&percent)); + EXPECT_EQ(mockProgressPercent, percent); + delete pFwUtilImp; +} + +TEST(FwUtilImpProgressTest, GivenFirmwareUtilImpWhenSettingProgressThroughCallbackThenCorrectProgressIsReturned) { + L0::Sysman::FirmwareUtilImp *pFwUtilImp = new L0::Sysman::FirmwareUtilImp(0, 0, 0, 0); + uint32_t mockDone = 55; + uint32_t mockTotal = 100; + + firmwareFlashProgressFunc(mockDone, mockTotal, &pFwUtilImp->flashProgress); + + uint32_t percent = 0; + EXPECT_EQ(ZE_RESULT_SUCCESS, pFwUtilImp->getFlashFirmwareProgress(&percent)); + uint32_t percentCalculation = (uint32_t)((mockDone * 100) / mockTotal); + EXPECT_EQ(percentCalculation, percent); + delete pFwUtilImp; +} + +TEST(FwUtilImpProgressTest, GivenFirmwareUtilImpAndNullContextWhenSettingProgressThroughCallbackThenZeroProgressIsReturned) { + L0::Sysman::FirmwareUtilImp *pFwUtilImp = new L0::Sysman::FirmwareUtilImp(0, 0, 0, 0); + uint32_t mockDone = 55; + uint32_t mockTotal = 100; + + firmwareFlashProgressFunc(mockDone, mockTotal, nullptr); + + uint32_t percent = 0; + EXPECT_EQ(ZE_RESULT_SUCCESS, pFwUtilImp->getFlashFirmwareProgress(&percent)); + EXPECT_EQ((uint32_t)0, percent); + delete pFwUtilImp; +} + } // namespace ult } // namespace Sysman } // namespace L0 diff --git a/level_zero/sysman/test/unit_tests/sources/global_operations/linux/mock_global_operations.h b/level_zero/sysman/test/unit_tests/sources/global_operations/linux/mock_global_operations.h index f0b02f4662..4366779ae2 100644 --- a/level_zero/sysman/test/unit_tests/sources/global_operations/linux/mock_global_operations.h +++ b/level_zero/sysman/test/unit_tests/sources/global_operations/linux/mock_global_operations.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -591,6 +591,7 @@ struct MockGlobalOpsFwInterface : public L0::Sysman::FirmwareUtil { ADDMETHOD_NOBASE(fwDeviceInit, ze_result_t, ZE_RESULT_SUCCESS, (void)); ADDMETHOD_NOBASE(getFwVersion, ze_result_t, ZE_RESULT_SUCCESS, (std::string fwType, std::string &firmwareVersion)); + ADDMETHOD_NOBASE(getFlashFirmwareProgress, ze_result_t, ZE_RESULT_SUCCESS, (uint32_t * pCompletionPercent)); ADDMETHOD_NOBASE(flashFirmware, ze_result_t, ZE_RESULT_SUCCESS, (std::string fwType, void *pImage, uint32_t size)); ADDMETHOD_NOBASE(fwSupportedDiagTests, ze_result_t, ZE_RESULT_SUCCESS, (std::vector & supportedDiagTests)); ADDMETHOD_NOBASE(fwRunDiagTests, ze_result_t, ZE_RESULT_SUCCESS, (std::string & osDiagType, zes_diag_result_t *pResult)); diff --git a/level_zero/sysman/test/unit_tests/sources/ras/linux/mock_sysman_ras.h b/level_zero/sysman/test/unit_tests/sources/ras/linux/mock_sysman_ras.h index e8d8647d0f..d89d0fe424 100644 --- a/level_zero/sysman/test/unit_tests/sources/ras/linux/mock_sysman_ras.h +++ b/level_zero/sysman/test/unit_tests/sources/ras/linux/mock_sysman_ras.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -645,6 +645,7 @@ struct MockRasFwInterface : public L0::Sysman::FirmwareUtil { ADDMETHOD_NOBASE(fwDeviceInit, ze_result_t, ZE_RESULT_SUCCESS, ()); ADDMETHOD_NOBASE(getFwVersion, ze_result_t, ZE_RESULT_SUCCESS, (std::string fwType, std::string &firmwareVersion)); + ADDMETHOD_NOBASE(getFlashFirmwareProgress, ze_result_t, ZE_RESULT_SUCCESS, (uint32_t * pCompletionPercent)); ADDMETHOD_NOBASE(flashFirmware, ze_result_t, ZE_RESULT_SUCCESS, (std::string fwType, void *pImage, uint32_t size)); ADDMETHOD_NOBASE(fwIfrApplied, ze_result_t, ZE_RESULT_SUCCESS, (bool &ifrStatus)); ADDMETHOD_NOBASE(fwSupportedDiagTests, ze_result_t, ZE_RESULT_SUCCESS, (std::vector & supportedDiagTests)); diff --git a/level_zero/tools/test/black_box_tests/CMakeLists.txt b/level_zero/tools/test/black_box_tests/CMakeLists.txt index 818a77b15f..2056a7f71c 100644 --- a/level_zero/tools/test/black_box_tests/CMakeLists.txt +++ b/level_zero/tools/test/black_box_tests/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2020-2023 Intel Corporation +# Copyright (C) 2020-2024 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -22,9 +22,9 @@ if(UNIX) if(BUILD_LEVEL_ZERO_LOADER) add_dependencies(${TEST_NAME} ze_loader) - target_link_libraries(${TEST_NAME} ${NEO_BINARY_DIR}/lib/libze_loader.so) + target_link_libraries(${TEST_NAME} ${NEO_BINARY_DIR}/lib/libze_loader.so pthread) else() - target_link_libraries(${TEST_NAME} PUBLIC ${TARGET_NAME_L0}) + target_link_libraries(${TEST_NAME} PUBLIC ${TARGET_NAME_L0} pthread) endif() set_target_properties(${TEST_NAME} PROPERTIES FOLDER ${L0_BLACK_BOX_TEST_PROJECT_FOLDER}) endforeach() diff --git a/level_zero/tools/test/black_box_tests/zello_sysman.cpp b/level_zero/tools/test/black_box_tests/zello_sysman.cpp index 7e146c4ea5..3045a28952 100644 --- a/level_zero/tools/test/black_box_tests/zello_sysman.cpp +++ b/level_zero/tools/test/black_box_tests/zello_sysman.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -22,10 +22,16 @@ #include #include #endif // defined(_WIN32) || defined(_WIN64) +#include #include - bool verbose = true; +typedef struct { + zes_firmware_handle_t firmwareHandle; + std::mutex firmwareProgressMutex; + bool flashComplete; +} FirmwareFlashInfo; + std::string getErrorString(ze_result_t error) { static const std::map mgetErrorString{ {ZE_RESULT_NOT_READY, "ZE_RESULT_NOT_READY"}, @@ -1061,12 +1067,42 @@ void testSysmanMemory(ze_device_handle_t &device) { } } } + +static void trackFirmwareFlashProgress(FirmwareFlashInfo *flashData) { + bool loopContinue = true; + uint32_t progressPercent = 0; + do { + progressPercent = 0; + ze_result_t result = zesFirmwareGetFlashProgress(flashData->firmwareHandle, &progressPercent); + if (result != ZE_RESULT_SUCCESS) { + break; + } + printf("\rFirmware Flash Progress: %d %%", progressPercent); + fflush(stdout); + + std::this_thread::sleep_for(std::chrono::seconds(1)); + + flashData->firmwareProgressMutex.lock(); + loopContinue = !flashData->flashComplete; + flashData->firmwareProgressMutex.unlock(); + + } while (loopContinue); + progressPercent = 0; + ze_result_t result = zesFirmwareGetFlashProgress(flashData->firmwareHandle, &progressPercent); + if (result != ZE_RESULT_SUCCESS) { + return; + } + printf("\rFirmware Flash Progress: %d %%\n", progressPercent); + fflush(stdout); +} + void testSysmanFirmware(ze_device_handle_t &device, std::string imagePath) { std::cout << std::endl << " ---- firmware tests ---- " << std::endl; uint32_t count = 0; std::ifstream imageFile; uint64_t imgSize = 0; + FirmwareFlashInfo flashData{}; if (imagePath.size() != 0) { struct stat statBuf; auto status = stat(imagePath.c_str(), &statBuf); @@ -1096,8 +1132,18 @@ void testSysmanFirmware(ze_device_handle_t &device, std::string imagePath) { if (imagePath.size() != 0 && imgSize > 0) { std::vector img(imgSize); imageFile.read(img.data(), imgSize); + + flashData.flashComplete = false; + flashData.firmwareHandle = handle; + std::thread thread(trackFirmwareFlashProgress, &flashData); + VALIDATECALL(zesFirmwareFlash(handle, img.data(), static_cast(imgSize))); + flashData.firmwareProgressMutex.lock(); + flashData.flashComplete = true; + flashData.firmwareProgressMutex.unlock(); + thread.join(); + VALIDATECALL(zesFirmwareGetProperties(handle, &fwProperties)); if (verbose) { std::cout << "firmware name = " << fwProperties.name << std::endl; @@ -1108,6 +1154,7 @@ void testSysmanFirmware(ze_device_handle_t &device, std::string imagePath) { } } } + void testSysmanReset(ze_device_handle_t &device, bool force) { std::cout << std::endl << " ---- Reset test (force = " << (force ? "true" : "false") << ") ---- " << std::endl;