Skip to content

Commit

Permalink
Merge branch 'master' into ringbuf-coalesce
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkw authored Apr 11, 2024
2 parents a5af3f4 + 1522fc4 commit 00ebec8
Show file tree
Hide file tree
Showing 36 changed files with 511 additions and 194 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/build-one.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,10 @@ jobs:
target/release/humility -a target/${{ inputs.app_name }}/dist/build-${{ inputs.app_name }}-image-$image.zip manifest; \
done
# TODO: Clippy temporarily disabled 2024-04 while people clean up
# the new Clippy warnings resulting from the last toolchain
# upgrade. If you're reading this, try turning it back on and see
# if we're good yet.
#- name: Clippy
# if: inputs.os == 'ubuntu-latest'
# run: |
# cargo xtask clippy ${{ inputs.app_toml}} -- --deny warnings
- name: Clippy
if: inputs.os == 'ubuntu-latest'
run: |
cargo xtask clippy ${{ inputs.app_toml}} -- --deny warnings
# upload the output of our build
- name: Upload build archive
Expand Down
2 changes: 1 addition & 1 deletion app/demo-stm32h7-nucleo/app-h743.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ task-slots = ["sys"]

[tasks.net]
name = "task-net"
stacksize = 3000
stacksize = 4000
priority = 2
max-sizes = {flash = 65536, ram = 8192, sram1 = 32768}
features = ["h743"]
Expand Down
2 changes: 1 addition & 1 deletion app/demo-stm32h7-nucleo/app-h753.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ task-slots = ["sys"]

[tasks.net]
name = "task-net"
stacksize = 3000
stacksize = 4000
priority = 2
max-sizes = {flash = 131072, ram = 16384, sram1 = 32768}
features = ["h753"]
Expand Down
14 changes: 10 additions & 4 deletions app/gimlet/base.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ request_reset = ["hiffy", "control_plane_agent"]

[tasks.net]
name = "task-net"
stacksize = 6040
stacksize = 8000
priority = 5
features = ["mgmt", "h753", "gimlet", "vlan", "vpd-mac"]
max-sizes = {flash = 131072, ram = 65536, sram1 = 16384}
Expand Down Expand Up @@ -66,6 +66,12 @@ notifications = ["exti-wildcard-irq"]
"exti.exti9_5" = "exti-wildcard-irq"
"exti.exti15_10" = "exti-wildcard-irq"

# PWR_CONT1_VCORE_TO_SP_ALERT_L
[tasks.sys.config.gpio-irqs.vcore_to_sp_alert_l]
port = "I"
pin = 14
owner = {name = "gimlet_seq", notification = "vcore"}

