Skip to content

Add PMBus status retrieval to MGS API#497

Draft
jamesmunns wants to merge 8 commits into
mainfrom
james/pmbus-please
Draft

Add PMBus status retrieval to MGS API#497
jamesmunns wants to merge 8 commits into
mainfrom
james/pmbus-please

Conversation

@jamesmunns
Copy link
Copy Markdown
Contributor

Follow-on PR to #496.

Part of oxidecomputer/hubris#2463.

This is a private type that is intended to be shared across wire types that
act as a null-padded fixed length container format.

This is intended to be used in a follow up PR for supporting
oxidecomputer/hubris#2463, but this is separated to
make reviewing this helper easier.
Cleanup NullStr a bit, add basic tests

Add command APIs
@jamesmunns jamesmunns force-pushed the james/nullstr-pt1 branch 2 times, most recently from 468144f to 604614c Compare June 1, 2026 16:59
Copy link
Copy Markdown
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this seems like a good start, I left a few suggestions.

Also, it would be nice to add support for this to faux-mgs. If you want to be fancy, it would be really cool if the non-JSON output for the faux-mgs command pretty-printed the decoded value of each register using the pmbus crate, in addition to printing the raw value of the register. That would probably make life much easier for the folks who end up using the MGS command to debug stuff. Feel free to steal from the pretty-printer I wrote for erebor and/or the humility pmbus command, as you see fit (though note that humility pmbus' pretty-printer is way more complex, as it also decodes PMBus registers that are not always just bitflags, as the status registers are)...

Comment thread gateway-messages/src/sp_to_mgs.rs Outdated
Comment thread gateway-messages/src/mgs_to_sp.rs Outdated
Comment thread wireshark/protofields.lua Outdated
Comment thread wireshark/protofields.lua Outdated
Comment thread gateway-messages/src/sp_to_mgs.rs Outdated
Comment thread gateway-messages/src/lib.rs
Comment thread gateway-messages/src/lib.rs Outdated
Comment thread gateway-messages/src/lib.rs Outdated
Comment thread gateway-messages/src/lib.rs Outdated
@hawkw hawkw added this to the 21 milestone Jun 1, 2026
@jamesmunns jamesmunns force-pushed the james/nullstr-pt1 branch from 604614c to d06ea64 Compare June 1, 2026 17:17
Base automatically changed from james/nullstr-pt1 to main June 2, 2026 13:45
Copy link
Copy Markdown
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. I had some smallish suggestions.

Comment thread faux-mgs/src/main.rs Outdated
Comment thread faux-mgs/src/main.rs Outdated
Comment on lines +2500 to +2522
lines.push(format!("Rail '{name}':"));
lines.push(format!("WORD 0x{status_word:04x}"));
let data = [
("VOUT ", status_vout),
("IOUT ", status_iout),
("TEMPERATURE ", status_temperature),
("CML ", status_cml),
("OTHER ", status_other),
("INPUT ", status_input),
("MFR_SPECIFIC ", status_mfr_specific),
("FANS_1_2 ", status_fans_1_2),
("FANS_3_4 ", status_fans_3_4),
];

use std::fmt::Write;
for (n, v) in data {
let mut l = n.to_string();
match v {
Ok(b) => write!(&mut l, "0x{b:02x}")?,
Err(e) => write!(&mut l, "Err({e:?})")?,
}
lines.push(l);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is cute! in future it might be nice to hook this onto the pmbus crate to decode the bit patterns, but i very much do not care about doing it in this PR.

Comment thread faux-mgs/src/main.rs Outdated
Comment thread gateway-messages/src/sp_to_mgs.rs Outdated
Comment on lines +756 to +757
/// Received unexpected data on the I2C bus
InvalidBusData,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we stop trying to interpret the status bits and then turn the m back into u8s, i think we can just get rid of this?

Comment thread gateway-messages/src/sp_to_mgs.rs Outdated
Comment on lines +804 to +807
if let Some(s) = self.as_str() {
debug.field("name", &s);
} else {
debug.field("name", self.name.contents());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i kinda wonder if NullStr should just have a Debug impl that does this, so that we can derive Debug for PowerRailName and SpComponent?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do this, that's a good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants