Skip to content

Commit cf2e23b

Browse files
committed
cosmo-seq: use microcbor for Vcore ereports
Presently, the `cosmo_seq::vcore` module still uses `serde` to encode ereports rather than using `microcbor`. This is due to some kind of oversight on my part. It's sad for it to do that because the new `microcbor` crate lets us have a statically calculated buffer length for the ereport. This commit changes it to use the new and proper ereport serialization API instead of the old and unpreferred one.
1 parent ddfb878 commit cf2e23b

File tree

4 files changed

+37
-59
lines changed

4 files changed

+37
-59
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

drv/cosmo-seq-server/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ cfg-if = { workspace = true }
2929
idol-runtime.workspace = true
3030
num-traits = { workspace = true }
3131
pmbus = { workspace = true }
32-
serde = { workspace = true }
3332
zerocopy = { workspace = true }
3433
zerocopy-derive = { workspace = true }
3534

drv/cosmo-seq-server/src/main.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,9 @@ struct StateMachineStates {
164164
nic: Result<fmc_sequencer::NicSm, u8>,
165165
}
166166

167-
const EREPORT_BUF_LEN: usize = {
168-
let n = microcbor::max_cbor_len_for!(
169-
task_packrat_api::Ereport<EreportClass, EreportKind>,
170-
);
171-
// someday, we will have const max.
172-
if n < 256 {
173-
256
174-
} else {
175-
n
176-
}
177-
};
167+
const EREPORT_BUF_LEN: usize = microcbor::max_cbor_len_for!(
168+
task_packrat_api::Ereport<EreportClass, EreportKind>,
169+
);
178170

179171
#[export_name = "main"]
180172
fn main() -> ! {
@@ -451,6 +443,8 @@ struct ServerImpl {
451443

452444
#[derive(microcbor::Encode)]
453445
pub enum EreportClass {
446+
#[cbor(rename = "hw.pwr.pmbus.alert")]
447+
PmbusAlert,
454448
#[cbor(rename = "hw.pwr.bmr491.mitfail")]
455449
Bmr491MitigationFailure,
456450
}
@@ -463,6 +457,24 @@ pub(crate) enum EreportKind {
463457
last_cause: drv_i2c_devices::bmr491::MitigationFailureKind,
464458
succeeded: bool,
465459
},
460+
PmbusAlert {
461+
refdes: FixedStr<{ crate::i2c_config::MAX_COMPONENT_ID_LEN }>,
462+
rail: vcore::Rail,
463+
time: u64,
464+
pwr_good: Option<bool>,
465+
pmbus_status: PmbusStatus,
466+
},
467+
}
468+
469+
#[derive(Copy, Clone, Default, microcbor::Encode)]
470+
pub(crate) struct PmbusStatus {
471+
word: Option<u16>,
472+
input: Option<u8>,
473+
iout: Option<u8>,
474+
vout: Option<u8>,
475+
temp: Option<u8>,
476+
cml: Option<u8>,
477+
mfr: Option<u8>,
466478
}
467479

468480
impl ServerImpl {

drv/cosmo-seq-server/src/vcore.rs

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
use super::i2c_config;
1616
use drv_i2c_api::ResponseCode;
1717
use drv_i2c_devices::raa229620a::{self, Raa229620A};
18+
use fixedstr::FixedStr;
1819
use ringbuf::*;
19-
use serde::Serialize;
2020
use userlib::{sys_get_timer, units, TaskId};
2121

2222
pub(super) struct VCore {
@@ -27,10 +27,11 @@ pub(super) struct VCore {
2727
packrat: task_packrat_api::Packrat,
2828
}
2929

30-
#[derive(Copy, Clone, PartialEq, Serialize)]
31-
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
32-
enum Rail {
30+
#[derive(Copy, Clone, PartialEq, microcbor::Encode)]
31+
pub(crate) enum Rail {
32+
#[cbor(rename = "VDDCR_CPU0")]
3333
VddcrCpu0,
34+
#[cbor(rename = "VDDCR_CPU1")]
3435
VddcrCpu1,
3536
}
3637

@@ -71,9 +72,6 @@ enum Trace {
7172
StatusCml(Rail, Result<u8, ResponseCode>),
7273
StatusMfrSpecific(Rail, Result<u8, ResponseCode>),
7374
I2cError(Rail, PmbusCmd, raa229620a::Error),
74-
EreportSent(Rail, usize),
75-
EreportLost(Rail, usize, task_packrat_api::EreportWriteError),
76-
EreportTooBig(Rail),
7775
}
7876

7977
#[derive(Copy, Clone, PartialEq)]
@@ -366,7 +364,7 @@ impl VCore {
366364
.map(|s| s.0);
367365
ringbuf_entry!(Trace::StatusMfrSpecific(rail, status_mfr));
368366

369-
let pmbus_status = PmbusStatus {
367+
let pmbus_status = crate::PmbusStatus {
370368
word: status_word.map(|s| s.0).ok(),
371369
input: status_input.ok(),
372370
vout: status_vout.ok(),
@@ -376,27 +374,19 @@ impl VCore {
376374
mfr: status_mfr.ok(),
377375
};
378376

379-
let ereport = Ereport {
380-
k: "hw.pwr.pmbus.alert",
381-
v: 0,
377+
let ereport = crate::EreportKind::PmbusAlert {
382378
rail,
383-
refdes: device.i2c_device().component_id(),
379+
refdes: FixedStr::from_str(device.i2c_device().component_id()),
384380
time: now,
385381
pmbus_status,
386382
pwr_good: power_good,
387383
};
388-
match self.packrat.serialize_ereport(&ereport, ereport_buf) {
389-
Ok(len) => ringbuf_entry!(Trace::EreportSent(rail, len)),
390-
Err(task_packrat_api::EreportSerializeError::Packrat {
391-
len,
392-
err,
393-
}) => {
394-
ringbuf_entry!(Trace::EreportLost(rail, len, err))
395-
}
396-
Err(task_packrat_api::EreportSerializeError::Serialize(_)) => {
397-
ringbuf_entry!(Trace::EreportTooBig(rail))
398-
}
399-
}
384+
crate::try_send_ereport(
385+
&self.packrat,
386+
ereport_buf,
387+
crate::EreportClass::PmbusAlert,
388+
ereport,
389+
);
400390
// TODO(eliza): if POWER_GOOD has been deasserted, we should produce a
401391
// subsequent ereport for that.
402392

@@ -407,28 +397,6 @@ impl VCore {
407397
}
408398
}
409399

410-
#[derive(Serialize)]
411-
struct Ereport {
412-
k: &'static str,
413-
v: usize,
414-
refdes: &'static str,
415-
rail: Rail,
416-
time: u64,
417-
pwr_good: Option<bool>,
418-
pmbus_status: PmbusStatus,
419-
}
420-
421-
#[derive(Copy, Clone, Default, Serialize)]
422-
struct PmbusStatus {
423-
word: Option<u16>,
424-
input: Option<u8>,
425-
iout: Option<u8>,
426-
vout: Option<u8>,
427-
temp: Option<u8>,
428-
cml: Option<u8>,
429-
mfr: Option<u8>,
430-
}
431-
432400
struct RegulatorState {
433401
faulted: bool,
434402
input_fault: bool,

0 commit comments

Comments
 (0)