Skip to content

Commit 437f02b

Browse files
committed
Add command APIs
1 parent 0158ec7 commit 437f02b

5 files changed

Lines changed: 60 additions & 53 deletions

File tree

faux-mgs/src/main.rs

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3281,27 +3281,8 @@ fn component_details_to_json(details: SpComponentDetails) -> serde_json::Value {
32813281
Measurement(Measurement),
32823282
LastPostCode(u32),
32833283
PostCode(u32),
3284-
GpioToggleCount {
3285-
edge_count: u32,
3286-
cycles_since_last_edge: u32,
3287-
},
3288-
Pcie {
3289-
bar: u32,
3290-
offset: u32,
3291-
reg_result: Result<u32, u32>,
3292-
},
3293-
PmbusStatus {
3294-
status_word: u16,
3295-
status_vout: u8,
3296-
status_iout: u8,
3297-
status_temperature: u8,
3298-
status_cml: u8,
3299-
status_other: u8,
3300-
status_input: u8,
3301-
status_mfr_specific: u8,
3302-
status_fans_1_2: u8,
3303-
status_fans_3_4: u8,
3304-
},
3284+
GpioToggleCount { edge_count: u32, cycles_since_last_edge: u32 },
3285+
Pcie { bar: u32, offset: u32, reg_result: Result<u32, u32> },
33053286
}
33063287

33073288
#[derive(serde::Serialize)]
@@ -3344,20 +3325,6 @@ fn component_details_to_json(details: SpComponentDetails) -> serde_json::Value {
33443325
reg_result: p.reg_result,
33453326
}
33463327
}
3347-
gateway_messages::ComponentDetails::PmbusStatus(stat) => {
3348-
ComponentDetails::PmbusStatus {
3349-
status_word: stat.status_word,
3350-
status_vout: stat.status_vout,
3351-
status_iout: stat.status_iout,
3352-
status_temperature: stat.status_temperature,
3353-
status_cml: stat.status_cml,
3354-
status_other: stat.status_other,
3355-
status_input: stat.status_input,
3356-
status_mfr_specific: stat.status_mfr_specific,
3357-
status_fans_1_2: stat.status_fans_1_2,
3358-
status_fans_3_4: stat.status_fans_3_4,
3359-
}
3360-
}
33613328
})
33623329
.collect::<Vec<_>>();
33633330

gateway-messages/src/mgs_to_sp.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! Types for messages sent from MGS to SPs.
66
77
use crate::BadRequestReason;
8+
use crate::PowerRailName;
89
use crate::PowerState;
910
use crate::RotRequest;
1011
use crate::RotSlotId;
@@ -241,6 +242,9 @@ pub enum MgsRequest {
241242
/// current default slot as persisted in non-volatile memory. This may be
242243
/// different than the current active slot (see `ComponentGetActiveSlot`).
243244
ComponentGetPersistentSlot(SpComponent),
245+
246+
/// Request the STATUS registers of a PMBus device, indexed by Power Rail Name
247+
GetPMBusStatus(PowerRailName),
244248
}
245249

246250
#[derive(

gateway-messages/src/sp_impl.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ use crate::MessageKind;
2626
use crate::MgsError;
2727
use crate::MgsRequest;
2828
use crate::MgsResponse;
29+
use crate::PMBusStatusResponse;
30+
use crate::PmbusStatus;
31+
use crate::PmbusStatusError;
32+
use crate::PowerRailName;
2933
use crate::PowerState;
3034
use crate::PowerStateTransition;
3135
use crate::ROT_PAGE_SIZE;
@@ -422,6 +426,11 @@ pub trait SpHandler {
422426
fn start_host_flash_hash(&mut self, slot: u16) -> Result<(), SpError>;
423427

424428
fn get_host_flash_hash(&mut self, slot: u16) -> Result<[u8; 32], SpError>;
429+
430+
fn get_pmbus_status(
431+
&mut self,
432+
rail: &PowerRailName,
433+
) -> Result<Result<PmbusStatus, PmbusStatusError>, SpError>;
425434
}
426435

427436
/// Handle a single incoming message.
@@ -1055,6 +1064,14 @@ fn handle_mgs_request<H: SpHandler>(
10551064
MgsRequest::GetHostFlashHash { slot } => {
10561065
handler.get_host_flash_hash(slot).map(SpResponse::HostFlashHash)
10571066
}
1067+
MgsRequest::GetPMBusStatus(power_rail_name) => {
1068+
handler.get_pmbus_status(&power_rail_name).map(|res| {
1069+
SpResponse::PmbusStatus(PMBusStatusResponse {
1070+
rail: power_rail_name,
1071+
result: res,
1072+
})
1073+
})
1074+
}
10581075
};
10591076

10601077
let response = match result {
@@ -1487,6 +1504,13 @@ mod tests {
14871504
) -> Result<[u8; 32], SpError> {
14881505
unimplemented!()
14891506
}
1507+
1508+
fn get_pmbus_status(
1509+
&mut self,
1510+
_rail: &PowerRailName,
1511+
) -> Result<Result<PmbusStatus, PmbusStatusError>, SpError> {
1512+
unimplemented!()
1513+
}
14901514
}
14911515

14921516
#[cfg(feature = "std")]

