| @@ -17,12 +17,12 @@ | |||
| 17 | #include <device_tree/interface/NVMe/LogCollection.h> | 17 | #include <device_tree/interface/NVMe/LogCollection.h> |
| 18 | #include <mc/timer.h> | 18 | #include <mc/timer.h> |
| 19 | #include <mutex> | 19 | #include <mutex> |
| 20 | -#include <nvme/nvme_mi_over_mctp_huawei.h> | 20 | +#include <nvme/nvme_mi_over_mctp.h> |
| 21 | #include <vector> | 21 | #include <vector> |
| 22 | 22 | ||
| 23 | namespace dev { | 23 | namespace dev { |
| 24 | 24 | ||
| 25 | -using nvme_mi_over_mctp_ptr = std::shared_ptr<nvme_mi_over_mctp_huawei>; | 25 | +using nvme_mi_over_mctp_ptr = std::shared_ptr<nvme_mi_over_mctp>; |
| 26 | 26 | ||
| 27 | // 日志采集定时任务周期:24小时 | 27 | // 日志采集定时任务周期:24小时 |
| 28 | constexpr auto LOG_COLLECTION_INTERVAL = std::chrono::hours(24); | 28 | constexpr auto LOG_COLLECTION_INTERVAL = std::chrono::hours(24); |
| @@ -30,14 +30,36 @@ bool NVMe_MultiRecord::update_multi_record_by_vpd() | |||
| 30 | std::string firmware_version; | 30 | std::string firmware_version; |
| 31 | // OSPowerState: 0=下电(SSDChip 不可读),1=上电。下电时固件版本跳过获取(Revision 保持上次值, | 31 | // OSPowerState: 0=下电(SSDChip 不可读),1=上电。下电时固件版本跳过获取(Revision 保持上次值, |
| 32 | // OS reset 后恢复刷新);容量/速率读 VPDChip(下电可读),不受影响,对齐 1.0 行为 | 32 | // OS reset 后恢复刷新);容量/速率读 VPDChip(下电可读),不受影响,对齐 1.0 行为 |
| 33 | - if (m_nvme_oem && m_nvme_oem->OSPowerState.get_value() == 1 && m_vpd_obj->get_firmware_version(firmware_version) && | 33 | + // 不同厂商/型号的固件版本偏移不同,由行为表决定;未命中时使用默认偏移 |
| 34 | - is_valid_vpd_string(firmware_version)) { | 34 | + uint8_t firmware_offset = SSD_FIRMWARE_OFFSET; |
| 35 | + std::string product_name; | ||
| 36 | + if (m_vpd_obj->get_product_name(product_name)) { | ||
| 37 | + firmware_offset = static_cast<uint8_t>( | ||
| 38 | + behavior_int({m_vendor_key, product_name}, behavior_key::firmware_offset, SSD_FIRMWARE_OFFSET)); | ||
| 39 | + } | ||
| 40 | + if (m_nvme_oem && m_nvme_oem->OSPowerState.get_value() == 1 && | ||
| 41 | + m_vpd_obj->get_firmware_version(firmware_version, firmware_offset) && is_valid_vpd_string(firmware_version)) { | ||
| 35 | Revision.set_value(firmware_version); | 42 | Revision.set_value(firmware_version); |
| 36 | } | 43 | } |
| 37 | 44 | ||
| 38 | - uint32_t capacity_mib; | 45 | + uint32_t capacity_mib = 0; |
| 39 | if (m_vpd_obj->get_capacity_mib(capacity_mib)) { | 46 | if (m_vpd_obj->get_capacity_mib(capacity_mib)) { |
| 40 | CapacityMiB.set_value(capacity_mib); | 47 | CapacityMiB.set_value(capacity_mib); |
| 48 | + } else { | ||
| 49 | + // VPD 标准容量读取失败时按型号兜底(samsung 特殊型号); | ||
| 50 | + // 型号后缀(如 "-00003")由行为表查询时统一归一化 | ||
| 51 | + std::string model; | ||
| 52 | + if (m_vpd_obj->get_model(model)) { | ||
| 53 | + const auto fallback_bytes = behavior_int({m_vendor_key, {}, model}, behavior_key::capacity_bytes, 0); | ||
| 54 | + if (fallback_bytes > 0) { | ||
| 55 | + capacity_mib = static_cast<uint32_t>(static_cast<uint64_t>(fallback_bytes) / (1024 * 1024)); | ||
| 56 | + CapacityMiB.set_value(capacity_mib); | ||
| 57 | + } else { | ||
| 58 | + dlog("Model '${model}' not found in capacity fallback rules", ("model", model)); | ||
| 59 | + } | ||
| 60 | + } else { | ||
| 61 | + dlog("Failed to get capacity from standard VPD"); | ||
| 62 | + } | ||
| 41 | } | 63 | } |
| 42 | 64 | ||
| 43 | uint8_t capable_speed_gbs; | 65 | uint8_t capable_speed_gbs; |
| @@ -15,6 +15,10 @@ | |||
| 15 | 15 | ||
| 16 | #include <device_tree/interface/NVMe/MultiRecord.h> | 16 | #include <device_tree/interface/NVMe/MultiRecord.h> |
| 17 | #include <nvme/vpd_protocol.h> | 17 | #include <nvme/vpd_protocol.h> |
| 18 | +#include <string> | ||
| 19 | +#include <string_view> | ||
| 20 | + | ||
| 21 | +#include "../../nvme_pcie4_behavior_table.h" | ||
| 18 | 22 | ||
| 19 | namespace dev { | 23 | namespace dev { |
| 20 | 24 | ||
| @@ -33,10 +37,15 @@ public: | |||
| 33 | { | 37 | { |
| 34 | m_nvme_oem = oem; | 38 | m_nvme_oem = oem; |
| 35 | } | 39 | } |
| 40 | + void set_vendor_key(std::string_view vendor_key) | ||
| 41 | + { | ||
| 42 | + m_vendor_key = std::string(vendor_key); | ||
| 43 | + } | ||
| 36 | 44 | ||
| 37 | private: | 45 | private: |
| 38 | vpd_protocol_ptr m_vpd_obj; | 46 | vpd_protocol_ptr m_vpd_obj; |
| 39 | NVMe_Oem* m_nvme_oem = nullptr; | 47 | NVMe_Oem* m_nvme_oem = nullptr; |
| 48 | + std::string m_vendor_key; | ||
| 40 | }; | 49 | }; |
| 41 | 50 | ||
| 42 | } // namespace dev | 51 | } // namespace dev |
| @@ -56,7 +56,8 @@ static std::tuple<bool, std::string> download_chunk(nvme_mi_over_mctp_ptr nvme_m | |||
| 56 | // Active 阶段由用户通过 Redfish 接口下发 commit CA3 | 56 | // Active 阶段由用户通过 Redfish 接口下发 commit CA3 |
| 57 | // @return (true, "") 或 (false, fail_reason) | 57 | // @return (true, "") 或 (false, fail_reason) |
| 58 | static std::tuple<bool, std::string> do_firmware_download(nvme_mi_over_mctp_ptr nvme_mi_obj, uint32_t ctrl_id, | 58 | static std::tuple<bool, std::string> do_firmware_download(nvme_mi_over_mctp_ptr nvme_mi_obj, uint32_t ctrl_id, |
| 59 | - const std::string& image_path, uint8_t retry_times) | 59 | + const std::string& image_path, uint8_t retry_times, |
| 60 | + const std::atomic<bool>* cancel) | ||
| 60 | { | 61 | { |
| 61 | std::ifstream file(image_path, std::ios::binary | std::ios::ate); | 62 | std::ifstream file(image_path, std::ios::binary | std::ios::ate); |
| 62 | if (!file.is_open()) { | 63 | if (!file.is_open()) { |
| @@ -91,6 +92,12 @@ static std::tuple<bool, std::string> do_firmware_download(nvme_mi_over_mctp_ptr | |||
| 91 | bool download_ok = true; | 92 | bool download_ok = true; |
| 92 | uint32_t chunk_idx = 0; | 93 | uint32_t chunk_idx = 0; |
| 93 | while (offset < total_size) { | 94 | while (offset < total_size) { |
| 95 | + // 收到取消信号后立即退出,避免 transport 销毁后继续访问 | ||
| 96 | + if (cancel != nullptr && cancel->load()) { | ||
| 97 | + nlog("do_firmware_download: cancelled at chunk=${idx}, offset=${off}", | ||
| 98 | + ("idx", chunk_idx)("off", offset)); | ||
| 99 | + return std::make_tuple(false, "cancelled"); | ||
| 100 | + } | ||
| 94 | const uint32_t remain = static_cast<uint32_t>(total_size - offset); | 101 | const uint32_t remain = static_cast<uint32_t>(total_size - offset); |
| 95 | uint32_t chunk_size = std::min(fwug, remain); | 102 | uint32_t chunk_size = std::min(fwug, remain); |
| 96 | if ((chunk_size & 0x3U) != 0U) { | 103 | if ((chunk_size & 0x3U) != 0U) { |
| @@ -226,6 +233,7 @@ uint32_t NVMe_NVMeMI::GetTelemetryData(const std::string& data_type) | |||
| 226 | } | 233 | } |
| 227 | 234 | ||
| 228 | // 接口是宿主的值成员;先借用已托管宿主,避免收养裸 new/栈对象。 | 235 | // 接口是宿主的值成员;先借用已托管宿主,避免收养裸 new/栈对象。 |
| 236 | + // owner_guard 会随异步任务一起持有,任务完成前宿主不会被销毁。 | ||
| 229 | auto* owner = get_owner(); | 237 | auto* owner = get_owner(); |
| 230 | auto owner_guard = owner != nullptr && owner->is_managed() ? owner->weak_from_this().lock() : mc::object_ptr{}; | 238 | auto owner_guard = owner != nullptr && owner->is_managed() ? owner->weak_from_this().lock() : mc::object_ptr{}; |
| 231 | if (!owner_guard) { | 239 | if (!owner_guard) { |
| @@ -233,7 +241,7 @@ uint32_t NVMe_NVMeMI::GetTelemetryData(const std::string& data_type) | |||
| 233 | return 0; | 241 | return 0; |
| 234 | } | 242 | } |
| 235 | 243 | ||
| 236 | - if (m_telemetry_running.exchange(true)) { | 244 | + if (m_telemetry_running->exchange(true)) { |
| 237 | elog("GetTelemetryData: telemetry collection already in progress"); | 245 | elog("GetTelemetryData: telemetry collection already in progress"); |
| 238 | return 0; | 246 | return 0; |
| 239 | } | 247 | } |
| @@ -248,16 +256,23 @@ uint32_t NVMe_NVMeMI::GetTelemetryData(const std::string& data_type) | |||
| 248 | 256 | ||
| 249 | if (create_result != mc::app::task::CreateResult::Success) { | 257 | if (create_result != mc::app::task::CreateResult::Success) { |
| 250 | elog("GetTelemetryData: create_task failed, result=${result}", ("result", static_cast<int>(create_result))); | 258 | elog("GetTelemetryData: create_task failed, result=${result}", ("result", static_cast<int>(create_result))); |
| 251 | - m_telemetry_running.store(false); | 259 | + m_telemetry_running->store(false); |
| 252 | return 0; | 260 | return 0; |
| 253 | } | 261 | } |
| 254 | 262 | ||
| 255 | nlog("GetTelemetryData: task created, taskId=${task}, data_type=${type}", ("task", task_id)("type", data_type)); | 263 | nlog("GetTelemetryData: task created, taskId=${task}, data_type=${type}", ("task", task_id)("type", data_type)); |
| 256 | 264 | ||
| 257 | auto nvme_mi_obj = m_nvme_mi_obj; | 265 | auto nvme_mi_obj = m_nvme_mi_obj; |
| 266 | + auto mctp_obj = m_mctp_obj; | ||
| 267 | + auto running = m_telemetry_running; | ||
| 258 | auto ctrl_id = m_ctrl_id; | 268 | auto ctrl_id = m_ctrl_id; |
| 259 | - this->post([this, owner_guard, nvme_mi_obj, ctrl_id, log_id, task_id]() mutable { | 269 | + // 异步任务不捕获 this:本接口对象被析构后任务仍可安全执行。 |
| 260 | - TelemetryGuard guard{m_telemetry_running}; | 270 | + // svc 由应用框架持有,生命周期长于本接口;mctp_obj 用于延长 transport 生命周期, |
| 271 | + // stop 后 request() 会因 parent/endpoint 已清理而安全失败。 | ||
| 272 | + this->post([owner_guard, nvme_mi_obj, mctp_obj, running, ctrl_id, log_id, task_id, svc]() mutable { | ||
| 273 | + (void)owner_guard; | ||
| 274 | + (void)mctp_obj; | ||
| 275 | + TelemetryGuard guard{*running}; | ||
| 261 | 276 | ||
| 262 | mc::dict data; | 277 | mc::dict data; |
| 263 | 278 | ||
| @@ -266,7 +281,7 @@ uint32_t NVMe_NVMeMI::GetTelemetryData(const std::string& data_type) | |||
| 266 | elog("GetTelemetryData: failed to create directory"); | 281 | elog("GetTelemetryData: failed to create directory"); |
| 267 | data["State"] = mc::string("Exception"); | 282 | data["State"] = mc::string("Exception"); |
| 268 | data["Status"] = mc::string("Error"); | 283 | data["Status"] = mc::string("Error"); |
| 269 | - get_app_service()->task_mgmt().update_task(task_id, data); | 284 | + svc->task_mgmt().update_task(task_id, data); |
| 270 | return; | 285 | return; |
| 271 | } | 286 | } |
| 272 | } | 287 | } |
| @@ -276,27 +291,27 @@ uint32_t NVMe_NVMeMI::GetTelemetryData(const std::string& data_type) | |||
| 276 | elog("GetTelemetryData: failed to open file for writing"); | 291 | elog("GetTelemetryData: failed to open file for writing"); |
| 277 | data["State"] = mc::string("Exception"); | 292 | data["State"] = mc::string("Exception"); |
| 278 | data["Status"] = mc::string("Error"); | 293 | data["Status"] = mc::string("Error"); |
| 279 | - get_app_service()->task_mgmt().update_task(task_id, data); | 294 | + svc->task_mgmt().update_task(task_id, data); |
| 280 | return; | 295 | return; |
| 281 | } | 296 | } |
| 282 | 297 | ||
| 283 | data["State"] = mc::string("Running"); | 298 | data["State"] = mc::string("Running"); |
| 284 | data["Status"] = mc::string("OK"); | 299 | data["Status"] = mc::string("OK"); |
| 285 | data["Progress"] = static_cast<int64_t>(0); | 300 | data["Progress"] = static_cast<int64_t>(0); |
| 286 | - get_app_service()->task_mgmt().update_task(task_id, data); | 301 | + svc->task_mgmt().update_task(task_id, data); |
| 287 | 302 | ||
| 288 | - if (!nvme_mi_obj->get_telemetry_data(ctrl_id, log_id, ofs, [this, task_id](uint8_t percent) { | 303 | + if (!nvme_mi_obj->get_telemetry_data(ctrl_id, log_id, ofs, [svc, task_id](uint8_t percent) { |
| 289 | mc::dict prog_data; | 304 | mc::dict prog_data; |
| 290 | prog_data["State"] = mc::string("Running"); | 305 | prog_data["State"] = mc::string("Running"); |
| 291 | prog_data["Status"] = mc::string("OK"); | 306 | prog_data["Status"] = mc::string("OK"); |
| 292 | prog_data["Progress"] = static_cast<int64_t>(percent); | 307 | prog_data["Progress"] = static_cast<int64_t>(percent); |
| 293 | - get_app_service()->task_mgmt().update_task(task_id, prog_data); | 308 | + svc->task_mgmt().update_task(task_id, prog_data); |
| 294 | })) { | 309 | })) { |
| 295 | elog("GetTelemetryData: failed to get telemetry data, ctrl_id=${cid}", ("cid", ctrl_id)); | 310 | elog("GetTelemetryData: failed to get telemetry data, ctrl_id=${cid}", ("cid", ctrl_id)); |
| 296 | ofs.close(); | 311 | ofs.close(); |
| 297 | data["State"] = mc::string("Exception"); | 312 | data["State"] = mc::string("Exception"); |
| 298 | data["Status"] = mc::string("Error"); | 313 | data["Status"] = mc::string("Error"); |
| 299 | - get_app_service()->task_mgmt().update_task(task_id, data); | 314 | + svc->task_mgmt().update_task(task_id, data); |
| 300 | return; | 315 | return; |
| 301 | } | 316 | } |
| 302 | ofs.close(); | 317 | ofs.close(); |
| @@ -306,7 +321,7 @@ uint32_t NVMe_NVMeMI::GetTelemetryData(const std::string& data_type) | |||
| 306 | elog("GetTelemetryData: failed to copy telemetry log"); | 321 | elog("GetTelemetryData: failed to copy telemetry log"); |
| 307 | data["State"] = mc::string("Exception"); | 322 | data["State"] = mc::string("Exception"); |
| 308 | data["Status"] = mc::string("Error"); | 323 | data["Status"] = mc::string("Error"); |
| 309 | - get_app_service()->task_mgmt().update_task(task_id, data); | 324 | + svc->task_mgmt().update_task(task_id, data); |
| 310 | return; | 325 | return; |
| 311 | } | 326 | } |
| 312 | mc::filesystem::remove(NVME_TELEMETRY_LOG_PATH_SRC); | 327 | mc::filesystem::remove(NVME_TELEMETRY_LOG_PATH_SRC); |
| @@ -314,7 +329,7 @@ uint32_t NVMe_NVMeMI::GetTelemetryData(const std::string& data_type) | |||
| 314 | data["State"] = mc::string("Completed"); | 329 | data["State"] = mc::string("Completed"); |
| 315 | data["Status"] = mc::string("OK"); | 330 | data["Status"] = mc::string("OK"); |
| 316 | data["Progress"] = static_cast<int64_t>(100); | 331 | data["Progress"] = static_cast<int64_t>(100); |
| 317 | - get_app_service()->task_mgmt().update_task(task_id, data); | 332 | + svc->task_mgmt().update_task(task_id, data); |
| 318 | nlog("GetTelemetryData: completed, taskId=${task}", ("task", task_id)); | 333 | nlog("GetTelemetryData: completed, taskId=${task}", ("task", task_id)); |
| 319 | }); | 334 | }); |
| 320 | 335 | ||
| @@ -351,15 +366,21 @@ std::vector<uint8_t> NVMe_NVMeMI::GetIdentifyData(uint8_t cns_value) | |||
| 351 | return result; | 366 | return result; |
| 352 | } | 367 | } |
| 353 | 368 | ||
| 354 | -std::tuple<bool, std::string> NVMe_NVMeMI::firmware_upgrade_process(const std::string& image_path, uint8_t retry_times) | 369 | +std::tuple<bool, std::string> NVMe_NVMeMI::firmware_upgrade_process(const std::string& image_path, uint8_t retry_times, |
| 370 | + const std::atomic<bool>* cancel) | ||
| 355 | { | 371 | { |
| 356 | if (!m_nvme_mi_obj) { | 372 | if (!m_nvme_mi_obj) { |
| 357 | elog("NVMe-MI object not initialized"); | 373 | elog("NVMe-MI object not initialized"); |
| 358 | return std::make_tuple(false, "NVMe-MI object not initialized"); | 374 | return std::make_tuple(false, "NVMe-MI object not initialized"); |
| 359 | } | 375 | } |
| 376 | + // 在访问任何 MCTP 资源前检查取消标记:stop 可能已销毁 transport | ||
| 377 | + if (cancel != nullptr && cancel->load()) { | ||
| 378 | + nlog("firmware_upgrade_process: cancelled before download"); | ||
| 379 | + return std::make_tuple(false, "cancelled"); | ||
| 380 | + } | ||
| 360 | nlog("firmware_upgrade_process: download only, retry_times=${retry}", | 381 | nlog("firmware_upgrade_process: download only, retry_times=${retry}", |
| 361 | ("retry", static_cast<uint32_t>(retry_times))); | 382 | ("retry", static_cast<uint32_t>(retry_times))); |
| 362 | - return do_firmware_download(m_nvme_mi_obj, m_ctrl_id, image_path, retry_times); | 383 | + return do_firmware_download(m_nvme_mi_obj, m_ctrl_id, image_path, retry_times, cancel); |
| 363 | } | 384 | } |
| 364 | 385 | ||
| 365 | std::tuple<bool, std::string> NVMe_NVMeMI::firmware_upgrade_active() | 386 | std::tuple<bool, std::string> NVMe_NVMeMI::firmware_upgrade_active() |
| @@ -17,7 +17,8 @@ | |||
| 17 | #include <cstdint> | 17 | #include <cstdint> |
| 18 | #include <device_tree/interface/NVMe/NVMeMI.h> | 18 | #include <device_tree/interface/NVMe/NVMeMI.h> |
| 19 | #include <mc/app/service.h> | 19 | #include <mc/app/service.h> |
| 20 | -#include <nvme/nvme_mi_over_mctp_huawei.h> | 20 | +#include <memory> |
| 21 | +#include <nvme/nvme_mi_over_mctp.h> | ||
| 21 | #include <string> | 22 | #include <string> |
| 22 | #include <tuple> | 23 | #include <tuple> |
| 23 | 24 | ||
| @@ -29,7 +30,7 @@ class NVMe_Oem; | |||
| 29 | #define NVME_CNS_IDENTIFY_NS 0x00 | 30 | #define NVME_CNS_IDENTIFY_NS 0x00 |
| 30 | #define NVME_LOG_PAGE_RAE_CLEAR false | 31 | #define NVME_LOG_PAGE_RAE_CLEAR false |
| 31 | 32 | ||
| 32 | -using nvme_mi_over_mctp_ptr = std::shared_ptr<nvme_mi_over_mctp_huawei>; | 33 | +using nvme_mi_over_mctp_ptr = std::shared_ptr<nvme_mi_over_mctp>; |
| 33 | 34 | ||
| 34 | class MC_API NVMe_NVMeMI : public mc::engine::interface<NVMe_NVMeMI, gen::NVMe_NVMeMI> { | 35 | class MC_API NVMe_NVMeMI : public mc::engine::interface<NVMe_NVMeMI, gen::NVMe_NVMeMI> { |
| 35 | public: | 36 | public: |
| @@ -44,11 +45,17 @@ public: | |||
| 44 | std::vector<uint8_t> GetIdentifyData(uint8_t cns_value) override; | 45 | std::vector<uint8_t> GetIdentifyData(uint8_t cns_value) override; |
| 45 | // Upgrade 阶段:实现 firmware_image_download,不做 commit | 46 | // Upgrade 阶段:实现 firmware_image_download,不做 commit |
| 46 | // commit CA3 由 Active 阶段执行 | 47 | // commit CA3 由 Active 阶段执行 |
| 47 | - std::tuple<bool, std::string> firmware_upgrade_process(const std::string& image_path, uint8_t retry_times); | 48 | + std::tuple<bool, std::string> firmware_upgrade_process(const std::string& image_path, uint8_t retry_times, |
| 49 | + const std::atomic<bool>* cancel = nullptr); | ||
| 48 | // Active 阶段:执行 firmware_commit(CA3),不重试 | 50 | // Active 阶段:执行 firmware_commit(CA3),不重试 |
| 49 | std::tuple<bool, std::string> firmware_upgrade_active(); | 51 | std::tuple<bool, std::string> firmware_upgrade_active(); |
| 50 | 52 | ||
| 51 | void set_nvme_mi_obj(nvme_mi_over_mctp_ptr nvme_mi_obj); | 53 | void set_nvme_mi_obj(nvme_mi_over_mctp_ptr nvme_mi_obj); |
| 54 | + // 供异步任务延长 transport 生命周期,避免 stop 后仍在执行的任务访问已释放对象 | ||
| 55 | + void set_mctp_obj(mc::shared_ptr<mctp> mctp_obj) | ||
| 56 | + { | ||
| 57 | + m_mctp_obj = std::move(mctp_obj); | ||
| 58 | + } | ||
| 52 | void set_ctrl_id(uint32_t ctrl_id) | 59 | void set_ctrl_id(uint32_t ctrl_id) |
| 53 | { | 60 | { |
| 54 | m_ctrl_id = ctrl_id; | 61 | m_ctrl_id = ctrl_id; |
| @@ -65,9 +72,11 @@ public: | |||
| 65 | 72 | ||
| 66 | private: | 73 | private: |
| 67 | nvme_mi_over_mctp_ptr m_nvme_mi_obj; | 74 | nvme_mi_over_mctp_ptr m_nvme_mi_obj; |
| 75 | + mc::shared_ptr<mctp> m_mctp_obj; | ||
| 68 | uint32_t m_ctrl_id = 0; | 76 | uint32_t m_ctrl_id = 0; |
| 69 | - std::atomic<bool> m_telemetry_running{false}; | 77 | + // 用 shared_ptr 持有:异步任务捕获后不再依赖 this 存活 |
| 70 | - NVMe_Oem* m_nvme_oem{nullptr}; | 78 | + std::shared_ptr<std::atomic<bool>> m_telemetry_running = std::make_shared<std::atomic<bool>>(false); |
| 79 | + NVMe_Oem* m_nvme_oem{nullptr}; | ||
| 71 | }; | 80 | }; |
| 72 | 81 | ||
| 73 | } // namespace dev | 82 | } // namespace dev |
| @@ -45,6 +45,14 @@ bool NVMe_ProductInfo::update_product_info_by_vpd() | |||
| 45 | uint32_t manufacturer_id; | 45 | uint32_t manufacturer_id; |
| 46 | // OSPowerState: 0=下电(SSDChip 不可读),1=上电。下电时跳过厂商 id 获取,保持上次值,OS reset 后恢复刷新 | 46 | // OSPowerState: 0=下电(SSDChip 不可读),1=上电。下电时跳过厂商 id 获取,保持上次值,OS reset 后恢复刷新 |
| 47 | if (m_nvme_oem && m_nvme_oem->OSPowerState.get_value() == 1 && m_vpd_obj->get_manufacturer_id(manufacturer_id)) { | 47 | if (m_nvme_oem && m_nvme_oem->OSPowerState.get_value() == 1 && m_vpd_obj->get_manufacturer_id(manufacturer_id)) { |
| 48 | + // 特殊型号使用扩展 Vendor ID(如 samsung PM9A3/PM9D3a) | ||
| 49 | + std::string product_name; | ||
| 50 | + if (m_vpd_obj->get_product_name(product_name)) { | ||
| 51 | + const auto override_id = behavior_int({m_vendor_key, product_name}, behavior_key::manufacturer_id, 0); | ||
| 52 | + if (override_id != 0) { | ||
| 53 | + manufacturer_id = static_cast<uint32_t>(override_id); | ||
| 54 | + } | ||
| 55 | + } | ||
| 48 | ManufacturerId.set_value(manufacturer_id); | 56 | ManufacturerId.set_value(manufacturer_id); |
| 49 | } | 57 | } |
| 50 | 58 | ||
| @@ -15,6 +15,10 @@ | |||
| 15 | 15 | ||
| 16 | #include <device_tree/interface/NVMe/ProductInfo.h> | 16 | #include <device_tree/interface/NVMe/ProductInfo.h> |
| 17 | #include <nvme/vpd_protocol.h> | 17 | #include <nvme/vpd_protocol.h> |
| 18 | +#include <string> | ||
| 19 | +#include <string_view> | ||
| 20 | + | ||
| 21 | +#include "../../nvme_pcie4_behavior_table.h" | ||
| 18 | 22 | ||
| 19 | namespace dev { | 23 | namespace dev { |
| 20 | 24 | ||
| @@ -33,10 +37,15 @@ public: | |||
| 33 | { | 37 | { |
| 34 | m_nvme_oem = oem; | 38 | m_nvme_oem = oem; |
| 35 | } | 39 | } |
| 40 | + void set_vendor_key(std::string_view vendor_key) | ||
| 41 | + { | ||
| 42 | + m_vendor_key = std::string(vendor_key); | ||
| 43 | + } | ||
| 36 | 44 | ||
| 37 | private: | 45 | private: |
| 38 | vpd_protocol_ptr m_vpd_obj; | 46 | vpd_protocol_ptr m_vpd_obj; |
| 39 | NVMe_Oem* m_nvme_oem = nullptr; | 47 | NVMe_Oem* m_nvme_oem = nullptr; |
| 48 | + std::string m_vendor_key; | ||
| 40 | }; | 49 | }; |
| 41 | 50 | ||
| 42 | } // namespace dev | 51 | } // namespace dev |
| @@ -58,15 +58,18 @@ bool NVMe_Smart::update_smart_by_mctp() | |||
| 58 | uint16_t vendor = NVME_VENDOR_STANDARD; | 58 | uint16_t vendor = NVME_VENDOR_STANDARD; |
| 59 | bool success = m_nvme_mi_obj->get_smart_info(ctrl_id, vendor, smart_data); | 59 | bool success = m_nvme_mi_obj->get_smart_info(ctrl_id, vendor, smart_data); |
| 60 | 60 | ||
| 61 | - // 如果标准的失败,尝试华为 vendor-specific 的 SMART log (log_id=0xe5) | 61 | + // 标准日志失败时,按厂商行为表尝试 vendor-specific SMART log |
| 62 | - if (!success) { | 62 | + const uint8_t vendor_log_id = |
| 63 | - nlog("Standard SMART log failed, trying Huawei vendor-specific SMART log (0xe5)"); | 63 | + static_cast<uint8_t>(behavior_int({m_vendor_key}, behavior_key::vendor_smart_log_id, 0)); |
| 64 | - vendor = NVME_VENDOR_HUAWEI_LOG_ID; | 64 | + if (!success && vendor_log_id != 0) { |
| 65 | + nlog("Standard SMART log failed, trying vendor-specific SMART log (0x${lid})", | ||
| 66 | + ("lid", static_cast<uint32_t>(vendor_log_id))); | ||
| 67 | + vendor = vendor_log_id; | ||
| 65 | success = m_nvme_mi_obj->get_smart_info(ctrl_id, vendor, smart_data); | 68 | success = m_nvme_mi_obj->get_smart_info(ctrl_id, vendor, smart_data); |
| 66 | } | 69 | } |
| 67 | 70 | ||
| 68 | if (!success) { | 71 | if (!success) { |
| 69 | - elog("Failed to get SMART info (tried both standard and Huawei vendor-specific)"); | 72 | + elog("Failed to get SMART info (tried both standard and vendor-specific logs)"); |
| 70 | return false; | 73 | return false; |
| 71 | } | 74 | } |
| 72 | 75 | ||
| @@ -91,11 +94,17 @@ bool NVMe_Smart::update_smart_by_mctp() | |||
| 91 | CriticalWarning.set_value(smart_log.critical_warning); | 94 | CriticalWarning.set_value(smart_log.critical_warning); |
| 92 | AvailableSpare.set_value(smart_log.avail_spare); | 95 | AvailableSpare.set_value(smart_log.avail_spare); |
| 93 | UsedPercentage.set_value(smart_log.percent_used); | 96 | UsedPercentage.set_value(smart_log.percent_used); |
| 94 | - TLCSpareBlockPercentage.set_value(smart_log.avail_spare); | 97 | + // 部分厂商(如 dapustor)不能直接取标准 Available Spare,由上层结合厂商日志的 |
| 98 | + // TlcValidSpareBlock/TlcTotalSpareBlock 计算,见 update_nvme_properties_from_smart | ||
| 99 | + if (behavior_bool({m_vendor_key}, behavior_key::tlc_from_avail_spare, true)) { | ||
| 100 | + TLCSpareBlockPercentage.set_value(smart_log.avail_spare); | ||
| 101 | + if (m_nvme_oem != nullptr) { | ||
| 102 | + m_nvme_oem->update_prop_without_bma("TLCSpareBlockPercentage", mc::variant(smart_log.avail_spare)); | ||
| 103 | + } | ||
| 104 | + } | ||
🟡 Medium Priority 变更行(smart.cpp:97-104)把 TLCSpareBlockPercentage 的赋值与 update_prop_without_bma 快照一起放进了 但上层 update_nvme_properties_from_smart(nvme_pcie4_driver.h:805-816)在算完 建议:需与 nvme_pcie4_driver.h 的 update_nvme_properties_from_smart 一起调整,不能只改本处:确认 dapustor 的 TLCSpareBlockPercentage 唯一写入点在 driver 侧,并把 driver 侧第 813 行的 tlc_from_avail_spare 条件改为无条件(已由 mctp_huawei 提前过滤),或在本文件为 tlc_from_avail_spare=false 的厂商补一个由厂商日志计算写入的分支。 ![]() ![]() Incorrect? | |||
| 95 | PowerOnHours.set_value(power_on_hours); | 105 | PowerOnHours.set_value(power_on_hours); |
| 96 | // 记录带外获取到的值到快照,用于 BMA 断开后恢复 | 106 | // 记录带外获取到的值到快照,用于 BMA 断开后恢复 |
| 97 | if (m_nvme_oem) { | 107 | if (m_nvme_oem) { |
| 98 | - m_nvme_oem->update_prop_without_bma("TLCSpareBlockPercentage", mc::variant(smart_log.avail_spare)); | ||
| 99 | m_nvme_oem->update_prop_without_bma("PowerOnHours", mc::variant(power_on_hours)); | 108 | m_nvme_oem->update_prop_without_bma("PowerOnHours", mc::variant(power_on_hours)); |
| 100 | } | 109 | } |
| 101 | return true; | 110 | return true; |
| @@ -16,13 +16,15 @@ | |||
| 16 | #include <device_tree/interface/NVMe/Smart.h> | 16 | #include <device_tree/interface/NVMe/Smart.h> |
| 17 | #include <functional> | 17 | #include <functional> |
| 18 | #include <mc/timer.h> | 18 | #include <mc/timer.h> |
| 19 | -#include <nvme/nvme_mi_over_mctp_huawei.h> | 19 | +#include <nvme/nvme_mi_over_mctp.h> |
| 20 | +#include <string> | ||
| 21 | +#include <string_view> | ||
| 22 | + | ||
| 23 | +#include "../../nvme_pcie4_behavior_table.h" | ||
| 20 | 24 | ||
| 21 | namespace dev { | 25 | namespace dev { |
| 22 | 26 | ||
| 23 | -#define NVME_VENDOR_HUAWEI_LOG_ID 0xe5 | 27 | +using nvme_mi_over_mctp_ptr = std::shared_ptr<nvme_mi_over_mctp>; |
| 24 | - | ||
| 25 | -using nvme_mi_over_mctp_ptr = std::shared_ptr<nvme_mi_over_mctp_huawei>; | ||
| 26 | 28 | ||
| 27 | class NVMe_Oem; | 29 | class NVMe_Oem; |
| 28 | 30 | ||
| @@ -46,6 +48,10 @@ public: | |||
| 46 | { | 48 | { |
| 47 | m_nvme_oem = oem; | 49 | m_nvme_oem = oem; |
| 48 | } | 50 | } |
| 51 | + void set_vendor_key(std::string_view vendor_key) | ||
| 52 | + { | ||
| 53 | + m_vendor_key = std::string(vendor_key); | ||
| 54 | + } | ||
| 49 | 55 | ||
| 50 | private: | 56 | private: |
| 51 | nvme_mi_over_mctp_ptr m_nvme_mi_obj; | 57 | nvme_mi_over_mctp_ptr m_nvme_mi_obj; |
| @@ -53,6 +59,7 @@ private: | |||
| 53 | std::function<void()> m_on_update_callback; | 59 | std::function<void()> m_on_update_callback; |
| 54 | uint32_t m_ctrl_id = 0; | 60 | uint32_t m_ctrl_id = 0; |
| 55 | NVMe_Oem* m_nvme_oem = nullptr; | 61 | NVMe_Oem* m_nvme_oem = nullptr; |
| 62 | + std::string m_vendor_key; | ||
| 56 | }; | 63 | }; |
| 57 | 64 | ||
| 58 | } // namespace dev | 65 | } // namespace dev |
| @@ -53,10 +53,10 @@ bool NVMe_Status::update_status_by_vpd() | |||
| 53 | // bit5 Drive Functional ,1表示正常的 | 53 | // bit5 Drive Functional ,1表示正常的 |
| 54 | // bit6 Drive Not Ready,0是正常的 | 54 | // bit6 Drive Not Ready,0是正常的 |
| 55 | { | 55 | { |
| 56 | - constexpr uint8_t expression = 0x60; // 01100000 华为忽略bit3 | 56 | + // 华为/大普微忽略 bit3(Port0 Link Active),只看 bit5/bit6;其余厂商同时检查 bit3 |
| 57 | - uint8_t f = basic_info.status_flags; | 57 | + const bool ignore_link_active = behavior_bool({m_vendor_key}, behavior_key::ignore_port_link_active, false); |
| 58 | - int ssd_fault = ((f & expression) == 0x20) ? 0 : 1; | 58 | + int ssd_fault = is_nvme_status_fault(basic_info.status_flags, ignore_link_active) ? 1 : 0; |
| 59 | - auto val = debounce_failure->get_debounce_val(ssd_fault); | 59 | + auto val = debounce_failure->get_debounce_val(ssd_fault); |
| 60 | if (val.has_value() && elapsed >= NVME_ALARM_DELAY_SECONDS) { | 60 | if (val.has_value() && elapsed >= NVME_ALARM_DELAY_SECONDS) { |
| 61 | Failure.set_value(val.value()); | 61 | Failure.set_value(val.value()); |
| 62 | } | 62 | } |
| @@ -14,10 +14,15 @@ | |||
| 14 | #define NVME_STATUS_H | 14 | #define NVME_STATUS_H |
| 15 | 15 | ||
| 16 | #include <chrono> | 16 | #include <chrono> |
| 17 | +#include <cstdint> | ||
| 17 | #include <device_tree/interface/NVMe/Status.h> | 18 | #include <device_tree/interface/NVMe/Status.h> |
| 18 | #include <mc/debounce/base.h> | 19 | #include <mc/debounce/base.h> |
| 19 | #include <mc/timer.h> | 20 | #include <mc/timer.h> |
| 20 | #include <nvme/vpd_protocol.h> | 21 | #include <nvme/vpd_protocol.h> |
| 22 | +#include <string> | ||
| 23 | +#include <string_view> | ||
| 24 | + | ||
| 25 | +#include "../../nvme_pcie4_behavior_table.h" | ||
| 21 | 26 | ||
| 22 | #define NVME_FAILURE_DEBOUNCE_COUNT 5 | 27 | #define NVME_FAILURE_DEBOUNCE_COUNT 5 |
| 23 | #define NVME_PRE_FAILURE_DEBOUNCE_COUNT 5 | 28 | #define NVME_PRE_FAILURE_DEBOUNCE_COUNT 5 |
| @@ -27,6 +32,16 @@ namespace dev { | |||
| 27 | 32 | ||
| 28 | using vpd_protocol_ptr = std::shared_ptr<vpd_protocol>; | 33 | using vpd_protocol_ptr = std::shared_ptr<vpd_protocol>; |
| 29 | 34 | ||
| 35 | +// Status Flags 故障判定:bit5 Drive Functional=1、bit6 Drive Not Ready=0 为正常。 | ||
| 36 | +// ignore_link_active=true(华为/大普微)时忽略 bit3 Port0 Link Active; | ||
| 37 | +// 其余厂商额外要求 bit3=1。 | ||
| 38 | +inline bool is_nvme_status_fault(uint8_t status_flags, bool ignore_link_active) | ||
| 39 | +{ | ||
| 40 | + const uint8_t expression = ignore_link_active ? 0x60 : 0x68; | ||
| 41 | + const uint8_t expected = ignore_link_active ? 0x20 : 0x28; | ||
| 42 | + return (status_flags & expression) != expected; | ||
| 43 | +} | ||
| 44 | + | ||
| 30 | class MC_API NVMe_Status : public mc::engine::interface<NVMe_Status, gen::NVMe_Status> { | 45 | class MC_API NVMe_Status : public mc::engine::interface<NVMe_Status, gen::NVMe_Status> { |
| 31 | public: | 46 | public: |
| 32 | NVMe_Status() = default; | 47 | NVMe_Status() = default; |
| @@ -38,9 +53,14 @@ public: | |||
| 38 | void start_vpd_update_task(vpd_protocol_ptr vpd, mc::milliseconds interval); | 53 | void start_vpd_update_task(vpd_protocol_ptr vpd, mc::milliseconds interval); |
| 39 | void stop_vpd_update_task(); | 54 | void stop_vpd_update_task(); |
| 40 | bool update_status_by_vpd(); | 55 | bool update_status_by_vpd(); |
| 56 | + void set_vendor_key(std::string_view vendor_key) | ||
| 57 | + { | ||
| 58 | + m_vendor_key = std::string(vendor_key); | ||
| 59 | + } | ||
| 41 | 60 | ||
| 42 | private: | 61 | private: |
| 43 | vpd_protocol_ptr m_vpd_obj; | 62 | vpd_protocol_ptr m_vpd_obj; |
| 63 | + std::string m_vendor_key; | ||
| 44 | mc::shared_ptr<mc::timer> m_vpd_timer; | 64 | mc::shared_ptr<mc::timer> m_vpd_timer; |
| 45 | std::chrono::steady_clock::time_point m_start_time; | 65 | std::chrono::steady_clock::time_point m_start_time; |
| 46 | 66 | ||
| @@ -15,6 +15,29 @@ | |||
| 15 | 15 | ||
| 16 | namespace dev { | 16 | namespace dev { |
| 17 | 17 | ||
| 18 | +namespace { | ||
| 19 | +// 与 storage 及 CSR 的 INVALID_U32 语义保持一致 | ||
| 20 | +constexpr uint32_t kInvalidU32 = 0xFFFFFFFF; | ||
| 21 | +} // namespace | ||
| 22 | + | ||
| 23 | +NVMe_VendorSpecificSmart::NVMe_VendorSpecificSmart() | ||
| 24 | +{ | ||
| 25 | + TlcTotalSpareBlock.set_value(kInvalidU32); | ||
| 26 | + SlcTotalSpareBlock.set_value(kInvalidU32); | ||
| 27 | + TlcValidSpareBlock.set_value(kInvalidU32); | ||
| 28 | + SlcValidSpareBlock.set_value(kInvalidU32); | ||
| 29 | + TlcUsedLifespan.set_value(kInvalidU32); | ||
| 30 | + SlcUsedLifespan.set_value(kInvalidU32); | ||
| 31 | + TlcNandWriteLow.set_value(kInvalidU32); | ||
| 32 | + TlcNandWriteHigh.set_value(kInvalidU32); | ||
| 33 | + TlcPeCycle.set_value(kInvalidU32); | ||
| 34 | + SlcPeCycle.set_value(kInvalidU32); | ||
| 35 | + TlcEraseCount.set_value(kInvalidU32); | ||
| 36 | + SlcEraseCount.set_value(kInvalidU32); | ||
| 37 | + TlcWearout.set_value(kInvalidU32); | ||
| 38 | + SlcWearout.set_value(kInvalidU32); | ||
| 39 | +} | ||
| 40 | + | ||
| 18 | void NVMe_VendorSpecificSmart::start_mctp_update_task(nvme_mi_over_mctp_huawei_ptr nvme_mi_obj, | 41 | void NVMe_VendorSpecificSmart::start_mctp_update_task(nvme_mi_over_mctp_huawei_ptr nvme_mi_obj, |
| 19 | mc::milliseconds interval) | 42 | mc::milliseconds interval) |
| 20 | { | 43 | { |
| @@ -38,7 +61,7 @@ void NVMe_VendorSpecificSmart::stop_mctp_update_task() | |||
| 38 | std::vector<uint8_t> NVMe_VendorSpecificSmart::GetLogPage(uint8_t vendor_specific_lid) | 61 | std::vector<uint8_t> NVMe_VendorSpecificSmart::GetLogPage(uint8_t vendor_specific_lid) |
| 39 | { | 62 | { |
| 40 | if (!m_nvme_mi_obj) { | 63 | if (!m_nvme_mi_obj) { |
| 41 | - elog("NVMe-MI Huawei object not initialized"); | 64 | + elog("NVMe-MI MCTP object not initialized"); |
| 42 | return {}; | 65 | return {}; |
| 43 | } | 66 | } |
| 44 | 67 | ||
| @@ -68,7 +91,7 @@ std::vector<uint8_t> NVMe_VendorSpecificSmart::GetLogPage(uint8_t vendor_specifi | |||
| 68 | bool NVMe_VendorSpecificSmart::update_vendor_specific_smart_by_mctp() | 91 | bool NVMe_VendorSpecificSmart::update_vendor_specific_smart_by_mctp() |
| 69 | { | 92 | { |
| 70 | if (!m_nvme_mi_obj) { | 93 | if (!m_nvme_mi_obj) { |
| 71 | - elog("NVMe-MI Huawei object not initialized"); | 94 | + elog("NVMe-MI MCTP object not initialized"); |
| 72 | return false; | 95 | return false; |
| 73 | } | 96 | } |
| 74 | 97 | ||
| @@ -24,7 +24,10 @@ using nvme_mi_over_mctp_huawei_ptr = std::shared_ptr<nvme_mi_over_mctp_huawei>; | |||
| 24 | class MC_API NVMe_VendorSpecificSmart | 24 | class MC_API NVMe_VendorSpecificSmart |
| 25 | : public mc::engine::interface<NVMe_VendorSpecificSmart, gen::NVMe_VendorSpecificSmart> { | 25 | : public mc::engine::interface<NVMe_VendorSpecificSmart, gen::NVMe_VendorSpecificSmart> { |
| 26 | public: | 26 | public: |
| 27 | - NVMe_VendorSpecificSmart() = default; | 27 | + // 属性初始化为无效值(0xFFFFFFFF):全部厂商都暴露本接口, |
| 28 | + // 但只有 huawei/dapustor 启动采集;未采集厂商若保留默认 0, | ||
| 29 | + // 会被 storage 当作有效数据(如 UsedLifespan=0 推导出剩余寿命 0%)。 | ||
| 30 | + NVMe_VendorSpecificSmart(); | ||
| 28 | ~NVMe_VendorSpecificSmart() | 31 | ~NVMe_VendorSpecificSmart() |
| 29 | { | 32 | { |
| 30 | stop_mctp_update_task(); | 33 | stop_mctp_update_task(); |
| @@ -21,7 +21,7 @@ | |||
| 21 | #include <mc/filesystem.h> | 21 | #include <mc/filesystem.h> |
| 22 | #include <mc/log.h> | 22 | #include <mc/log.h> |
| 23 | 23 | ||
| 24 | -#include "../hw_nvme_pcie4/hw_nvme_pcie4.h" | 24 | +#include "../nvme_pcie4_behavior_table.h" |
| 25 | 25 | ||
| 26 | namespace dev { | 26 | namespace dev { |
| 27 | 27 | ||
| @@ -42,9 +42,22 @@ constexpr uint8_t RETRY_TIMES_DEFAULT = 3; | |||
| 42 | 42 | ||
| 43 | NVMe_Upgrade::~NVMe_Upgrade() | 43 | NVMe_Upgrade::~NVMe_Upgrade() |
| 44 | { | 44 | { |
| 45 | + cancel_and_join(); | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +void NVMe_Upgrade::cancel_and_join() | ||
| 49 | +{ | ||
| 50 | + std::lock_guard<std::mutex> lock(m_thread_mutex); | ||
| 51 | + m_cancel_upgrade.store(true); | ||
| 45 | if (m_upgrade_thread && m_upgrade_thread->joinable()) { | 52 | if (m_upgrade_thread && m_upgrade_thread->joinable()) { |
| 46 | m_upgrade_thread->join(); | 53 | m_upgrade_thread->join(); |
| 47 | } | 54 | } |
| 55 | + m_upgrade_thread.reset(); | ||
| 56 | +} | ||
🔵 Low Priority 变更点:upgrade.cpp:48-56 的 失败模式:OS 下电/OS reset/BDF 变化都会经 stop_mctp_update_tasks → cancel_and_join 把标记永久置真。若随后的重启路径没有走到 start_mctp_update_tasks(例如 start_mctp_protocol 在 nvme_pcie4_driver.h:488 的 修法:在 Upgrade() 入口( ![]() ![]() Incorrect? | |||
| 57 | + | ||
| 58 | +void NVMe_Upgrade::reset_cancel() | ||
| 59 | +{ | ||
| 60 | + m_cancel_upgrade.store(false); | ||
| 48 | } | 61 | } |
| 49 | 62 | ||
| 50 | void NVMe_Upgrade::update_progress(uint8_t percent) | 63 | void NVMe_Upgrade::update_progress(uint8_t percent) |
| @@ -66,6 +79,10 @@ bool NVMe_Upgrade::Upgrade(const std::string& firmware_type, const std::string& | |||
| 66 | update_result(false, RESULT_CARD_NOT_INITIALIZED, "nvme card not initialized"); | 79 | update_result(false, RESULT_CARD_NOT_INITIALIZED, "nvme card not initialized"); |
| 67 | return false; | 80 | return false; |
| 68 | } | 81 | } |
| 82 | + if (!behavior_bool({m_nvme_card->vendor_key()}, behavior_key::upgrade_supported, true)) { | ||
| 83 | + elog("${vendor} NVMe Upgrade not supported", ("vendor", m_nvme_card->vendor_key())); | ||
| 84 | + return false; | ||
| 85 | + } | ||
🔵 Low Priority 变更点:upgrade.cpp:82-85(Upgrade)与 176-179(Active)新增 影响的行为契约:ResultCode/ResultDetail/Status 是升级接口对外(资源树/BMA)暴露的执行结果。其它失败分支(1/2/3/5/6 行号附近的 RESULT_*)均会刷新这三者。 失败模式:前一次升级成功使 Status="Success"、ResultCode=0 后,再对不支持升级的厂商(行为表 samsung 配 upgrade_supported=false)调用 Upgrade/Active,接口返回 false 但资源树仍显示上次的 Success/0,导致上层误判为成功、或状态长期停留在过期结果;Active 同理没有 RESULT_ACTIVE_FAILED/专属错误码。修法:新增一个“厂商不支持升级”的结果码,并在该分支调用 建议:为“厂商不支持升级”新增 RESULT_* 错误码,并在 Upgrade/Active 的该提前返回分支调用 update_result(false, ...),保持与其它失败分支一致;Active 处同改。 ![]() ![]() Incorrect? | |||
| 69 | if (m_is_upgrading.exchange(true)) { | 86 | if (m_is_upgrading.exchange(true)) { |
| 70 | elog("NVMe Upgrade failed: already upgrading"); | 87 | elog("NVMe Upgrade failed: already upgrading"); |
| 71 | update_result(false, RESULT_ALREADY_UPGRADING, "already upgrading"); | 88 | update_result(false, RESULT_ALREADY_UPGRADING, "already upgrading"); |
| @@ -77,7 +94,7 @@ bool NVMe_Upgrade::Upgrade(const std::string& firmware_type, const std::string& | |||
| 77 | ResultDetail.set_value(""); | 94 | ResultDetail.set_value(""); |
| 78 | update_progress(NVME_PROGRESS_INITIAL); | 95 | update_progress(NVME_PROGRESS_INITIAL); |
| 79 | 96 | ||
| 80 | - const uint8_t slot = m_nvme_card->m_nvme.Slot.get_value().as<uint8_t>(); | 97 | + const uint8_t slot = m_nvme_card->nvme().Slot.get_value().as<uint8_t>(); |
| 81 | 98 | ||
| 82 | if (firmware_type != FIRMWARE_TYPE_DRIVE) { | 99 | if (firmware_type != FIRMWARE_TYPE_DRIVE) { |
| 83 | elog("NVMe Upgrade failed: unsupported firmware type ${type}", ("type", firmware_type)); | 100 | elog("NVMe Upgrade failed: unsupported firmware type ${type}", ("type", firmware_type)); |
| @@ -91,7 +108,7 @@ bool NVMe_Upgrade::Upgrade(const std::string& firmware_type, const std::string& | |||
| 91 | m_is_upgrading.store(false); | 108 | m_is_upgrading.store(false); |
| 92 | return false; | 109 | return false; |
| 93 | } | 110 | } |
| 94 | - if (!m_nvme_card->m_nvme_management.SupportedMctpOverPcie.get_value().as<bool>()) { | 111 | + if (!m_nvme_card->nvme_management().SupportedMctpOverPcie.get_value().as<bool>()) { |
| 95 | elog("NVMe Upgrade failed: mctp over pcie is disabled, slot=${slot}", ("slot", static_cast<uint32_t>(slot))); | 112 | elog("NVMe Upgrade failed: mctp over pcie is disabled, slot=${slot}", ("slot", static_cast<uint32_t>(slot))); |
| 96 | update_result(false, RESULT_MCTP_OVER_PCIE_DISABLED, "mctp over pcie is disabled"); | 113 | update_result(false, RESULT_MCTP_OVER_PCIE_DISABLED, "mctp over pcie is disabled"); |
| 97 | m_is_upgrading.store(false); | 114 | m_is_upgrading.store(false); |
| @@ -105,19 +122,21 @@ bool NVMe_Upgrade::Upgrade(const std::string& firmware_type, const std::string& | |||
| 105 | 122 | ||
| 106 | void NVMe_Upgrade::do_download_async(const std::string& file_path) | 123 | void NVMe_Upgrade::do_download_async(const std::string& file_path) |
| 107 | { | 124 | { |
| 125 | + std::lock_guard<std::mutex> lock(m_thread_mutex); | ||
| 126 | + | ||
| 108 | // 等待前一个线程结束 | 127 | // 等待前一个线程结束 |
| 109 | if (m_upgrade_thread && m_upgrade_thread->joinable()) { | 128 | if (m_upgrade_thread && m_upgrade_thread->joinable()) { |
| 110 | m_upgrade_thread->join(); | 129 | m_upgrade_thread->join(); |
| 111 | } | 130 | } |
| 112 | 131 | ||
| 113 | m_upgrade_thread = std::make_unique<std::thread>([this, file_path]() { | 132 | m_upgrade_thread = std::make_unique<std::thread>([this, file_path]() { |
| 114 | - const uint8_t slot = m_nvme_card->m_nvme.Slot.get_value().as<uint8_t>(); | 133 | + const uint8_t slot = m_nvme_card->nvme().Slot.get_value().as<uint8_t>(); |
| 115 | const uint8_t retry_times = RETRY_TIMES_DEFAULT; | 134 | const uint8_t retry_times = RETRY_TIMES_DEFAULT; |
| 116 | 135 | ||
| 117 | bool download_ok = false; | 136 | bool download_ok = false; |
| 118 | std::string download_msg; | 137 | std::string download_msg; |
| 119 | try { | 138 | try { |
| 120 | - auto result = m_nvme_card->m_nvme_nvme_mi.firmware_upgrade_process(file_path, retry_times); | 139 | + auto result = m_nvme_card->nvme_mi().firmware_upgrade_process(file_path, retry_times, &m_cancel_upgrade); |
| 121 | download_ok = std::get<0>(result); | 140 | download_ok = std::get<0>(result); |
| 122 | download_msg = std::get<1>(result); | 141 | download_msg = std::get<1>(result); |
| 123 | } catch (const std::exception& e) { | 142 | } catch (const std::exception& e) { |
| @@ -153,7 +172,11 @@ bool NVMe_Upgrade::Active(const std::string& firmware_type) | |||
| 153 | update_result(false, RESULT_CARD_NOT_INITIALIZED, "nvme card not initialized"); | 172 | update_result(false, RESULT_CARD_NOT_INITIALIZED, "nvme card not initialized"); |
| 154 | return false; | 173 | return false; |
| 155 | } | 174 | } |
| 156 | - const uint8_t slot = m_nvme_card->m_nvme.Slot.get_value().as<uint8_t>(); | 175 | + if (!behavior_bool({m_nvme_card->vendor_key()}, behavior_key::upgrade_supported, true)) { |
| 176 | + elog("${vendor} NVMe Active not supported", ("vendor", m_nvme_card->vendor_key())); | ||
| 177 | + return false; | ||
| 178 | + } | ||
| 179 | + const uint8_t slot = m_nvme_card->nvme().Slot.get_value().as<uint8_t>(); | ||
| 157 | if (firmware_type != FIRMWARE_TYPE_DRIVE) { | 180 | if (firmware_type != FIRMWARE_TYPE_DRIVE) { |
| 158 | elog("NVMe Active failed: unsupported firmware type ${type}, slot=${slot}", | 181 | elog("NVMe Active failed: unsupported firmware type ${type}, slot=${slot}", |
| 159 | ("type", firmware_type)("slot", static_cast<uint32_t>(slot))); | 182 | ("type", firmware_type)("slot", static_cast<uint32_t>(slot))); |
| @@ -161,7 +184,7 @@ bool NVMe_Upgrade::Active(const std::string& firmware_type) | |||
| 161 | return false; | 184 | return false; |
| 162 | } | 185 | } |
| 163 | 186 | ||
| 164 | - auto [ok, msg] = m_nvme_card->m_nvme_nvme_mi.firmware_upgrade_active(); | 187 | + auto [ok, msg] = m_nvme_card->nvme_mi().firmware_upgrade_active(); |
| 165 | if (ok) { | 188 | if (ok) { |
| 166 | nlog("NVMe Active success, slot=${slot}", ("slot", static_cast<uint32_t>(slot))); | 189 | nlog("NVMe Active success, slot=${slot}", ("slot", static_cast<uint32_t>(slot))); |
| 167 | std::ostringstream detail; | 190 | std::ostringstream detail; |
| @@ -10,8 +10,8 @@ | |||
| 10 | * See the Mulan PSL v2 for more details. | 10 | * See the Mulan PSL v2 for more details. |
| 11 | */ | 11 | */ |
| 12 | 12 | ||
| 13 | -#ifndef PCIE_NVME_HUAWEI_UPGRADE_H | 13 | +#ifndef NVME_PCIE4_UPGRADE_H |
| 14 | -#define PCIE_NVME_HUAWEI_UPGRADE_H | 14 | +#define NVME_PCIE4_UPGRADE_H |
| 15 | 15 | ||
| 16 | #define NVME_PROGRESS_INITIAL 0u | 16 | #define NVME_PROGRESS_INITIAL 0u |
| 17 | #define NVME_PROGRESS_COMPLETE 100u | 17 | #define NVME_PROGRESS_COMPLETE 100u |
| @@ -19,14 +19,15 @@ | |||
| 19 | #include <atomic> | 19 | #include <atomic> |
| 20 | #include <cstddef> | 20 | #include <cstddef> |
| 21 | #include <memory> | 21 | #include <memory> |
| 22 | +#include <mutex> | ||
| 22 | #include <string> | 23 | #include <string> |
| 23 | #include <thread> | 24 | #include <thread> |
| 24 | 25 | ||
| 25 | #include <device_tree/interface/Upgrade.h> | 26 | #include <device_tree/interface/Upgrade.h> |
| 26 | 27 | ||
| 27 | -namespace dev { | 28 | +#include "../nvme_pcie4_card_if.h" |
| 28 | 29 | ||
| 29 | -class hw_nvme_pcie4; | 30 | +namespace dev { |
| 30 | 31 | ||
| 31 | class MC_API NVMe_Upgrade : public mc::engine::interface<NVMe_Upgrade, gen::FWUpgrade> { | 32 | class MC_API NVMe_Upgrade : public mc::engine::interface<NVMe_Upgrade, gen::FWUpgrade> { |
| 32 | public: | 33 | public: |
| @@ -36,7 +37,13 @@ public: | |||
| 36 | bool Upgrade(const std::string& firmware_type, const std::string& protocol, const std::string& file_path) override; | 37 | bool Upgrade(const std::string& firmware_type, const std::string& protocol, const std::string& file_path) override; |
| 37 | bool Active(const std::string& firmware_type) override; | 38 | bool Active(const std::string& firmware_type) override; |
| 38 | 39 | ||
| 39 | - void set_nvme_card(hw_nvme_pcie4* card) | 40 | + // 通知升级线程退出并等待其结束。调用后保证升级线程不会再访问 |
| 41 | + // nvme_mi / mctp 对象,可安全销毁 transport。 | ||
| 42 | + void cancel_and_join(); | ||
| 43 | + // transport 重新建立后调用,允许再次发起升级 | ||
| 44 | + void reset_cancel(); | ||
| 45 | + | ||
| 46 | + void set_nvme_card(nvme_pcie4_card_if* card) | ||
| 40 | { | 47 | { |
| 41 | m_nvme_card = card; | 48 | m_nvme_card = card; |
| 42 | } | 49 | } |
| @@ -46,11 +53,13 @@ private: | |||
| 46 | void update_result(bool success, uint32_t code, const std::string& detail); | 53 | void update_result(bool success, uint32_t code, const std::string& detail); |
| 47 | void do_download_async(const std::string& file_path); | 54 | void do_download_async(const std::string& file_path); |
| 48 | 55 | ||
| 49 | - hw_nvme_pcie4* m_nvme_card = nullptr; | 56 | + nvme_pcie4_card_if* m_nvme_card = nullptr; |
| 50 | std::atomic<bool> m_is_upgrading{false}; | 57 | std::atomic<bool> m_is_upgrading{false}; |
| 58 | + std::atomic<bool> m_cancel_upgrade{false}; | ||
| 59 | + std::mutex m_thread_mutex; | ||
| 51 | std::unique_ptr<std::thread> m_upgrade_thread; | 60 | std::unique_ptr<std::thread> m_upgrade_thread; |
| 52 | }; | 61 | }; |
| 53 | 62 | ||
| 54 | } // namespace dev | 63 | } // namespace dev |
| 55 | 64 | ||
| 56 | -#endif // PCIE_NVME_HUAWEI_UPGRADE_H | 65 | +#endif // NVME_PCIE4_UPGRADE_H |
| @@ -1,7 +1,8 @@ | |||
| 1 | -# PCIe4 NVMe 行为差异表 | 1 | +# PCIe4 NVMe 厂商驱动公共代码 |
| 2 | # | 2 | # |
| 3 | -# 行为表独立编译为静态库,先保证表数据与查询逻辑可编译; | 3 | +# 行为差异表独立编译为静态库,保证表数据与查询逻辑可编译; |
| 4 | -# 厂商驱动接入与公共接口层在后续提交中完成。 | 4 | +# 所有厂商的接口实现(PCIeDevice/NVMe/Cooling/Upgrade 等)统一在此编译一次, |
| 5 | +# 各厂商的 shared_library 通过 link_whole 复用,厂商目录只保留差异配置与对象声明。 | ||
| 5 | 6 | ||
| 6 | message('开始构建 pcie_nvme 公共代码') | 7 | message('开始构建 pcie_nvme 公共代码') |
| 7 | 8 | ||
| @@ -9,6 +10,23 @@ pcie_nvme_common_inc = include_directories('.') | |||
| 9 | 10 | ||
| 10 | pcie_nvme_common_sources = files( | 11 | pcie_nvme_common_sources = files( |
| 11 | 'nvme_pcie4_behavior_table.cpp', | 12 | 'nvme_pcie4_behavior_table.cpp', |
L [P1] 公共实现的前置文件未包含在当前分支,Meson 配置直接失败
将该 SHA 的原样 请将对应前置提交纳入本分支,或调整依赖/合入顺序并更新分支,使本 PR 的实际可构建版本包含上述公共实现,再执行完整配置、编译和 Huawei 驱动回归。 ![]() ![]() | |||
| 13 | + 'interface/pcie_device.cpp', | ||
| 14 | + 'interface/pcie_device/pcie_function.cpp', | ||
| 15 | + 'interface/pcie_device/oem.cpp', | ||
| 16 | + 'interface/pcie_device/status.cpp', | ||
| 17 | + 'interface/upgrade.cpp', | ||
| 18 | + 'interface/nvme.cpp', | ||
| 19 | + 'interface/nvme/management.cpp', | ||
| 20 | + 'interface/nvme/product_info.cpp', | ||
| 21 | + 'interface/nvme/multi_record.cpp', | ||
| 22 | + 'interface/nvme/status.cpp', | ||
| 23 | + 'interface/cooling.cpp', | ||
| 24 | + 'interface/nvme/basic_management.cpp', | ||
| 25 | + 'interface/nvme/nvme_mi.cpp', | ||
| 26 | + 'interface/nvme/log_collection.cpp', | ||
| 27 | + 'interface/nvme/smart.cpp', | ||
| 28 | + 'interface/nvme/vendor_specific_smart.cpp', | ||
| 29 | + 'interface/nvme/oem.cpp', | ||
| 12 | ) | 30 | ) |
| 13 | 31 | ||
| 14 | libpcie_nvme_common_static = static_library( | 32 | libpcie_nvme_common_static = static_library( |
| @@ -1,9 +1,8 @@ | |||
| 1 | /* | 1 | /* |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. |
| 3 | * openUBMC is licensed under Mulan PSL v2. | 3 | * openUBMC is licensed under Mulan PSL v2. |
| 4 | * You can use this software according to the terms and conditions of the Mulan PSL v2. | 4 | * You can use this software according to the terms and conditions of the Mulan PSL v2. |
| 5 | - * You may obtain a copy of Mulan PSL v2 at: | 5 | + * You may obtain a copy of Mulan PSL v2 at: http://license.coscl.org.cn/MulanPSL2 |
| 6 | - * http://license.coscl.org.cn/MulanPSL2 | ||
| 7 | * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, | 6 | * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, |
| 8 | * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, | 7 | * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, |
| 9 | * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. | 8 | * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. |
| @@ -1,9 +1,8 @@ | |||
| 1 | /* | 1 | /* |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. |
| 3 | * openUBMC is licensed under Mulan PSL v2. | 3 | * openUBMC is licensed under Mulan PSL v2. |
| 4 | * You can use this software according to the terms and conditions of the Mulan PSL v2. | 4 | * You can use this software according to the terms and conditions of the Mulan PSL v2. |
| 5 | - * You may obtain a copy of Mulan PSL v2 at: | 5 | + * You may obtain a copy of Mulan PSL v2 at: http://license.coscl.org.cn/MulanPSL2 |
| 6 | - * http://license.coscl.org.cn/MulanPSL2 | ||
| 7 | * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, | 6 | * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, |
| 8 | * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, | 7 | * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, |
| 9 | * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. | 8 | * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. |
| @@ -13,127 +12,16 @@ | |||
| 13 | #ifndef HW_NVME_PCIE4_H | 12 | #ifndef HW_NVME_PCIE4_H |
| 14 | #define HW_NVME_PCIE4_H | 13 | #define HW_NVME_PCIE4_H |
| 15 | 14 | ||
| 16 | -#include <mc/app/object.h> | 15 | +#include "../../common/nvme_pcie4_driver.h" |
| 17 | -#include <mc/engine.h> | 16 | +#include "../../common/nvme_pcie4_object_macros.h" |
| 18 | -#include <mc/timer.h> | ||
| 19 | -#include <mctp/mctp.h> | ||
| 20 | -#include <mutex> | ||
| 21 | -#include <nvme/nvme_mi_over_mctp_huawei.h> | ||
| 22 | -#include <nvme/nvme_mi_vpd.h> | ||
| 23 | -#include <nvme/sff_vpd.h> | ||
| 24 | -#include <nvme/vpd_protocol.h> | ||
| 25 | - | ||
| 26 | -#include "../interface/cooling.h" | ||
| 27 | -#include "../interface/nvme.h" | ||
| 28 | -#include "../interface/nvme/basic_management.h" | ||
| 29 | -#include "../interface/nvme/log_collection.h" | ||
| 30 | -#include "../interface/nvme/management.h" | ||
| 31 | -#include "../interface/nvme/multi_record.h" | ||
| 32 | -#include "../interface/nvme/nvme_mi.h" | ||
| 33 | -#include "../interface/nvme/oem.h" | ||
| 34 | -#include "../interface/nvme/product_info.h" | ||
| 35 | -#include "../interface/nvme/smart.h" | ||
| 36 | -#include "../interface/nvme/status.h" | ||
| 37 | -#include "../interface/nvme/vendor_specific_smart.h" | ||
| 38 | -#include "../interface/pcie_device.h" | ||
| 39 | -#include "../interface/pcie_device/oem.h" | ||
| 40 | -#include "../interface/pcie_device/pcie_function.h" | ||
| 41 | -#include "../interface/pcie_device/status.h" | ||
| 42 | -#include "../interface/upgrade.h" | ||
| 43 | 17 | ||
| 44 | namespace dev { | 18 | namespace dev { |
| 45 | 19 | ||
| 46 | -using vpd_protocol_ptr = std::shared_ptr<vpd_protocol>; | 20 | +class hw_nvme_pcie4 : public nvme_pcie4_driver<hw_nvme_pcie4> { |
| 47 | -using nvme_mi_over_mctp_ptr = std::shared_ptr<nvme_mi_over_mctp_huawei>; | ||
| 48 | -using mctp_ptr = std::shared_ptr<mctp>; | ||
| 49 | - | ||
| 50 | -class hw_nvme_pcie4 : public mc::app::object<hw_nvme_pcie4> { | ||
| 51 | public: | 21 | public: |
| 52 | - MC_OBJECT( | 22 | + static constexpr const char* vendor_key = "huawei"; |
| 53 | - hw_nvme_pcie4, "PCIeNVMe", "/bmc/dev/Systems/1/PCIeNVMe/${object_name}", | ||
| 54 | - (PCIeDevice)(PCIeDevice_PCIeFunction)(PCIeDevice_Status)(PCIeDevice_Oem)(NVMe_Upgrade)(NVMe)(NVMe_Management)(NVMe_ProductInfo)(NVMe_MultiRecord)(NVMe_Status)(NVMe_BasicManagement)(NVMe_NVMeMI)(NVMe_LogCollection)(NVMe_Smart)(NVMe_VendorSpecificSmart)(NVMe_Oem)(Cooling)) | ||
| 55 | 23 | ||
| 56 | - hw_nvme_pcie4(); | 24 | + NVME_PCIE4_OBJECT(hw_nvme_pcie4) |
| 57 | - ~hw_nvme_pcie4(); | ||
| 58 | - | ||
| 59 | - bool start(); | ||
| 60 | - bool stop(); | ||
| 61 | - bool init(mc::mutable_dict& csr_object, const mc::dict& connector); | ||
| 62 | - void replace_dynamic_property(mc::mutable_dict& object, const mc::dict& connector); | ||
| 63 | - | ||
| 64 | - // 供上层(含测试)调整 VPD 动态任务周期(Status/BasicManagement,默认 10 秒) | ||
| 65 | - void set_vpd_dynamic_interval(mc::milliseconds interval) | ||
| 66 | - { | ||
| 67 | - m_vpd_dynamic_interval = interval; | ||
| 68 | - } | ||
| 69 | - | ||
| 70 | - // 接口成员变量 | ||
| 71 | - uint8_t m_system_id; | ||
| 72 | - PCIeDevice m_pcie_device; | ||
| 73 | - PCIeDevice_PCIeFunction m_pcie_device_pcie_function; | ||
| 74 | - PCIeDevice_Status m_pcie_device_status; | ||
| 75 | - PCIeDevice_Oem m_pcie_device_oem; | ||
| 76 | - NVMe_Upgrade m_upgrade; | ||
| 77 | - NVMe m_nvme; | ||
| 78 | - NVMe_Management m_nvme_management; | ||
| 79 | - NVMe_ProductInfo m_nvme_product_info; | ||
| 80 | - NVMe_MultiRecord m_nvme_multi_record; | ||
| 81 | - NVMe_Status m_nvme_status; | ||
| 82 | - Cooling m_cooling; | ||
| 83 | - NVMe_BasicManagement m_nvme_basic_management; | ||
| 84 | - NVMe_NVMeMI m_nvme_nvme_mi; | ||
| 85 | - NVMe_LogCollection m_nvme_log_collection; | ||
| 86 | - NVMe_Smart m_nvme_smart; | ||
| 87 | - NVMe_VendorSpecificSmart m_nvme_vendor_specific_smart; | ||
| 88 | - NVMe_Oem m_nvme_oem; | ||
| 89 | - | ||
| 90 | -private: | ||
| 91 | - // VPD 协议类型(华为只支持 NVMe-MI 和 SFF) | ||
| 92 | - // NVME_MI = 0, SFF = 1 | ||
| 93 | - enum class VpdProtocolType { | ||
| 94 | - NVME_MI = 0, // NVMe-MI 协议 | ||
| 95 | - SFF = 1 // SSD Form Factor 协议 | ||
| 96 | - }; | ||
| 97 | - | ||
| 98 | - VpdProtocolType detect_vpd_protocol(); | ||
| 99 | - bool init_vpd_protocol(); | ||
| 100 | - bool start_mctp_protocol(); | ||
| 101 | - bool start_mctp_over_pcie(); | ||
| 102 | - bool start_mctp_over_smbus(); | ||
| 103 | - void restart_mctp_protocol(); | ||
| 104 | - | ||
| 105 | - void start_vpd_update_tasks(); | ||
| 106 | - void stop_vpd_update_tasks(); | ||
| 107 | - void start_mctp_update_tasks(); | ||
| 108 | - void stop_mctp_update_tasks(); | ||
| 109 | - void start_vpd_dynamic_tasks(); | ||
| 110 | - void restart_vpd_dynamic_tasks(); | ||
| 111 | - void handle_os_off(); | ||
| 112 | - void handle_os_reset(); | ||
| 113 | - void update_nvme_properties_from_basic_mgmt(); | ||
| 114 | - void update_nvme_properties_from_smart(); | ||
| 115 | - void update_negotiated_link_width(); | ||
| 116 | - | ||
| 117 | - vpd_protocol_ptr m_vpd_obj; | ||
| 118 | - VpdProtocolType m_protocol_type = VpdProtocolType::SFF; | ||
| 119 | - nvme_mi_over_mctp_ptr m_nvme_mi_over_mctp_obj; | ||
| 120 | - mc::shared_ptr<mctp> m_mctp_object; | ||
| 121 | - uint32_t m_ctrl_id; | ||
| 122 | - uint16_t m_last_phy_addr = 0; | ||
| 123 | - | ||
| 124 | - // VPD 更新间隔 | ||
| 125 | - mc::milliseconds m_vpd_cooling_interval = mc::milliseconds(3000); // Cooling: 3 秒 | ||
| 126 | - mc::milliseconds m_vpd_dynamic_interval = mc::milliseconds(10000); // Status, BasicManagement: 10 秒 | ||
| 127 | - | ||
| 128 | - mc::milliseconds m_vpd_static_interval = mc::milliseconds(120000); // Static: 2 分钟 | ||
| 129 | - mc::shared_ptr<mc::timer> m_static_update_timer; | ||
| 130 | - | ||
| 131 | - // MCTP 更新间隔 | ||
| 132 | - mc::milliseconds m_mctp_smart_interval = mc::milliseconds(120000); // Smart: 2 分钟 | ||
| 133 | - mc::milliseconds m_mctp_vendor_specific_smart_interval = mc::milliseconds(120000); // Vendor Specific Smart: 2 分钟 | ||
| 134 | - | ||
| 135 | - // 防止 OS 重启和 BDF 变化同时触发 start_mctp_protocol 导致并发 | ||
| 136 | - std::mutex m_mctp_restart_mutex; | ||
| 137 | }; | 25 | }; |
| 138 | 26 | ||
| 139 | } // namespace dev | 27 | } // namespace dev |
| @@ -5,7 +5,7 @@ message('开始构建 hw_nvme_pcie4 驱动库') | |||
| 5 | hw_nvme_pcie4_sources = files( | 5 | hw_nvme_pcie4_sources = files( |
| 6 | 'hw_nvme_pcie4.cpp', | 6 | 'hw_nvme_pcie4.cpp', |
| 7 | 'hw_nvme_pcie4_abi.cpp', | 7 | 'hw_nvme_pcie4_abi.cpp', |
| 8 | -) + interface_sources | 8 | +) |
| 9 | 9 | ||
| 10 | include_dirs += include_directories('../../../chip') | 10 | include_dirs += include_directories('../../../chip') |
| 11 | include_dirs += include_directories('../../../internal') | 11 | include_dirs += include_directories('../../../internal') |
| @@ -13,7 +13,7 @@ include_dirs += include_directories('../../../internal') | |||
| 13 | libhw_nvme_pcie4_static = static_library( | 13 | libhw_nvme_pcie4_static = static_library( |
| 14 | 'hw_nvme_pcie4', | 14 | 'hw_nvme_pcie4', |
| 15 | hw_nvme_pcie4_sources, | 15 | hw_nvme_pcie4_sources, |
| 16 | - include_directories: include_dirs + huawei_interface_inc, | 16 | + include_directories: include_dirs + pcie_nvme_common_inc, |
| 17 | dependencies: [dev_deps, libnvme_dep, libmctp_dep], | 17 | dependencies: [dev_deps, libnvme_dep, libmctp_dep], |
| 18 | install: false, | 18 | install: false, |
| 19 | override_options: ['unity_size=15'], | 19 | override_options: ['unity_size=15'], |
| @@ -21,19 +21,19 @@ libhw_nvme_pcie4_static = static_library( | |||
| 21 | 21 | ||
| 22 | libhw_nvme_pcie4 = shared_library( | 22 | libhw_nvme_pcie4 = shared_library( |
| 23 | 'hw_nvme_pcie4', | 23 | 'hw_nvme_pcie4', |
| 24 | - include_directories: include_dirs + huawei_interface_inc, | 24 | + include_directories: include_dirs + pcie_nvme_common_inc, |
| 25 | name_prefix: 'lib', | 25 | name_prefix: 'lib', |
| 26 | name_suffix: 'so', | 26 | name_suffix: 'so', |
| 27 | install: true, | 27 | install: true, |
| 28 | install_dir: drivers_install_dir, | 28 | install_dir: drivers_install_dir, |
| 29 | - link_whole: [libhw_nvme_pcie4_static], | 29 | + link_whole: [libhw_nvme_pcie4_static, libpcie_nvme_common_static], |
| 30 | dependencies: [dev_deps, libnvme_dep, libmctp_dep], | 30 | dependencies: [dev_deps, libnvme_dep, libmctp_dep], |
| 31 | ) | 31 | ) |
| 32 | 32 | ||
| 33 | if build_tests | 33 | if build_tests |
| 34 | hw_nvme_pcie4_dep = declare_dependency( | 34 | hw_nvme_pcie4_dep = declare_dependency( |
| 35 | - include_directories: include_dirs + huawei_interface_inc, | 35 | + include_directories: include_dirs + pcie_nvme_common_inc, |
| 36 | - link_with: libhw_nvme_pcie4_static, | 36 | + link_with: [libhw_nvme_pcie4_static, libpcie_nvme_common_static], |
| 37 | dependencies: [ | 37 | dependencies: [ |
| 38 | libmcpp_deps, | 38 | libmcpp_deps, |
| 39 | libnvme_dep, | 39 | libnvme_dep, |
| @@ -1,25 +0,0 @@ | |||
| 1 | -# interface 目录的 meson.build 文件 | ||
| 2 | - | ||
| 3 | -message('开始构建 huawei nvme interface') | ||
| 4 | - | ||
| 5 | -interface_sources = files( | ||
| 6 | - 'pcie_device.cpp', | ||
| 7 | - 'pcie_device/pcie_function.cpp', | ||
| 8 | - 'pcie_device/oem.cpp', | ||
| 9 | - 'pcie_device/status.cpp', | ||
| 10 | - 'upgrade.cpp', | ||
| 11 | - 'nvme.cpp', | ||
| 12 | - 'nvme/management.cpp', | ||
| 13 | - 'nvme/product_info.cpp', | ||
| 14 | - 'nvme/multi_record.cpp', | ||
| 15 | - 'nvme/status.cpp', | ||
| 16 | - 'cooling.cpp', | ||
| 17 | - 'nvme/basic_management.cpp', | ||
| 18 | - 'nvme/nvme_mi.cpp', | ||
| 19 | - 'nvme/log_collection.cpp', | ||
| 20 | - 'nvme/smart.cpp', | ||
| 21 | - 'nvme/vendor_specific_smart.cpp', | ||
| 22 | - 'nvme/oem.cpp', | ||
| 23 | -) | ||
| 24 | - | ||
| 25 | -# interface_sources 将被父目录的 meson.build 使用 | ||
| @@ -1,5 +1,3 @@ | |||
| 1 | # huawei 目录的 meson.build 文件 | 1 | # huawei 目录的 meson.build 文件 |
| 2 | 2 | ||
| 3 | -huawei_interface_inc = include_directories('.') | ||
| 4 | -subdir('interface') | ||
| 5 | subdir('hw_nvme_pcie4') | 3 | subdir('hw_nvme_pcie4') |
| @@ -13,7 +13,8 @@ if build_tests | |||
| 13 | include_dirs, | 13 | include_dirs, |
| 14 | include_directories('.'), | 14 | include_directories('.'), |
| 15 | include_directories('../../../../../drivers/pcie_nvme/huawei'), | 15 | include_directories('../../../../../drivers/pcie_nvme/huawei'), |
| 16 | - include_directories('../../../../../drivers/pcie_nvme/huawei/interface'), | 16 | + include_directories('../../../../../drivers/pcie_nvme/common'), |
| 17 | + include_directories('../../../../../drivers/pcie_nvme/common/interface'), | ||
| 17 | include_directories('../../../../../libraries'), | 18 | include_directories('../../../../../libraries'), |
| 18 | include_directories('../../../../../drivers'), | 19 | include_directories('../../../../../drivers'), |
| 19 | include_directories('../../../../../drivers/bus/i2c'), | 20 | include_directories('../../../../../drivers/bus/i2c'), |
| @@ -31,7 +31,8 @@ test_nvme_interface = executable( | |||
| 31 | include_directories('.'), | 31 | include_directories('.'), |
| 32 | include_directories('../..'), | 32 | include_directories('../..'), |
| 33 | include_directories('../../../../../drivers/pcie_nvme/huawei'), | 33 | include_directories('../../../../../drivers/pcie_nvme/huawei'), |
| 34 | - include_directories('../../../../../drivers/pcie_nvme/huawei/interface'), | 34 | + include_directories('../../../../../drivers/pcie_nvme/common'), |
H 【测试未同步】数据驱动差异化缺少 UT 覆盖,现有 interface UT 实际校验的是“通用厂商”分支 本 PR 把 huawei 的 interface 测试目标从 新增的差异化行为全部由 同时,#1487 的 建议:接口 UT 的 fixture 中补 ![]() ![]() | |||
| 35 | + include_directories('../../../../../drivers/pcie_nvme/common/interface'), | ||
| 35 | include_directories('../../../../../drivers/internal'), | 36 | include_directories('../../../../../drivers/internal'), |
| 36 | include_directories('../../../../../include'), | 37 | include_directories('../../../../../include'), |
| 37 | include_directories('../../../../../gen'), | 38 | include_directories('../../../../../gen'), |
| @@ -52,6 +52,8 @@ protected: | |||
| 52 | void SetUp() override | 52 | void SetUp() override |
| 53 | { | 53 | { |
| 54 | m_multi_record = make_iface<dev::NVMe_MultiRecord>(); | 54 | m_multi_record = make_iface<dev::NVMe_MultiRecord>(); |
| 55 | + // 该用例集验证华为语义(firmware_offset/capacity 兜底查表) | ||
| 56 | + m_multi_record->set_vendor_key("huawei"); | ||
| 55 | } | 57 | } |
| 56 | void TearDown() override | 58 | void TearDown() override |
| 57 | { | 59 | { |
| @@ -53,6 +53,8 @@ protected: | |||
| 53 | void SetUp() override | 53 | void SetUp() override |
| 54 | { | 54 | { |
| 55 | m_product_info = make_iface<dev::NVMe_ProductInfo>(); | 55 | m_product_info = make_iface<dev::NVMe_ProductInfo>(); |
| 56 | + // 该用例集验证华为语义(产品级 manufacturer_id/firmware_offset 查表) | ||
| 57 | + m_product_info->set_vendor_key("huawei"); | ||
| 56 | } | 58 | } |
| 57 | void TearDown() override | 59 | void TearDown() override |
| 58 | { | 60 | { |
| @@ -60,6 +60,8 @@ protected: | |||
| 60 | void SetUp() override | 60 | void SetUp() override |
| 61 | { | 61 | { |
| 62 | m_nvme_smart = make_iface<dev::NVMe_Smart>(); | 62 | m_nvme_smart = make_iface<dev::NVMe_Smart>(); |
| 63 | + // 该用例集验证华为语义:vendor_smart_log_id=0xE5、tlc_from_avail_spare=true | ||
| 64 | + m_nvme_smart->set_vendor_key("huawei"); | ||
| 63 | 65 | ||
| 64 | // 创建真实的 mctp 和 nvme_mi_over_mctp_huawei,通过 MCTP 请求处理器来模拟响应 | 66 | // 创建真实的 mctp 和 nvme_mi_over_mctp_huawei,通过 MCTP 请求处理器来模拟响应 |
| 65 | m_mctp = mc::make_shared<dev::mctp>(nullptr, 0, dev::MCTP_MESSAGE_TYPE_NVME, ""); | 67 | m_mctp = mc::make_shared<dev::mctp>(nullptr, 0, dev::MCTP_MESSAGE_TYPE_NVME, ""); |
| @@ -106,6 +108,30 @@ TEST_F(NVMeSmartTest, UpdateSmartByMctp_RoundsPowerOnHoursOnce) | |||
| 106 | m_nvme_smart->stop_mctp_update_task(); | 108 | m_nvme_smart->stop_mctp_update_task(); |
| 107 | } | 109 | } |
| 108 | 110 | ||
| 111 | +TEST_F(NVMeSmartTest, UpdateSmartByMctp_VendorLogFallbackFollowsBehaviorTable) | ||
| 112 | +{ | ||
| 113 | + // 目标:标准 SMART log 失败后是否重试厂商日志由行为表 vendor_smart_log_id 决定。 | ||
| 114 | + // huawei=0xE5,会再发一次厂商日志请求;未配置厂商键时默认 0,只尝试标准日志。 | ||
| 115 | + int request_count = 0; | ||
| 116 | + dev::set_mctp_request_handler([&request_count](const mc::dict&, const std::vector<uint8_t>&, std::string&) { | ||
| 117 | + ++request_count; | ||
| 118 | + return false; | ||
| 119 | + }); | ||
| 120 | + | ||
| 121 | + m_nvme_smart->start_mctp_update_task(m_nvme_mi_obj, mc::milliseconds(10000)); | ||
| 122 | + EXPECT_FALSE(m_nvme_smart->update_smart_by_mctp()); | ||
| 123 | + EXPECT_EQ(request_count, 2); // 标准日志 + huawei 厂商日志 | ||
| 124 | + | ||
| 125 | + auto generic_smart = make_iface<dev::NVMe_Smart>(); | ||
| 126 | + generic_smart->start_mctp_update_task(m_nvme_mi_obj, mc::milliseconds(10000)); | ||
| 127 | + request_count = 0; | ||
| 128 | + EXPECT_FALSE(generic_smart->update_smart_by_mctp()); | ||
| 129 | + EXPECT_EQ(request_count, 1); // 仅标准日志 | ||
| 130 | + | ||
| 131 | + generic_smart->stop_mctp_update_task(); | ||
| 132 | + m_nvme_smart->stop_mctp_update_task(); | ||
| 133 | +} | ||
| 134 | + | ||
| 109 | TEST_F(NVMeSmartTest, UpdateSmartByMctp_WithoutMctpObj) | 135 | TEST_F(NVMeSmartTest, UpdateSmartByMctp_WithoutMctpObj) |
| 110 | { | 136 | { |
| 111 | // 目标:验证在没有设置 MCTP 对象的情况下调用 update_smart_by_mctp 返回 false | 137 | // 目标:验证在没有设置 MCTP 对象的情况下调用 update_smart_by_mctp 返回 false |
| @@ -79,6 +79,8 @@ protected: | |||
| 79 | // 注册对象到 dbus 服务,避免析构时尝试注销未注册的路径 | 79 | // 注册对象到 dbus 服务,避免析构时尝试注销未注册的路径 |
| 80 | m_test_service->register_object(m_test_object); | 80 | m_test_service->register_object(m_test_object); |
| 81 | m_status = &m_test_object->m_status; | 81 | m_status = &m_test_object->m_status; |
| 82 | + // 该用例集验证华为语义:忽略 bit3 Port0 Link Active | ||
| 83 | + m_status->set_vendor_key("huawei"); | ||
| 82 | } | 84 | } |
| 83 | 85 | ||
| 84 | void TearDown() override | 86 | void TearDown() override |
| @@ -422,36 +424,37 @@ TEST_F(NVMeStatusTest, Debounce_PredictiveFailure_Requires5ConsecutiveFaults) | |||
| 422 | 424 | ||
| 423 | TEST_F(NVMeStatusTest, StatusFlags_DifferentCombinations) | 425 | TEST_F(NVMeStatusTest, StatusFlags_DifferentCombinations) |
| 424 | { | 426 | { |
| 425 | - // 目标:验证不同 status_flags 组合对 ssd_fault 计算的影响 | 427 | + // 目标:验证华为语义(ignore_port_link_active=true)下不同 status_flags 的故障判定 |
| 426 | - // 表达式: ((f & 0x60) == 0x20) ? 0 : 1 | 428 | + // 表达式: ((f & 0x60) == 0x20) ? 正常 : 故障;bit3 Port0 Link Active 被忽略 |
| 427 | - // 0x60 = 01100000 (bit5=Drive Functional, bit6=Drive Not Ready) | ||
| 428 | auto mock_vpd = std::make_shared<mock_vpd_protocol>(); | 429 | auto mock_vpd = std::make_shared<mock_vpd_protocol>(); |
| 429 | m_status->start_vpd_update_task(mock_vpd, mc::milliseconds(10)); | 430 | m_status->start_vpd_update_task(mock_vpd, mc::milliseconds(10)); |
| 430 | 431 | ||
| 431 | // 测试各种 status_flags 组合 | 432 | // 测试各种 status_flags 组合 |
| 432 | struct TestCase { | 433 | struct TestCase { |
| 433 | uint8_t flags; | 434 | uint8_t flags; |
| 434 | - int expected_fault; // 预期的 ssd_fault 值 | 435 | + bool expected_fault; // 预期的故障判定 |
| 435 | const char* desc; | 436 | const char* desc; |
| 436 | }; | 437 | }; |
| 437 | 438 | ||
| 438 | - std::vector<TestCase> test_cases = { | 439 | + const std::vector<TestCase> test_cases = { |
| 439 | - {0x00, 1, "所有位为0,故障"}, // (0x00 & 0x60) = 0x00 != 0x20 -> fault=1 | 440 | + {0x00, true, "所有位为0,故障"}, // (0x00 & 0x60) = 0x00 != 0x20 -> fault |
| 440 | - {0x20, 0, "正常状态"}, // (0x20 & 0x60) = 0x20 == 0x20 -> fault=0 | 441 | + {0x20, false, "Drive Functional=1,正常"}, // (0x20 & 0x60) = 0x20 -> normal |
| 441 | - {0x40, 1, "Drive Not Ready=1,故障"}, // (0x40 & 0x60) = 0x40 != 0x20 -> fault=1 | 442 | + {0x40, true, "Drive Not Ready=1,故障"}, // (0x40 & 0x60) = 0x40 != 0x20 -> fault |
| 442 | - {0x60, 1, "两个位都为1,故障"}, // (0x60 & 0x60) = 0x60 != 0x20 -> fault=1 | 443 | + {0x60, true, "两个位都为1,故障"}, // (0x60 & 0x60) = 0x60 != 0x20 -> fault |
| 443 | - {0x10, 1, "其他位设置,故障"}, // (0x10 & 0x60) = 0x00 != 0x20 -> fault=1 | 444 | + {0x10, true, "其他位设置,故障"}, // (0x10 & 0x60) = 0x00 != 0x20 -> fault |
| 444 | - {0x30, 1, "混合状态,故障"}, // (0x30 & 0x60) = 0x20 -> fault=0 (注意:0x30 & 0x60 = 0x20) | 445 | + {0x30, false, "bit3=1 被忽略,正常"}, // (0x30 & 0x60) = 0x20 -> normal |
| 445 | - {0x28, 0, "Port0 Link Active=1,正常"}, // (0x28 & 0x60) = 0x20 -> fault=0 | 446 | + {0x28, false, "Port0 Link Active=1,正常"}, // (0x28 & 0x60) = 0x20 -> normal |
| 446 | }; | 447 | }; |
| 447 | 448 | ||
| 448 | for (const auto& tc : test_cases) { | 449 | for (const auto& tc : test_cases) { |
| 450 | + // 直接断言可观测的判定结果,避免依赖 6 分钟告警门控 | ||
| 451 | + EXPECT_EQ(is_nvme_status_fault(tc.flags, true), tc.expected_fault) << tc.desc; | ||
| 452 | + | ||
| 449 | mock_vpd->set_status_flags(tc.flags); | 453 | mock_vpd->set_status_flags(tc.flags); |
| 450 | mock_vpd->set_smart_warnings(0x1F); // 确保预测故障不会干扰 | 454 | mock_vpd->set_smart_warnings(0x1F); // 确保预测故障不会干扰 |
| 451 | 455 | ||
| 452 | - // 调用一次以触发 debounce 计算 | 456 | + // 调用一次,确认接口路径不崩溃 |
| 453 | - bool result = m_status->update_status_by_vpd(); | 457 | + EXPECT_TRUE(m_status->update_status_by_vpd()); |
| 454 | - EXPECT_TRUE(result); | ||
| 455 | } | 458 | } |
| 456 | 459 | ||
| 457 | m_status->stop_vpd_update_task(); | 460 | m_status->stop_vpd_update_task(); |
| @@ -461,6 +464,29 @@ TEST_F(NVMeStatusTest, StatusFlags_DifferentCombinations) | |||
| 461 | } | 464 | } |
| 462 | } | 465 | } |
| 463 | 466 | ||
| 467 | +TEST_F(NVMeStatusTest, StatusFlags_GenericVendorRequiresLinkActive) | ||
| 468 | +{ | ||
| 469 | + // 目标:验证未配置 ignore_port_link_active 的厂商(默认)需同时满足 | ||
| 470 | + // bit3 Port0 Link Active=1、bit5 Drive Functional=1、bit6 Drive Not Ready=0 | ||
| 471 | + struct TestCase { | ||
| 472 | + uint8_t flags; | ||
| 473 | + bool expected_fault; | ||
| 474 | + const char* desc; | ||
| 475 | + }; | ||
| 476 | + | ||
| 477 | + const std::vector<TestCase> test_cases = { | ||
| 478 | + {0x20, true, "Drive Functional=1 但 Port0 Link Active=0,故障"}, | ||
| 479 | + {0x28, false, "Drive Functional=1 且 Port0 Link Active=1,正常"}, | ||
| 480 | + {0x30, true, "仅 bit3/bit4,故障"}, | ||
| 481 | + {0x68, true, "Drive Not Ready=1,故障"}, | ||
| 482 | + {0x00, true, "所有位为0,故障"}, | ||
| 483 | + }; | ||
| 484 | + | ||
| 485 | + for (const auto& tc : test_cases) { | ||
| 486 | + EXPECT_EQ(is_nvme_status_fault(tc.flags, false), tc.expected_fault) << tc.desc; | ||
| 487 | + } | ||
| 488 | +} | ||
| 489 | + | ||
| 464 | TEST_F(NVMeStatusTest, SmartWarnings_DifferentCombinations) | 490 | TEST_F(NVMeStatusTest, SmartWarnings_DifferentCombinations) |
| 465 | { | 491 | { |
| 466 | // 目标:验证不同 smart_warnings 组合对 ssd_pre_fault 计算的影响 | 492 | // 目标:验证不同 smart_warnings 组合对 ssd_pre_fault 计算的影响 |
| @@ -542,11 +568,13 @@ TEST_F(NVMeStatusTest, MultipleVpdObjects) | |||
| 542 | auto test_obj1 = mc::make_shared<test_nvme_status_object>(); | 568 | auto test_obj1 = mc::make_shared<test_nvme_status_object>(); |
| 543 | test_obj1->set_object_path("/bmc/test/NVMeStatus1"); | 569 | test_obj1->set_object_path("/bmc/test/NVMeStatus1"); |
| 544 | test_obj1->set_object_name("TestNVMeStatus1"); | 570 | test_obj1->set_object_name("TestNVMeStatus1"); |
| 571 | + test_obj1->m_status.set_vendor_key("huawei"); | ||
| 545 | m_test_service->register_object(test_obj1); | 572 | m_test_service->register_object(test_obj1); |
| 546 | 573 | ||
| 547 | auto test_obj2 = mc::make_shared<test_nvme_status_object>(); | 574 | auto test_obj2 = mc::make_shared<test_nvme_status_object>(); |
| 548 | test_obj2->set_object_path("/bmc/test/NVMeStatus2"); | 575 | test_obj2->set_object_path("/bmc/test/NVMeStatus2"); |
| 549 | test_obj2->set_object_name("TestNVMeStatus2"); | 576 | test_obj2->set_object_name("TestNVMeStatus2"); |
| 577 | + test_obj2->m_status.set_vendor_key("huawei"); | ||
| 550 | m_test_service->register_object(test_obj2); | 578 | m_test_service->register_object(test_obj2); |
| 551 | 579 | ||
| 552 | test_obj1->m_status.start_vpd_update_task(mock_vpd1, mc::milliseconds(10)); | 580 | test_obj1->m_status.start_vpd_update_task(mock_vpd1, mc::milliseconds(10)); |


🟡 Medium Priority
变更点:multi_record.cpp:36-39 在能读到 product_name 时,用
behavior_int({m_vendor_key, product_name}, behavior_key::firmware_offset, SSD_FIRMWARE_OFFSET)查偏移,否则才用默认值 SSD_FIRMWARE_OFFSET。证据链:行为表 nvme_pcie4_behavior_table.cpp 中 firmware_offset 同时存在于两个层级——厂商级(
{"dera"/"kioxia"/"ymtc", {{firmware_offset, 97}}},见该文件 47-58 行)和产品级("samsung/PM9A3"→33、"dera/D6436"→39、"solidigm/D7-..."→97等,见 60-82 行)。而本仓其它调用点的惯例是:要厂商级就只传厂商字段(smart.cpp:63behavior_int({m_vendor_key}, ...)、nvme_pcie4_driver.h:533behavior_bool({Derived::vendor_key}, ...)),要型号级就传{vendor, {}, model}(nvme_pcie4_driver.h:331)。本处传的是{m_vendor_key, product_name},即 product 级,没有“product 未命中原厂再回落到 vendor 级”的二次查询。失效模式:对只配置了厂商级条目的厂商(dera/kioxia/ymtc,表中为 97),只要 VPD 能读出 product_name,厂商级条目就查不到,落到默认 SSD_FIRMWARE_OFFSET;而各厂商旧实现中 dera 的默认偏移是 97(dera/interface/nvme/multi_record.cpp:37),SSD_FIRMWARE_OFFSET 按 samsung 实现注释为 39。结果是用 39 字节偏移去解析需要 97 偏移的固件版本串,Revision 属性读到错误字节(is_valid_vpd_string 可能通过,从而把垃圾字符串写入 Revision,属静默错误而非报错)。触发条件:由 Pcie4 通用驱动加载 dera/kioxia/ymtc 卡且 product_name 可读。
不确定性:behavior_lookup 是否内部做了 model→product→vendor 的级联回落,我无法读取该实现(nvme_pcie4_behavior_table.h 不在可读范围),若确已级联则本条不成立,故置信度取 0.45。
修复方向:在 product 级未命中时再以
{m_vendor_key}查一次,命中前不要直接落到默认值。