Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 56 additions & 8 deletions fboss/platform/configs/leh800bcls/platform_manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
59 changes: 10 additions & 49 deletions fboss/platform/platform_manager/PlatformExplorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() &&
Expand Down
11 changes: 10 additions & 1 deletion fboss/platform/platform_manager/platform_manager_config.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
//
Expand Down Expand Up @@ -284,7 +293,7 @@ struct I2cDeviceConfig {
13: bool isEeprom;
14: optional i16 eepromOffset;
15: optional list<CpldSysfsAttr> cpldSysfsAttrs;
16: optional i32 pca9548Mode;
16: optional list<I2cDeviceSysfsValue> postCreateSysfsValues;
17: optional FanCpldConfig fanCpldConfig;
}

Expand Down
Loading