gateway-messages/src/sp_to_mgs.rs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! Types for messages sent from SPs to MGS.
66
77
use crate::BadRequestReason;
8+
use crate::PowerRailName;
89
use crate::PowerState;
910
use crate::RotResponse;
1011
use crate::RotSlotId;
@@ -186,6 +187,17 @@ pub enum SpResponse {
186187

187188
/// Default slot as persisted in non-volatile memory
188189
ComponentPersistentSlot(u16),
190+
191+
/// PMBus status of a given rail
192+
PmbusStatus(PMBusStatusResponse),
193+
}
194+
195+
#[derive(
196+
Clone, Copy, Debug, PartialEq, Serialize, Deserialize, SerializedSize,
197+
)]
198+
pub struct PMBusStatusResponse {
199+
pub rail: PowerRailName,
200+
pub result: Result<PmbusStatus, PmbusStatusError>,
189201
}
190202

191203
/// Identifier for one of of an SP's KSZ8463 management-network-facing ports.
@@ -712,24 +724,25 @@ pub struct TlvPage {
712724
pub total: u32,
713725
}
714726

727+
#[derive(
728+
Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, SerializedSize,
729+
)]
730+
pub enum PmbusStatusError {}
731+
715732
#[derive(
716733
Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, SerializedSize,
717734
)]
718735
pub struct PmbusStatus {
719736
pub status_word: u16,
720-
pub status_vout: u8,
721-
pub status_iout: u8,
722-
pub status_temperature: u8,
723-
pub status_cml: u8,
724-
pub status_other: u8,
725-
pub status_input: u8,
726-
pub status_mfr_specific: u8,
727-
pub status_fans_1_2: u8,
728-
pub status_fans_3_4: u8,
729-
}
730-
731-
impl PmbusStatus {
732-
pub const TAG: tlv::Tag = tlv::Tag(*b"PMBS");
737+
pub status_vout: Result<u8, PmbusStatusError>,
738+
pub status_iout: Result<u8, PmbusStatusError>,
739+
pub status_temperature: Result<u8, PmbusStatusError>,
740+
pub status_cml: Result<u8, PmbusStatusError>,
741+
pub status_other: Result<u8, PmbusStatusError>,
742+
pub status_input: Result<u8, PmbusStatusError>,
743+
pub status_mfr_specific: Result<u8, PmbusStatusError>,
744+
pub status_fans_1_2: Result<u8, PmbusStatusError>,
745+
pub status_fans_3_4: Result<u8, PmbusStatusError>,
733746
}
734747

735748
/// Types of component details that can be included in the TLV-encoded data of
@@ -749,7 +762,6 @@ pub enum ComponentDetails {
749762
PostCode(PostCode),
750763
GpioToggleCount(GpioToggleCount),
751764
Pcie(PcieRegisterRead),
752-
PmbusStatus(PmbusStatus),
753765
}
754766

755767
impl ComponentDetails {
@@ -761,7 +773,6 @@ impl ComponentDetails {
761773
ComponentDetails::PostCode(_) => PostCode::TAG,
762774
ComponentDetails::GpioToggleCount(_) => GpioToggleCount::TAG,
763775
ComponentDetails::Pcie(_) => PcieRegisterRead::TAG,
764-
ComponentDetails::PmbusStatus(_) => PmbusStatus::TAG,
765776
}
766777
}
767778

@@ -791,9 +802,6 @@ impl ComponentDetails {
791802
hubpack::serialize(buf, code)
792803
}
793804
ComponentDetails::Pcie(p) => hubpack::serialize(buf, p),
794-
ComponentDetails::PmbusStatus(stat) => {
795-
hubpack::serialize(buf, stat)
796-
}
797805
}
798806
}
799807
}

wireshark/protofields.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ M.mgs_request.names = {
9595
[48] = "StartHostFlashHash",
9696
[49] = "GetHostFlashHash",
9797
[50] = "ComponentGetPersistentSlot",
98+
[51] = "GetPmBusStatus",
9899
}
99100
M.mgs_request.handlers = {
100101
[0] = "dissect_discover",
@@ -148,6 +149,7 @@ M.mgs_request.handlers = {
148149
[48] = "dissect_start_host_flash_hash",
149150
[49] = "dissect_get_host_flash_hash",
150151
[50] = "dissect_component_get_persistent_slot",
152+
[51] = "dissect_get_pm_bus_status",
151153
}
152154
M.mgs_request.field = ProtoField.uint8(
153155
"mgs.mgs_request",
@@ -333,6 +335,7 @@ M.sp_response.names = {
333335
[50] = "StartHostFlashHashAck",
334336
[51] = "HostFlashHash",
335337
[52] = "ComponentPersistentSlot",
338+
[53] = "PmbusStatus",
336339
}
337340
M.sp_response.handlers = {
338341
[0] = "dissect_discover",
@@ -388,6 +391,7 @@ M.sp_response.handlers = {
388391
[50] = "dissect_start_host_flash_hash_ack",
389392
[51] = "dissect_host_flash_hash",
390393
[52] = "dissect_component_persistent_slot",
394+
[53] = "dissect_pmbus_status",
391395
}
392396
M.sp_response.field = ProtoField.uint8(
393397
"mgs.sp_response",

0 commit comments

Comments
 (0)