From ee45da93ecf4ecd10edd14a5cec32baa237da949 Mon Sep 17 00:00:00 2001 From: wuchao Date: Wed, 17 Jun 2026 06:31:37 +0000 Subject: [PATCH] Add associate code for the pca9548 idle state Signed-off-by: wuchao --- .../configs/leh800bcls/platform_manager.json | 64 ++++++++++++++++--- .../platform_manager/PlatformExplorer.cpp | 59 +++-------------- .../platform_manager_config.thrift | 11 +++- 3 files changed, 76 insertions(+), 58 deletions(-) diff --git a/fboss/platform/configs/leh800bcls/platform_manager.json b/fboss/platform/configs/leh800bcls/platform_manager.json index ec85faf509edb..a34fe502db4b9 100644 --- a/fboss/platform/configs/leh800bcls/platform_manager.json +++ b/fboss/platform/configs/leh800bcls/platform_manager.json @@ -577,7 +577,13 @@ "address": "0x70", "kernelDeviceName": "pca9548", "pmUnitScopedName": "SMB_L_MUX_1", - "numOutgoingChannels": 8 + "numOutgoingChannels": 8, + "postCreateSysfsValues": [ + { + "attr": "idle_state", + "value": "-2" + } + ] }, { "busName": "SMB_L_MUX_1@0", @@ -650,7 +656,13 @@ "address": "0x70", "kernelDeviceName": "pca9548", "pmUnitScopedName": "SMB_L_MUX_2", - "numOutgoingChannels": 8 + "numOutgoingChannels": 8, + "postCreateSysfsValues": [ + { + "attr": "idle_state", + "value": "-2" + } + ] }, { "busName": "SMB_L_MUX_2@2", @@ -693,7 +705,13 @@ "address": "0x72", "kernelDeviceName": "pca9548", "pmUnitScopedName": "SMB_L_MUX_3", - "numOutgoingChannels": 8 + "numOutgoingChannels": 8, + "postCreateSysfsValues": [ + { + "attr": "idle_state", + "value": "-2" + } + ] }, { "busName": "SMB_L_MUX_3@0", @@ -736,7 +754,13 @@ "address": "0x70", "kernelDeviceName": "pca9548", "pmUnitScopedName": "SMB_L_MUX_4", - "numOutgoingChannels": 8 + "numOutgoingChannels": 8, + "postCreateSysfsValues": [ + { + "attr": "idle_state", + "value": "-2" + } + ] }, { "busName": "SMB_L_MUX_4@0", @@ -886,7 +910,13 @@ "address": "0x70", "kernelDeviceName": "pca9548", "pmUnitScopedName": "SMB_R_MUX_1", - "numOutgoingChannels": 8 + "numOutgoingChannels": 8, + "postCreateSysfsValues": [ + { + "attr": "idle_state", + "value": "-2" + } + ] }, { "busName": "SMB_R_MUX_1@0", @@ -959,7 +989,13 @@ "address": "0x70", "kernelDeviceName": "pca9548", "pmUnitScopedName": "SMB_R_MUX_2", - "numOutgoingChannels": 8 + "numOutgoingChannels": 8, + "postCreateSysfsValues": [ + { + "attr": "idle_state", + "value": "-2" + } + ] }, { "busName": "SMB_R_MUX_2@2", @@ -1002,7 +1038,13 @@ "address": "0x72", "kernelDeviceName": "pca9548", "pmUnitScopedName": "SMB_R_MUX_3", - "numOutgoingChannels": 8 + "numOutgoingChannels": 8, + "postCreateSysfsValues": [ + { + "attr": "idle_state", + "value": "-2" + } + ] }, { "busName": "SMB_R_MUX_3@0", @@ -1045,7 +1087,13 @@ "address": "0x70", "kernelDeviceName": "pca9548", "pmUnitScopedName": "SMB_R_MUX_4", - "numOutgoingChannels": 8 + "numOutgoingChannels": 8, + "postCreateSysfsValues": [ + { + "attr": "idle_state", + "value": "-2" + } + ] }, { "busName": "SMB_R_MUX_4@0", diff --git a/fboss/platform/platform_manager/PlatformExplorer.cpp b/fboss/platform/platform_manager/PlatformExplorer.cpp index 72a7de39b0943..a6412d2287d44 100644 --- a/fboss/platform/platform_manager/PlatformExplorer.cpp +++ b/fboss/platform/platform_manager/PlatformExplorer.cpp @@ -564,56 +564,17 @@ void PlatformExplorer::exploreI2cDevices( errMsg); } } - if (i2cDeviceConfig.pca9548Mode().has_value()) { - int32_t modeValue = *i2cDeviceConfig.pca9548Mode(); - - auto i2cDevicePath = i2cExplorer_.getDeviceI2cPath(busNum, devAddr); - XLOG(INFO) << "Setting idle-state for PCA9548 to " << modeValue - << " at " << i2cDevicePath; - - try { - if (modeValue < -2) { - throw std::invalid_argument( - fmt::format( - "Invalid pca9548Mode value: {}. Allowed values are -2, -1, or >= 0.", - modeValue)); - } - std::string idleStatePath = i2cDevicePath + "/idle_state"; - std::ofstream ofs(idleStatePath); - if (!ofs.is_open()) { - throw std::runtime_error( - fmt::format("Failed to open {} for writing", idleStatePath)); + if (i2cDeviceConfig.postCreateSysfsValues()) { + for (const auto& sv : *i2cDeviceConfig.postCreateSysfsValues()) { + auto path = + i2cExplorer_.getDeviceI2cPath(busNum, devAddr) + "/" + *sv.attr(); + if (!platformFsUtils_->writeStringToSysfs(*sv.value(), path)) { + explorationSummary_.addError( + ExplorationErrorType::I2C_CONFIG_FAILED, + slotPath, + *i2cDeviceConfig.pmUnitScopedName(), + fmt::format("failed writing {} to {}", *sv.value(), path)); } - - ofs << modeValue; - - ofs.flush(); - - if (ofs.fail()) { - throw std::runtime_error( - fmt::format( - "Failed to write value '{}' to {}", - modeValue, - idleStatePath)); - } - ofs.close(); - XLOG(INFO) << "Successfully set PCA9548 idle-state to " << modeValue - << " via " << idleStatePath; - - } catch (const std::exception& e) { - auto errMsg = fmt::format( - "Failed to set idle-state for PCA9548 (mode: {}) {} in {}. Error: {}", - modeValue, - *i2cDeviceConfig.pmUnitScopedName(), - slotPath, - e.what()); - XLOG(ERR) << errMsg; - - explorationSummary_.addError( - ExplorationErrorType::I2C_CONFIG_FAILED, - slotPath, - *i2cDeviceConfig.pmUnitScopedName(), - errMsg); } } if (i2cDeviceConfig.cpldSysfsAttrs() && diff --git a/fboss/platform/platform_manager/platform_manager_config.thrift b/fboss/platform/platform_manager/platform_manager_config.thrift index fa95e511a2b94..b75e441abe8e0 100644 --- a/fboss/platform/platform_manager/platform_manager_config.thrift +++ b/fboss/platform/platform_manager/platform_manager_config.thrift @@ -205,6 +205,13 @@ struct FanCpldConfig { 5: bool hasLeds; } +// A value to write to a sysfs attribute (relative to the i2c device dir) +// after the device's kernel driver has bound. +struct I2cDeviceSysfsValue { + 1: string attr;// e.g. "idle_state" + 2: string value;// e.g. "-2" +} + // `I2cDeviceConfig` defines a i2c device within any PmUnit. // // `busName`: Refer to Bus Naming Convention above. @@ -243,6 +250,8 @@ struct FanCpldConfig { // `fanCpldConfig`: configuration for a generic fan CPLD device, sent to the // fbfancpld driver via ioctl after device creation // +// `postCreateSysfsValues`: A value to write to a sysfs attributes +// // For example, the three i2c devices in the below Sample PmUnit will be modeled // as follows // @@ -284,7 +293,7 @@ struct I2cDeviceConfig { 13: bool isEeprom; 14: optional i16 eepromOffset; 15: optional list cpldSysfsAttrs; - 16: optional i32 pca9548Mode; + 16: optional list postCreateSysfsValues; 17: optional FanCpldConfig fanCpldConfig; }