[tasks.sys.config.gpio-irqs.rot_irq]
port = "E"
pin = 3
Expand Down Expand Up @@ -139,7 +145,7 @@ name = "task-power"
features = ["gimlet"]
priority = 6
max-sizes = {flash = 65536, ram = 16384 }
stacksize = 2800
stacksize = 3800
start = true
task-slots = ["i2c_driver", "sensor", "gimlet_seq"]
notifications = ["timer", "external_badness"]
Expand All @@ -157,11 +163,11 @@ task-slots = ["sys", "hf", "i2c_driver", "hash_driver", "update_server", "sprot"
name = "drv-gimlet-seq-server"
features = ["h753"]
priority = 4
max-sizes = {flash = 131072, ram = 8192 }
max-sizes = {flash = 131072, ram = 16384 }
stacksize = 1600
start = true
task-slots = ["sys", "i2c_driver", {spi_driver = "spi2_driver"}, "hf", "jefe", "packrat"]
notifications = ["timer"]
notifications = ["timer", "vcore"]
copy-to-archive = ["register_defs"]

[tasks.gimlet_seq.config]
Expand Down
2 changes: 1 addition & 1 deletion app/gimletlet/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ notifications = ["hash-irq"]

[tasks.net]
name = "task-net"
stacksize = 6040
stacksize = 8000
priority = 3
features = ["h753", "vlan", "gimletlet-nic", "use-spi-core", "spi4"]
max-sizes = {flash = 131072, ram = 65536, sram1 = 16384}
Expand Down
2 changes: 1 addition & 1 deletion app/psc/base.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ task-slots = ["i2c_driver"]

[tasks.net]
name = "task-net"
stacksize = 6040
stacksize = 8000
priority = 4
features = ["mgmt", "h753", "psc", "vlan", "vpd-mac", "use-spi-core", "spi2"]
max-sizes = {flash = 131072, ram = 65536, sram1 = 16384}
Expand Down
4 changes: 2 additions & 2 deletions app/sidecar/base.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ task-slots = ["sys"]

[tasks.net]
name = "task-net"
stacksize = 6040
stacksize = 8000
priority = 5
features = ["mgmt", "h753", "sidecar", "vlan", "vpd-mac", "use-spi-core", "spi3"]
max-sizes = {flash = 131072, ram = 65536, sram1 = 16384}
Expand Down Expand Up @@ -278,7 +278,7 @@ name = "task-power"
features = ["sidecar"]
priority = 6
max-sizes = {flash = 32768, ram = 8192 }
stacksize = 2800
stacksize = 3800
start = true
task-slots = ["i2c_driver", "sensor", "sequencer"]
notifications = ["timer"]
Expand Down
4 changes: 2 additions & 2 deletions build/stm32xx-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl SysConfig {
},
) in &self.gpio_irqs
{
match dispatch_table.get_mut(pin as usize) {
match dispatch_table.get_mut(pin) {
Some(Some(curr)) => {
anyhow::bail!("pin {pin} is already mapped to IRQ {curr:?}")
}
Expand Down Expand Up @@ -242,7 +242,7 @@ impl SysConfig {

fn to_const_name(mut s: String) -> anyhow::Result<syn::Ident> {
s.make_ascii_uppercase();
let s = s.replace("-", "_");
let s = s.replace('-', "_");
syn::parse_str::<syn::Ident>(&s)
.with_context(|| format!("`{s}` is not a valid Rust identifier"))
}
2 changes: 2 additions & 0 deletions drv/gimlet-hf-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ impl ServerImpl {
addr: Option<u32>,
raw_data: &RawPersistentData,
) -> Result<(), HfError> {
// Clippy misfire as of 2024-04
#[allow(clippy::manual_unwrap_or_default)]
let addr = match addr {
Some(a) => a,
None => {
Expand Down
93 changes: 78 additions & 15 deletions drv/gimlet-seq-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#![no_main]

mod seq_spi;
mod vcore;

use counters::*;
use ringbuf::*;
Expand Down Expand Up @@ -46,6 +47,17 @@ include!(concat!(env!("OUT_DIR"), "/i2c_config.rs"));
)]
mod payload;

#[derive(Copy, Clone, PartialEq, Count)]
enum I2cTxn {
SpdLoad(u8, u8),
SpdLoadTop(u8, u8),
VCoreOn,
VCoreOff,
VCoreUndervoltageInitialize,
SocOn,
SocOff,
}

#[derive(Copy, Clone, PartialEq, Count)]
enum Trace {
Ice40Rails(bool, bool),
Expand Down Expand Up @@ -111,11 +123,17 @@ enum Trace {
SpdBankAbsent(u8),
SpdAbsent(u8, u8, u8),
SpdDimmsFound(usize),
I2cFault {
retries_remaining: u8,
I2cError {
txn: I2cTxn,
#[count(children)]
code: i2c::ResponseCode,
},
I2cFault(I2cTxn),
I2cRetry {
#[count(children)]
txn: I2cTxn,
retries_remaining: u8,
},
StartFailed(#[count(children)] SeqError),
#[count(skip)]
None,
Expand Down Expand Up @@ -165,6 +183,7 @@ struct ServerImpl<S: SpiServer> {
seq: seq_spi::SequencerFpga<S>,
jefe: Jefe,
hf: hf_api::HostFlash,
vcore: vcore::VCore,
deadline: u64,
}

Expand Down Expand Up @@ -446,13 +465,16 @@ impl<S: SpiServer + Clone> ServerImpl<S> {
// Turn on the chassis LED once we reach A2
sys.gpio_set(CHASSIS_LED);

let (device, rail) = i2c_config::pmbus::vdd_vcore(I2C.get_task_id());

let mut server = Self {
state: PowerState::A2,
sys: sys.clone(),
seq,
jefe,
hf,
deadline: 0,
vcore: vcore::VCore::new(sys, &device, rail),
};

// Power on, unless suppressed by the `stay-in-a2` feature
Expand Down Expand Up @@ -484,10 +506,18 @@ impl<S: SpiServer + Clone> ServerImpl<S> {

impl<S: SpiServer> NotificationHandler for ServerImpl<S> {
fn current_notification_mask(&self) -> u32 {
notifications::TIMER_MASK
notifications::TIMER_MASK | self.vcore.mask()
}

fn handle_notification(&mut self, _bits: u32) {
fn handle_notification(&mut self, bits: u32) {
if (bits & self.vcore.mask()) != 0 {
self.vcore.handle_notification();
}

if (bits & notifications::TIMER_MASK) == 0 {
return;
}

let ifr = self.seq.read_byte(Addr::IFR).unwrap_lite();
ringbuf_entry!(Trace::Status {
ier: self.seq.read_byte(Addr::IER).unwrap_lite(),
Expand Down Expand Up @@ -592,6 +622,7 @@ impl<S: SpiServer> NotificationHandler for ServerImpl<S> {
}

fn retry_i2c_txn<T, E>(
which: I2cTxn,
mut txn: impl FnMut() -> Result<T, E>,
) -> Result<T, i2c::ResponseCode>
where
Expand All @@ -604,15 +635,18 @@ where
Ok(x) => return Ok(x),
Err(e) => {
let code = e.into();
ringbuf_entry!(Trace::I2cFault {
retries_remaining,
code,
});
ringbuf_entry!(Trace::I2cError { txn: which, code });

if retries_remaining == 0 {
ringbuf_entry!(Trace::I2cFault(which));
return Err(code);
}

ringbuf_entry!(Trace::I2cRetry {
txn: which,
retries_remaining
});

retries_remaining -= 1;
}
}
Expand Down Expand Up @@ -665,6 +699,15 @@ impl<S: SpiServer> ServerImpl<S> {
return Err(SeqError::MuxToHostCPUFailed);
}

//
// If we fail to initialize our UV warning despite retries, we
// will drive on: the failures will be logged, and this isn't
// strictly required to sequence.
//
_ = retry_i2c_txn(I2cTxn::VCoreUndervoltageInitialize, || {
self.vcore.initialize_uv_warning()
});

let start = sys_get_timer().now;
let deadline = start + A0_TIMEOUT_MILLIS;

Expand Down Expand Up @@ -1119,7 +1162,20 @@ fn read_spd_data_and_load_packrat(
// We'll store that byte and then read 255 more.
tmp[0] = first;

retry_i2c_txn(|| spd.read_into(&mut tmp[1..]))?;
let mut retried = false;

retry_i2c_txn(I2cTxn::SpdLoad(nbank, i), || {
if retried {
//
// If our read needs to be retried, we need to also reset
// ourselves back to the 0th byte.
//
_ = spd.read_reg::<u8, u8>(0)?;
}

retried = true;
spd.read_into(&mut tmp[1..])
})?;

packrat.set_spd_eeprom(ndx, false, 0, &tmp);
}
Expand All @@ -1146,9 +1202,16 @@ fn read_spd_data_and_load_packrat(
let spd = I2cDevice::new(i2c_task, controller, port, mux, mem);

let chunk = 128;
retry_i2c_txn(|| spd.read_reg_into::<u8>(0, &mut tmp[..chunk]))?;

retry_i2c_txn(|| spd.read_into(&mut tmp[chunk..]))?;
retry_i2c_txn(I2cTxn::SpdLoadTop(nbank, i), || {
//
// Both of these reads need to be in a single transaction from
// the perspective of the retry logic: if either fails, we
// must redo both.
//
spd.read_reg_into::<u8>(0, &mut tmp[..chunk])?;
spd.read_into(&mut tmp[chunk..])
})?;

packrat.set_spd_eeprom(ndx, true, 0, &tmp);
}
Expand Down Expand Up @@ -1302,8 +1365,8 @@ cfg_if::cfg_if! {
let (device, rail) = i2c_config::pmbus::vddcr_soc(i2c);
let mut vddcr_soc = Raa229618::new(&device, rail);

retry_i2c_txn(|| vdd_vcore.turn_off())?;
retry_i2c_txn(|| vddcr_soc.turn_off())?;
retry_i2c_txn(I2cTxn::VCoreOff, || vdd_vcore.turn_off())?;
retry_i2c_txn(I2cTxn::SocOff, || vddcr_soc.turn_off())?;
Ok(())
}

Expand All @@ -1317,8 +1380,8 @@ cfg_if::cfg_if! {
let (device, rail) = i2c_config::pmbus::vddcr_soc(i2c);
let mut vddcr_soc = Raa229618::new(&device, rail);

retry_i2c_txn(|| vdd_vcore.turn_on())?;
retry_i2c_txn(|| vddcr_soc.turn_on())?;
retry_i2c_txn(I2cTxn::VCoreOn, || vdd_vcore.turn_on())?;
retry_i2c_txn(I2cTxn::SocOn, || vddcr_soc.turn_on())?;
Ok(())
}

Expand Down
Loading

0 comments on commit 00ebec8

Please sign in to comment.