diff --git a/Cargo.lock b/Cargo.lock index d6a1b49000..0a93e27652 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2105,7 +2105,7 @@ checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" [[package]] name = "stela-boot-core" -version = "0.6.0" +version = "0.6.1" dependencies = [ "serde_json", "sha2", @@ -2125,7 +2125,7 @@ dependencies = [ [[package]] name = "stela-c-build" -version = "0.6.0" +version = "0.6.1" dependencies = [ "cc", "libc", @@ -2136,7 +2136,7 @@ dependencies = [ [[package]] name = "stela-cli" -version = "0.6.0" +version = "0.6.1" dependencies = [ "aes 0.8.4", "anyhow", @@ -2180,7 +2180,7 @@ dependencies = [ [[package]] name = "stela-compiler" -version = "0.6.0" +version = "0.6.1" dependencies = [ "rustc_apfloat", "serde", @@ -2189,14 +2189,14 @@ dependencies = [ [[package]] name = "stela-contracts" -version = "0.6.0" +version = "0.6.1" dependencies = [ "serde", ] [[package]] name = "stela-crypto" -version = "0.6.0" +version = "0.6.1" dependencies = [ "aes 0.8.4", "chacha20 0.10.2", @@ -2210,7 +2210,7 @@ dependencies = [ [[package]] name = "stela-dev" -version = "0.6.0" +version = "0.6.1" dependencies = [ "anyhow", "clap", @@ -2229,7 +2229,7 @@ dependencies = [ [[package]] name = "stela-driver-audio" -version = "0.6.0" +version = "0.6.1" dependencies = [ "sha2", "stela-driver-base", @@ -2238,7 +2238,7 @@ dependencies = [ [[package]] name = "stela-driver-base" -version = "0.6.0" +version = "0.6.1" dependencies = [ "cc", "sha2", @@ -2250,7 +2250,7 @@ dependencies = [ [[package]] name = "stela-driver-core" -version = "0.6.0" +version = "0.6.1" dependencies = [ "sha2", "stela-contracts", @@ -2259,7 +2259,7 @@ dependencies = [ [[package]] name = "stela-driver-gpu" -version = "0.6.0" +version = "0.6.1" dependencies = [ "ash", "cc", @@ -2276,7 +2276,7 @@ dependencies = [ [[package]] name = "stela-driver-net" -version = "0.6.0" +version = "0.6.1" dependencies = [ "aes 0.8.4", "hmac", @@ -2292,7 +2292,7 @@ dependencies = [ [[package]] name = "stela-driver-storage" -version = "0.6.0" +version = "0.6.1" dependencies = [ "stela-driver-base", "stela-driver-core", @@ -2300,7 +2300,7 @@ dependencies = [ [[package]] name = "stela-drivers" -version = "0.6.0" +version = "0.6.1" dependencies = [ "sha2", "stela-contracts", @@ -2315,7 +2315,7 @@ dependencies = [ [[package]] name = "stela-engine" -version = "0.6.0" +version = "0.6.1" dependencies = [ "anyhow", "hex", @@ -2333,14 +2333,14 @@ dependencies = [ [[package]] name = "stela-fingerprint" -version = "0.6.0" +version = "0.6.1" dependencies = [ "sha2", ] [[package]] name = "stela-formats" -version = "0.6.0" +version = "0.6.1" dependencies = [ "crypto-bigint", "hex", @@ -2358,7 +2358,7 @@ dependencies = [ [[package]] name = "stela-gpu-maintenance" -version = "0.6.0" +version = "0.6.1" dependencies = [ "anyhow", "clap", @@ -2375,7 +2375,7 @@ dependencies = [ [[package]] name = "stela-linux" -version = "0.6.0" +version = "0.6.1" dependencies = [ "cc", "libc", @@ -2389,7 +2389,7 @@ dependencies = [ [[package]] name = "stela-loader" -version = "0.6.0" +version = "0.6.1" dependencies = [ "anyhow", "hex", @@ -2412,7 +2412,7 @@ dependencies = [ [[package]] name = "stela-metal-input" -version = "0.6.0" +version = "0.6.1" dependencies = [ "stela-contracts", "stela-crypto", @@ -2420,7 +2420,7 @@ dependencies = [ [[package]] name = "stela-runtime" -version = "0.6.0" +version = "0.6.1" dependencies = [ "anyhow", "getrandom 0.2.17", @@ -2446,7 +2446,7 @@ dependencies = [ [[package]] name = "stela-soc" -version = "0.6.0" +version = "0.6.1" dependencies = [ "aes 0.8.4", "hex", @@ -2466,7 +2466,7 @@ dependencies = [ [[package]] name = "stela-soc-data" -version = "0.6.0" +version = "0.6.1" dependencies = [ "hex", "sha2", @@ -2477,7 +2477,7 @@ dependencies = [ [[package]] name = "stela-tls" -version = "0.6.0" +version = "0.6.1" dependencies = [ "aes 0.9.3", "aes-gcm 0.11.1", @@ -3068,7 +3068,7 @@ dependencies = [ [[package]] name = "xtask" -version = "0.6.0" +version = "0.6.1" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index 6ddfe7d461..11ea399ceb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,7 +60,7 @@ exclude = ["crates/stela-boot", "crates/stela-mesa", "third_party/smoltcp"] resolver = "2" [workspace.package] -version = "0.6.0" +version = "0.6.1" edition = "2024" license = "GPL-2.0-or-later" repository = "https://github.com/tylertms/Stela" diff --git a/crates/stela-boot-core/src/wifi_hardware.rs b/crates/stela-boot-core/src/wifi_hardware.rs index dc6f36a661..49b7d65110 100644 --- a/crates/stela-boot-core/src/wifi_hardware.rs +++ b/crates/stela-boot-core/src/wifi_hardware.rs @@ -78,12 +78,56 @@ pub fn decide(census: Result, &str>) -> Hardware { ) } +/// The widest line of [`Hardware::unavailable`], in characters, so the +/// page's text stays inside the startup menu's column. +pub const PAGE_LINE: usize = 40; + impl Hardware { /// Whether the menu shows its Wi-Fi line and `W` opens the page. pub fn offered(&self) -> bool { !matches!(self, Self::Absent(_)) } + /// The menu's bottom line on a PC with a Wi-Fi chip no driver here + /// starts, where `W` opens [`Self::unavailable`]'s page; none otherwise. + pub fn unsupported_line(&self) -> Option<&'static str> { + matches!(self, Self::Absent(chips) if !chips.is_empty()) + .then_some("Wi-Fi: this chip isn't supported yet (press W)") + } + + /// What `W` shows when the menu offers no Wi-Fi page: that the PC's + /// Wi-Fi chip (the first, by vendor and device ID) is not supported yet + /// and what to use instead, or that the PC has none. Each line at most + /// [`PAGE_LINE`] characters. None when the Wi-Fi page is offered. + pub fn unavailable(&self) -> Option> { + let Self::Absent(chips) = self else { + return None; + }; + let Some((chip, rest)) = chips.split_first() else { + return Some(Vec::from([ + String::from("This PC has no Wi-Fi chip that Stambha"), + String::from("can see. Use Ethernet, or a USB tether"), + String::from("or a supported Wi-Fi card."), + ])); + }; + let id = format!("{:04x}:{:04x}", chip.vendor, chip.device); + let named = match vendor(chip.vendor) { + Some(vendor) => format!("{vendor} {id}"), + None => id, + }; + let more = match rest.len() { + 0 => String::new(), + more => format!(", and {more} more"), + }; + Some(Vec::from([ + String::from("This PC's Wi-Fi chip isn't supported"), + format!("yet: {named}{more}."), + String::from("Use Ethernet, or a USB tether or a"), + String::from("supported Wi-Fi card. To ask for this"), + String::from("chip, post your log in hardware-reports."), + ])) + } + /// The boot log's one line saying which way the menu decided. pub fn line(&self) -> String { let named = |function: &Identity| { @@ -112,6 +156,20 @@ impl Hardware { } } +/// The name of a Wi-Fi chip's PCI vendor, for the few that make them. +fn vendor(id: u16) -> Option<&'static str> { + Some(match id { + 0x8086 => "Intel", + 0x14c3 => "MediaTek", + 0x10ec => "Realtek", + 0x14e4 => "Broadcom", + 0x168c => "Qualcomm Atheros", + 0x17cb => "Qualcomm", + 0x1814 => "Ralink", + _ => return None, + }) +} + #[cfg(test)] mod tests { use super::*; @@ -194,6 +252,56 @@ mod tests { ); } + /// W on a PC whose Wi-Fi chip no driver here starts, or with none: + /// the menu says the chip is not supported and W opens a page saying + /// what to use instead; with no chip, the page says so and the menu + /// keeps its bottom line clear. + #[test] + fn an_unsupported_or_missing_chip_gets_its_own_page() { + let ac9560 = function(2, 0x8086, 0x9df0, WIFI); + let mut functions = others(); + functions.push(ac9560); + let hardware = decide(census(&functions, 0)); + assert_eq!( + hardware.unsupported_line(), + Some("Wi-Fi: this chip isn't supported yet (press W)") + ); + let page = hardware.unavailable().unwrap(); + assert_eq!(page[1], "yet: Intel 8086:9df0."); + assert!(page.iter().any(|line| line.contains("hardware-reports"))); + assert!(page.iter().all(|line| line.chars().count() <= PAGE_LINE)); + // A second chip is counted, and an unknown vendor shows its ID alone. + functions.push(function(3, 0x1234, 0x5678, WIFI)); + let page = decide(census(&functions, 0)).unavailable().unwrap(); + assert_eq!(page[1], "yet: Intel 8086:9df0, and 1 more."); + let unnamed = Hardware::Absent(Vec::from([function(3, 0x1234, 0x5678, WIFI)])); + assert_eq!(unnamed.unavailable().unwrap()[1], "yet: 1234:5678."); + let atheros = Hardware::Absent(Vec::from([function(3, 0x168c, 0x003e, WIFI)])); + assert!( + atheros + .unavailable() + .unwrap() + .iter() + .all(|line| line.chars().count() <= PAGE_LINE) + ); + // No Wi-Fi chip at all. + let none = decide(census(&others(), 0)); + assert_eq!(none.unsupported_line(), None); + let page = none.unavailable().unwrap(); + assert!(page[0].starts_with("This PC has no Wi-Fi chip")); + assert!(page.iter().all(|line| line.chars().count() <= PAGE_LINE)); + // A chip the driver starts, or an unknown census, opens the Wi-Fi + // page itself. + let mut functions = others(); + functions.push(function(3, 0x10ec, 0xc852, WIFI)); + for hardware in [decide(census(&functions, 0)), decide(Err("none"))] { + assert_eq!( + (hardware.unsupported_line(), hardware.unavailable()), + (None, None) + ); + } + } + #[test] fn failed_census_offers_wifi() { let hardware = decide(Err("enumerate protocol: NOT_FOUND")); diff --git a/crates/stela-boot-core/src/wifi_page.rs b/crates/stela-boot-core/src/wifi_page.rs index 0436eceb2e..22ec704644 100644 --- a/crates/stela-boot-core/src/wifi_page.rs +++ b/crates/stela-boot-core/src/wifi_page.rs @@ -28,16 +28,29 @@ const CARD: usize = 244; /// The startup menu's Wi-Fi line: the network this boot joins first, the /// one the page chose (`prefer`) or else stela.cfg's `--wifi` one /// (`configured`), and the key that changes it. With no `--wifi` the boot -/// joins nothing, and saved networks (`saved`) can still be managed. `None` -/// when this boot has neither. No password reaches it. -pub fn status_line(configured: Option<&str>, prefer: Option<&str>, saved: bool) -> Option { +/// joins nothing, and saved networks (`saved`) can still be managed. With +/// neither, the line says how to choose one: Wi-Fi works only once a +/// network is chosen, and testers missed the key. No password reaches it. +pub fn status_line(configured: Option<&str>, prefer: Option<&str>, saved: bool) -> String { let network = match (configured, prefer) { (Some(_), Some(prefer)) => prefer, (Some(configured), None) => configured, (None, _) if saved => "not set up", - (None, _) => return None, + (None, _) => return String::from(CHOOSE), }; - Some(format!("Wi-Fi: {network} \u{b7} press W to change")) + format!("Wi-Fi: {network} \u{b7} press W to change") +} + +/// The startup menu's Wi-Fi line when no network is set up. +pub const CHOOSE: &str = "Wi-Fi: press W to choose a network"; + +/// The boot log's line for a menu that offers Wi-Fi with no network set up +/// (`configured` none and nothing `saved`): the hint the menu shows. +pub fn hint_line(configured: Option<&str>, saved: bool) -> Option<&'static str> { + (configured.is_none() && !saved).then_some( + "CHOICE Wi-Fi: no network is set up; press W in this menu to choose one, or Wi-Fi \ + stays off\n", + ) } /// One network the page lists. @@ -644,6 +657,38 @@ fn draw_form(scene: &mut Scene, layout: &Layout, form: &Form, joins: bool) { scene.text(left + 20, y + 212, message, tone); } +/// The page `W` opens where the startup menu offers no Wi-Fi page +/// (`wifi_hardware::Hardware::unavailable`): its `lines` on a card in the +/// menu's column, the first bright, and the key that leaves. +pub fn unavailable_scene(lines: &[String], geometry: Geometry) -> Scene { + let mut scene = Scene { + draws: Vec::new(), + glyph: geometry.glyph.max(1), + }; + let layout = Layout::new(geometry); + scene.text(layout.left + 16, layout.top, "Wi-Fi", Tone::Text); + let card = 24 + lines.len() * 28; + scene.panel( + layout.left, + layout.caption, + layout.column, + card, + 8, + Tone::Card, + ); + for (index, line) in lines.iter().enumerate() { + let tone = if index == 0 { Tone::Text } else { Tone::Dim }; + scene.text( + layout.left + 20, + layout.caption + 16 + index * 28, + line, + tone, + ); + } + scene.centred(layout.middle, layout.keys, "Esc: back", Tone::Dim); + scene +} + /// The screen the page is drawn on, in page units (`screen::scale`). #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct Geometry { diff --git a/crates/stela-boot-core/src/wifi_page/tests.rs b/crates/stela-boot-core/src/wifi_page/tests.rs index ed7413b5f9..efe1a4508d 100644 --- a/crates/stela-boot-core/src/wifi_page/tests.rs +++ b/crates/stela-boot-core/src/wifi_page/tests.rs @@ -71,27 +71,71 @@ fn has_text(scene: &Scene, wanted: &str) -> bool { #[test] fn the_status_line_names_the_network_this_boot_joins_first() { assert_eq!( - status_line(Some("home"), None, false).as_deref(), - Some("Wi-Fi: home \u{b7} press W to change") + status_line(Some("home"), None, false), + "Wi-Fi: home \u{b7} press W to change" ); assert_eq!( - status_line(Some("home"), Some("cafe"), true).as_deref(), - Some("Wi-Fi: cafe \u{b7} press W to change") + status_line(Some("home"), Some("cafe"), true), + "Wi-Fi: cafe \u{b7} press W to change" ); } #[test] fn the_status_line_shows_not_set_up_only_with_saved_networks() { assert_eq!( - status_line(None, None, true).as_deref(), - Some("Wi-Fi: not set up \u{b7} press W to change") + status_line(None, None, true), + "Wi-Fi: not set up \u{b7} press W to change" ); // A preference without `--wifi` joins nothing, as `with_prefer` adds none. assert_eq!( - status_line(None, Some("cafe"), true).as_deref(), - Some("Wi-Fi: not set up \u{b7} press W to change") + status_line(None, Some("cafe"), true), + "Wi-Fi: not set up \u{b7} press W to change" ); - assert_eq!(status_line(None, None, false), None); +} + +/// The page W opens without a Wi-Fi chip the driver starts shows each line +/// inside the menu's column, and Esc. +#[test] +fn the_unavailable_page_draws_its_lines_in_the_column() { + let lines = [String::from("first"), String::from("second")]; + let geometry = Geometry { + width: 1280, + height: 720, + top: 80, + glyph: 8, + }; + let scene = unavailable_scene(&lines, geometry); + let texts: Vec<&str> = scene.texts().collect(); + assert_eq!(texts, ["Wi-Fi", "first", "second", "Esc: back"]); + let column = (1280 - 440) / 2..(1280 - 440) / 2 + 440; + for draw in &scene.draws { + if let Draw::Text { x, text, .. } = draw + && text != "Esc: back" + { + assert!( + column.contains(x) && x + 8 * text.len() <= column.end, + "{text}" + ); + } + } +} + +/// Testers with a Wi-Fi chip the driver starts missed that a network is +/// chosen with W: with none set up the menu and the log both say so. +#[test] +fn with_no_network_set_up_the_line_and_the_log_say_to_press_w() { + assert_eq!( + status_line(None, None, false), + "Wi-Fi: press W to choose a network" + ); + let hint = hint_line(None, false).unwrap(); + assert_eq!( + hint, + "CHOICE Wi-Fi: no network is set up; press W in this menu to choose one, or Wi-Fi \ + stays off\n" + ); + assert_eq!(hint_line(Some("home"), false), None); + assert_eq!(hint_line(None, true), None); } // The rows. @@ -560,7 +604,7 @@ fn no_other_screen_draws_the_password() { }; assert_eq!(save.password, b"password"); assert!(!has_text(&page.scene(SCREEN), "password")); - let status = status_line(Some("home"), Some("cafe"), true).unwrap_or_default(); + let status = status_line(Some("home"), Some("cafe"), true); assert!(!status.contains("password")); } diff --git a/crates/stela-boot-core/src/wifi_page/tests/render.rs b/crates/stela-boot-core/src/wifi_page/tests/render.rs index 71277afef5..1918ad13b9 100644 --- a/crates/stela-boot-core/src/wifi_page/tests/render.rs +++ b/crates/stela-boot-core/src/wifi_page/tests/render.rs @@ -177,7 +177,7 @@ fn main_menu() -> Painter { painter.text(left + 20, y + 8, name, 1, rgb(Tone::Text)); y += 36; } - let line = status_line(Some("GarvitRoom_5G"), None, true).unwrap_or_default(); + let line = status_line(Some("GarvitRoom_5G"), None, true); painter.centred(640, 720 - 24, &line, rgb(Tone::Dim)); painter.centred(640, 720 - 56, "macOS Tahoe in 5", rgb(Tone::Dim)); painter diff --git a/crates/stela-boot/Cargo.lock b/crates/stela-boot/Cargo.lock index 54e1dff0bd..fffe7efe9a 100644 --- a/crates/stela-boot/Cargo.lock +++ b/crates/stela-boot/Cargo.lock @@ -963,7 +963,7 @@ checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" [[package]] name = "stela-boot" -version = "0.6.0" +version = "0.6.1" dependencies = [ "serde_json", "stela-boot-core", @@ -985,7 +985,7 @@ dependencies = [ [[package]] name = "stela-boot-core" -version = "0.6.0" +version = "0.6.1" dependencies = [ "serde_json", "stela-compiler", @@ -1004,7 +1004,7 @@ dependencies = [ [[package]] name = "stela-c-build" -version = "0.6.0" +version = "0.6.1" dependencies = [ "cc", "libc", @@ -1014,7 +1014,7 @@ dependencies = [ [[package]] name = "stela-compiler" -version = "0.6.0" +version = "0.6.1" dependencies = [ "rustc_apfloat", "serde", @@ -1023,14 +1023,14 @@ dependencies = [ [[package]] name = "stela-contracts" -version = "0.6.0" +version = "0.6.1" dependencies = [ "serde", ] [[package]] name = "stela-crypto" -version = "0.6.0" +version = "0.6.1" dependencies = [ "aes 0.8.4", "chacha20", @@ -1043,7 +1043,7 @@ dependencies = [ [[package]] name = "stela-driver-audio" -version = "0.6.0" +version = "0.6.1" dependencies = [ "stela-driver-base", "stela-driver-core", @@ -1051,7 +1051,7 @@ dependencies = [ [[package]] name = "stela-driver-base" -version = "0.6.0" +version = "0.6.1" dependencies = [ "cc", "stela-c-build", @@ -1062,7 +1062,7 @@ dependencies = [ [[package]] name = "stela-driver-core" -version = "0.6.0" +version = "0.6.1" dependencies = [ "stela-contracts", "stela-crypto", @@ -1070,7 +1070,7 @@ dependencies = [ [[package]] name = "stela-driver-gpu" -version = "0.6.0" +version = "0.6.1" dependencies = [ "ash", "cc", @@ -1086,7 +1086,7 @@ dependencies = [ [[package]] name = "stela-driver-net" -version = "0.6.0" +version = "0.6.1" dependencies = [ "hmac", "p256", @@ -1100,7 +1100,7 @@ dependencies = [ [[package]] name = "stela-driver-storage" -version = "0.6.0" +version = "0.6.1" dependencies = [ "stela-driver-base", "stela-driver-core", @@ -1108,7 +1108,7 @@ dependencies = [ [[package]] name = "stela-drivers" -version = "0.6.0" +version = "0.6.1" dependencies = [ "stela-contracts", "stela-crypto", @@ -1122,7 +1122,7 @@ dependencies = [ [[package]] name = "stela-engine" -version = "0.6.0" +version = "0.6.1" dependencies = [ "hex", "libc", @@ -1139,14 +1139,14 @@ dependencies = [ [[package]] name = "stela-fingerprint" -version = "0.6.0" +version = "0.6.1" dependencies = [ "sha2", ] [[package]] name = "stela-formats" -version = "0.6.0" +version = "0.6.1" dependencies = [ "crypto-bigint", "hex", @@ -1162,7 +1162,7 @@ dependencies = [ [[package]] name = "stela-linux" -version = "0.6.0" +version = "0.6.1" dependencies = [ "cc", "stela-c-build", @@ -1174,7 +1174,7 @@ dependencies = [ [[package]] name = "stela-loader" -version = "0.6.0" +version = "0.6.1" dependencies = [ "hex", "object", @@ -1314,7 +1314,7 @@ dependencies = [ [[package]] name = "stela-runtime" -version = "0.6.0" +version = "0.6.1" dependencies = [ "hex", "httparse", @@ -1337,7 +1337,7 @@ dependencies = [ [[package]] name = "stela-soc" -version = "0.6.0" +version = "0.6.1" dependencies = [ "hex", "hmac", @@ -1356,7 +1356,7 @@ dependencies = [ [[package]] name = "stela-soc-data" -version = "0.6.0" +version = "0.6.1" dependencies = [ "stela-contracts", "stela-crypto", @@ -1365,7 +1365,7 @@ dependencies = [ [[package]] name = "stela-tls" -version = "0.6.0" +version = "0.6.1" dependencies = [ "aes 0.9.3", "aes-gcm", diff --git a/crates/stela-boot/Cargo.toml b/crates/stela-boot/Cargo.toml index 5b2b38d90d..80aba9ede3 100644 --- a/crates/stela-boot/Cargo.toml +++ b/crates/stela-boot/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "stela-boot" -version = "0.6.0" +version = "0.6.1" edition = "2024" license = "GPL-2.0-or-later AND GPL-2.0-only AND BSD-2-Clause" description = "stela.efi: the UEFI application that boots macOS on a PC through Stela" diff --git a/crates/stela-boot/src/choice.rs b/crates/stela-boot/src/choice.rs index 406fea1f20..c4e0ddab63 100644 --- a/crates/stela-boot/src/choice.rs +++ b/crates/stela-boot/src/choice.rs @@ -31,7 +31,7 @@ use core::time::Duration; use stela_boot_core::{ chosen_disk::{Adopted, adopt}, options::{System, WIFI_PREFER, wifi_word}, - wifi_page, + wifi_hardware, wifi_page, }; use stela_contracts::refuse; use stela_loader::mount_interface::{ @@ -313,9 +313,11 @@ struct Menu<'a> { /// not `--wifi`'s ([`with_prefer`]). wifi_prefer: Option, /// The PC may have a Wi-Fi chip the driver starts - /// ([`crate::wifi_menu::offered`]); without one the Wi-Fi line is not - /// shown and `W` opens nothing. + /// ([`crate::wifi_menu::hardware`]); without one `W` opens a page that + /// says why instead of the Wi-Fi page. wifi_offered: bool, + /// What the census found of the PC's Wi-Fi, once the menu read it. + wifi_hardware: Option, } /// What the menu was left with. @@ -324,6 +326,8 @@ enum Pick { Item(usize), /// `W`: the Wi-Fi page. Wifi, + /// `W` without a Wi-Fi chip the driver starts: the page saying why. + Unavailable(Vec), } impl<'a> Menu<'a> { @@ -460,6 +464,7 @@ impl<'a> Menu<'a> { wifi_saved: false, wifi_prefer: None, wifi_offered: true, + wifi_hardware: None, } } @@ -500,14 +505,19 @@ impl<'a> Menu<'a> { } // The network this boot joins first and the Wi-Fi page's key, on // the bottom line. - if self.wifi_offered - && let Some(line) = wifi_page::status_line( + if self.wifi_offered { + let line = wifi_page::status_line( self.wifi.as_deref(), self.wifi_prefer.as_deref(), self.wifi_saved, - ) - { + ); canvas.text_centred(width / 2, height.saturating_sub(24), &line, 1, ui::DIM); + } else if let Some(line) = self + .wifi_hardware + .as_ref() + .and_then(wifi_hardware::Hardware::unsupported_line) + { + canvas.text_centred(width / 2, height.saturating_sub(24), line, 1, ui::DIM); } let (status, colour) = match (self.notice, self.countdown, self.held) { (Some(notice), _, _) => (String::from(notice), ui::ORANGE), @@ -549,11 +559,18 @@ impl<'a> Menu<'a> { if let Some(chosen) = chosen { return Some(Pick::Item(chosen)); } - if matches!(key, 'w' | 'W') - && self.wifi_offered - && (self.wifi.is_some() || self.wifi_saved) - { - return Some(Pick::Wifi); + // The page saves a network on a USB with none yet too. + if matches!(key, 'w' | 'W') { + if self.wifi_offered { + return Some(Pick::Wifi); + } + if let Some(lines) = self + .wifi_hardware + .as_ref() + .and_then(wifi_hardware::Hardware::unavailable) + { + return Some(Pick::Unavailable(lines)); + } } } Wait::Key(_) | Wait::Nothing => {} @@ -639,10 +656,21 @@ fn asked() -> bool { /// input to choose with. fn menu(volume: &mut FileSystem, choices: &Choices, mut menu: Menu<'_>) -> Option { menu.wifi_saved = crate::wifi_menu::saved(volume); - menu.wifi_offered = crate::wifi_menu::offered(); + let hardware = crate::wifi_menu::hardware(); + menu.wifi_offered = hardware.offered(); + menu.wifi_hardware = Some(hardware); + if menu.wifi_offered + && let Some(hint) = wifi_page::hint_line(menu.wifi.as_deref(), menu.wifi_saved) + { + output::arguments(format_args!("{hint}")); + } loop { let index = match menu.run()? { Pick::Item(index) => index, + Pick::Unavailable(lines) => { + crate::wifi_menu::unavailable(&lines); + continue; + } Pick::Wifi => { let configured = menu.wifi.clone(); let chosen = crate::wifi_menu::run( diff --git a/crates/stela-boot/src/engine.rs b/crates/stela-boot/src/engine.rs index 23342a06f6..09ff92457f 100644 --- a/crates/stela-boot/src/engine.rs +++ b/crates/stela-boot/src/engine.rs @@ -925,7 +925,8 @@ fn show_reset(otherwise: &str, action: &str, hold: u64) { if output::usb_log_kept() { crate::status::info( "Its full log is on this USB: on any computer with stambha, plug in this USB and run \ - `stambha log`, which saves it to log.txt.", + `stambha log`, which saves it to log.txt, or open the file \\EFI\\stela\\boot.log on \ + the USB.", ); } crate::status::countdown(action, hold); diff --git a/crates/stela-boot/src/engine/storage.rs b/crates/stela-boot/src/engine/storage.rs index 8a170fcc92..cb27a3d7e2 100644 --- a/crates/stela-boot/src/engine/storage.rs +++ b/crates/stela-boot/src/engine/storage.rs @@ -2541,20 +2541,22 @@ fn check(plan: &Plan, disk: &mut dyn BlockDevice, name: &str) -> crate::Refusal "RESULT PASS: the plan is safe to install. Nothing was written: no partition \ table, no zeroes, no TRIM, no BootNext", ); - crate::status::done("PASS, nothing was written"); + crate::status::done("PASS. Nothing was installed: this was only a check"); refuse!( - "Install check PASSED on {name}: nothing was written. Turn the PC off; to \ - install, choose Install macOS again and then Install", + "Install check PASSED on {name}. Nothing was installed: this was only a check. \ + Choose Install macOS to install: turn the PC off, start Stambha again, choose \ + Install macOS and then Install", name ) } Err(error) => { say(&format!("FAIL {error}")); say("RESULT FAIL: do not install. Nothing was written"); - crate::status::fail("FAIL, nothing was written"); + crate::status::fail("FAIL. Nothing was installed: this was only a check"); refuse!( - "Install check FAILED on {name}: {error}. Nothing was written. Do not install; \ - keep the log", + "Install check FAILED on {name}: {error}. Nothing was installed: this was only a \ + check. Do not install; keep the log (`stambha log`, or \\EFI\\stela\\boot.log on \ + the stick)", name, %error ) diff --git a/crates/stela-boot/src/installer.rs b/crates/stela-boot/src/installer.rs index 62298ee24f..091ee7fdfc 100644 --- a/crates/stela-boot/src/installer.rs +++ b/crates/stela-boot/src/installer.rs @@ -817,7 +817,7 @@ impl Picker { let keys: &[(&str, &str)] = match self.page { Page::Partitions => &[("Enter", "Install in free space"), ("Esc", "Back")], Page::Confirm => &[ - ("Left", "Check only"), + ("Left", "Install check (dry run)"), ("Right", "Install"), ("Enter", "Choose"), ("Esc", "Back"), @@ -1174,7 +1174,7 @@ impl Picker { "Back", self.focus == Focus::Back, ); - let check = "Check only"; + let check = "Install check (dry run)"; let check_width = canvas.text_width(check, 1) + 48; Self::button( canvas, @@ -1187,7 +1187,7 @@ impl Picker { canvas.text( layout.left, buttons + 56, - "Check only reads the disk with Stambha's driver and writes nothing", + "A dry run, changes nothing: it reads the disk and installs nothing", 1, ui::DIM, ); diff --git a/crates/stela-boot/src/native_mmio/shared.rs b/crates/stela-boot/src/native_mmio/shared.rs index d9f8345b0a..5145037313 100644 --- a/crates/stela-boot/src/native_mmio/shared.rs +++ b/crates/stela-boot/src/native_mmio/shared.rs @@ -814,8 +814,8 @@ impl Source { } crate::output::arguments(format_args!( "HOST PCI BAR at {address:#x} ({bytes:#x} bytes) on segment {segment} lies in \ - no memory window its ACPI host bridges declare (windows:{listed}); Stela \ - assigns no BARs, so it stays unmapped\n" + no memory window the firmware's root bridges report (windows:{listed}); \ + Stambha assigns no BARs, so it stays unmapped\n" )); return Err(Error::OutsideResource); }; diff --git a/crates/stela-boot/src/output.rs b/crates/stela-boot/src/output.rs index 6ebff1c5bb..ef74dff773 100644 --- a/crates/stela-boot/src/output.rs +++ b/crates/stela-boot/src/output.rs @@ -1424,8 +1424,9 @@ fn stopped(message: &str, next: &dyn Fn() -> &'static str) { /// What a stopped boot tells the user to do next: where its log is, and how /// to read it on any computer with stela. pub const STOPPED: &str = "Stambha stopped. Its log is on this USB: on any computer with stambha, \ - plug in this USB and run `stambha log`, which saves it to log.txt; include that file in a \ - report. Turn the PC off to try again; Ctrl+Alt+Delete on a laptop's own keyboard restarts it."; + plug in this USB and run `stambha log`, which saves it to log.txt, or open the file \ + \\EFI\\stela\\boot.log on the USB; include it in a report. Turn the PC off to try again; \ + Ctrl+Alt+Delete on a laptop's own keyboard restarts it."; /// What a stop whose last lines the USB's log does not hold, as one before /// the engine writes the log again, tells the user once the PC's firmware @@ -1434,7 +1435,8 @@ pub const STOPPED: &str = "Stambha stopped. Its log is on this USB: on any compu pub const STOPPED_RECORDED: &str = "Stambha stopped before it could write this part of its log \ to the USB. This PC keeps its last lines: start Stambha on this PC once more, which copies them \ into the log on this USB. Then, on any computer with stambha, plug in this USB and run `stambha \ - log`, which saves it to log.txt; include that file in a report. Turn the PC off to try again; \ + log`, which saves it to log.txt, or open the file \\EFI\\stela\\boot.log on the USB; include it \ + in a report. Turn the PC off to try again; \ Ctrl+Alt+Delete on a laptop's own keyboard restarts it."; /// What such a stop tells the user when the firmware did not take the diff --git a/crates/stela-boot/src/wifi_menu.rs b/crates/stela-boot/src/wifi_menu.rs index 06edbfef56..f9ca152363 100644 --- a/crates/stela-boot/src/wifi_menu.rs +++ b/crates/stela-boot/src/wifi_menu.rs @@ -27,10 +27,10 @@ use uefi::{ fs::{FileSystem, PathBuf}, }; -/// Whether the startup menu offers Wi-Fi on this PC, from the firmware's PCI -/// census before ExitBootServices (`stela_boot_core::wifi_hardware`); one -/// line says which way it decided. -pub(crate) fn offered() -> bool { +/// What the startup menu makes of this PC's Wi-Fi, from the firmware's PCI +/// census before ExitBootServices (`stela_boot_core::wifi_hardware`): the +/// Wi-Fi page, or a page saying why there is none. One line says which. +pub(crate) fn hardware() -> wifi_hardware::Hardware { let hardware = match crate::pci_io::capture() { Ok(census) => { let functions: Vec<_> = census @@ -48,7 +48,28 @@ pub(crate) fn offered() -> bool { Err(error) => wifi_hardware::decide(Err(&alloc::format!("{error}"))), }; output::arguments(format_args!("{}", hardware.line())); - hardware.offered() + hardware +} + +/// The page `W` opens where the menu offers no Wi-Fi page: `lines` +/// (`wifi_hardware::Hardware::unavailable`) until a key is pressed. +pub(crate) fn unavailable(lines: &[String]) { + let Some((screen, font)) = Framebuffer::from_firmware().zip(font::console()) else { + return; + }; + let mut canvas = Canvas::new(screen, font); + output::arguments(format_args!( + "CHOICE Wi-Fi page: no Wi-Fi chip the driver starts, so it says why\n" + )); + let scene = wifi_page::unavailable_scene(lines, geometry(&canvas)); + paint(&mut canvas, &scene); + drop(scene); + loop { + match key(None) { + Wait::Key(_) | Wait::NoInput => return, + Wait::Nothing | Wait::Timeout => {} + } + } } /// The page until a network is chosen, the one `--wifi` names being diff --git a/crates/stela-cli/src/lib.rs b/crates/stela-cli/src/lib.rs index d1ba7b3857..26d05b7296 100644 --- a/crates/stela-cli/src/lib.rs +++ b/crates/stela-cli/src/lib.rs @@ -38,7 +38,10 @@ fn examples() -> String { stambha Choose what to do, step by step stambha update Update the plugged-in stick stambha log Save the boot logs to log.txt - stambha create {disk} --confirm-disk 64.0GB --installer offline" + stambha create {disk} --confirm-disk 64.0GB --installer offline + +The boot log: run `stambha log` on any computer with the stick plugged in, +or open the file \\EFI\\stela\\boot.log on the stick." ) } diff --git a/crates/stela-driver-net/src/e1000e/pch/cold.rs b/crates/stela-driver-net/src/e1000e/pch/cold.rs index 005a154bb3..4f463e7493 100644 --- a/crates/stela-driver-net/src/e1000e/pch/cold.rs +++ b/crates/stela-driver-net/src/e1000e/pch/cold.rs @@ -121,6 +121,14 @@ pub enum Error { Dma(crate::block::BlockError), Stopped, Poisoned, + /// A step that failed after the PHY's forced ULP exit had failed, + /// through the ME (`me`) or a LANPHYPC toggle (`lanphypc`): both + /// causes, the exit's first. + AfterUlpExit { + how: &'static str, + exit: alloc::boxed::Box, + then: alloc::boxed::Box, + }, } impl From for Error { @@ -189,6 +197,10 @@ impl core::fmt::Display for Error { Self::Dma(error) => write!(f, "its DMA memory failed ({error})"), Self::Stopped => f.write_str("it is stopped"), Self::Poisoned => f.write_str("an earlier failure left it unusable"), + Self::AfterUlpExit { how, exit, then } => write!( + f, + "{then}, after the PHY did not leave its ultra-low-power state ({how}: {exit})" + ), } } } diff --git a/crates/stela-driver-net/src/e1000e/pch/cold/spt.rs b/crates/stela-driver-net/src/e1000e/pch/cold/spt.rs index 1ff1d2ed1b..6db23ea499 100644 --- a/crates/stela-driver-net/src/e1000e/pch/cold/spt.rs +++ b/crates/stela-driver-net/src/e1000e/pch/cold/spt.rs @@ -155,7 +155,21 @@ impl Controller { } Ok(()) } + /// [`Self::start_i219`], with a failed ULP exit named beside the step + /// that later failed: the exit's own cause is otherwise lost with the + /// controller, and it is the first thing that went wrong. pub(super) fn initialize_i219(&mut self) -> Result<(), Error> { + let result = self.start_i219(); + match (result, &self.ulp_exit) { + (Err(then), Some((how, Some(exit)))) if then != *exit => Err(Error::AfterUlpExit { + how, + exit: alloc::boxed::Box::new(exit.clone()), + then: alloc::boxed::Box::new(then), + }), + (result, _) => result, + } + } + fn start_i219(&mut self) -> Result<(), Error> { self.inherited_ring_check()?; self.validate_nvm()?; self.station = self.nvm.station()?; @@ -175,7 +189,26 @@ impl Controller { self.spt_ulp_exit() }; self.ulp_exit_failed = exit.is_err(); - self.ulp_exit = Some((if managed { "me" } else { "lanphypc" }, exit.err())); + self.ulp_exit = Some((if managed { "me" } else { "lanphypc" }, exit.clone().err())); + // A PHY that does not answer leaves the exit failed and the epoch + // usable. A transport fault (a refused or all-ones access, the + // semaphore, the delay clock) ends the epoch: that fault is the + // cause, not the `Poisoned` the next PHY access would report. + if let Err(error) = exit { + if self.phy.is_poisoned() { + return Err(error); + } + // `e1000_disable_ulp_lpt_lp`'s `release:` path: a forced exit + // resets the PHY and waits 50 ms whether or not it worked, so the + // access checks below meet a PHY in a known state. A reset the + // ME blocks is left out, as `e1000e_phy_hw_reset_generic` does. + if !managed { + if self.reset_phy()? { + self.configuration_done(true)?; + } + self.phy.wait_minimum(50_000)?; + } + } self.recover_phy_access(managed)?; self.identity = self.phy.identify()?; // The donor releases SWFLAG before this hardware PHY reset. No PHY @@ -233,9 +266,11 @@ impl Controller { /// power cycle to be reported done and 30 ms more and goes on either /// way, as `e1000_toggle_lanphypc_pch_lpt` does, then SMBus unforced in /// the PHY and the MAC, K1 back on and the PHY's ULP configuration - /// cleared. + /// cleared. A PHY that does not answer its MDIO cycles fails the exit + /// with the semaphore released and the epoch kept, as Linux gives up + /// at `release:` and goes on; only a transport fault poisons it. fn spt_ulp_exit(&mut self) -> Result<(), Error> { - let cycle_done = self.phy.transaction(|p| { + let (cycle_done, unanswered) = self.phy.transaction(|p| { let value = p.read_mac(super::FEXTNVM3)?; p.write_mac( super::FEXTNVM3, @@ -257,43 +292,77 @@ impl Controller { } } p.wait_minimum(30_000)?; - p.retry_enabled = false; - // A mode-switch MDIC error is a source-defined transition, not an - // access/removal fault. Only the exact CV_SMB_CTRL response may - // take this path; final readback must prove PCIe mode. - p.page(SMB_CONTROL.page)?; - let mut word = match p.mdic(1, SMB_CONTROL.index, None) { - Ok(value) => value, - Err(error) if smbus_read_unavailable(error) => { - let value = p.read_mac(CTRL_EXT)?; - p.write_mac(CTRL_EXT, value | FORCE_SMBUS)?; - p.wait_minimum(50_000)?; - p.page(SMB_CONTROL.page)?; - p.mdic(1, SMB_CONTROL.index, None)? - } - Err(error) => return Err(error), - }; - let switching = word & 1 != 0; - word &= !1; - match p.mdic(1, SMB_CONTROL.index, Some(word)) { - Ok(_) => {} - Err(error) if switching && smbus_response_error(error) => {} - Err(error) => return Err(error), - } + let exit = p.spt_leave_smbus_and_ulp(); p.retry_enabled = true; - let value = p.read_mac(CTRL_EXT)?; - p.write_mac(CTRL_EXT, value & !FORCE_SMBUS)?; - let value = p.access(PM_CONTROL, None)?; - p.access(PM_CONTROL, Some(value | K1_ENABLE))?; - let value = p.access(ULP_CONFIG, None)? & !ULP_CLEAR; - p.access(ULP_CONFIG, Some(value))?; - p.access(ULP_CONFIG, Some(value | ULP_START))?; - let value = p.read_mac(FEXTNVM7)?; - p.write_mac(FEXTNVM7, value & !DISABLE_SMB_PERST)?; - Ok(done) + match exit { + Ok(()) => Ok((done, None)), + Err(fault @ (Fault::MdicTimeout | Fault::MdicResponse(_))) => { + Ok((done, Some(fault))) + } + Err(fault) => Err(fault), + } })?; self.lanphypc_done = Some(cycle_done); - Ok(()) + match unanswered { + None => Ok(()), + Some(fault) => Err(fault.into()), + } + } +} + +impl Phy { + /// `e1000_disable_ulp_lpt_lp` after its LANPHYPC toggle, under the + /// semaphore: SMBus unforced in the PHY and the MAC, K1 back on, the + /// ULP configuration cleared and committed, SMBus release on PERST# + /// enabled again. The CV_SMB_CTRL cycles run without MDIC retries. + fn spt_leave_smbus_and_ulp(&mut self) -> Result<(), Fault> { + self.retry_enabled = false; + // A mode-switch MDIC error is a source-defined transition, not an + // access/removal fault. Only the exact CV_SMB_CTRL response may + // take this path; final readback must prove PCIe mode. + let mut word = match self.spt_smb_control() { + Ok(value) => value, + // "The MAC might be in PCIe mode, so temporarily force SMBus mode + // in order to access the PHY." + Err((true, _)) => { + let value = self.read_mac(CTRL_EXT)?; + self.write_mac(CTRL_EXT, value | FORCE_SMBUS)?; + self.wait_minimum(50_000)?; + self.spt_smb_control().map_err(|(_, error)| error)? + } + Err((false, error)) => return Err(error), + }; + let switching = word & 1 != 0; + word &= !1; + match self.mdic(1, SMB_CONTROL.index, Some(word)) { + Ok(_) => {} + Err(error) if switching && smbus_response_error(error) => {} + Err(error) => return Err(error), + } + self.retry_enabled = true; + let value = self.read_mac(CTRL_EXT)?; + self.write_mac(CTRL_EXT, value & !FORCE_SMBUS)?; + let value = self.access(PM_CONTROL, None)?; + self.access(PM_CONTROL, Some(value | K1_ENABLE))?; + let value = self.access(ULP_CONFIG, None)? & !ULP_CLEAR; + self.access(ULP_CONFIG, Some(value))?; + self.access(ULP_CONFIG, Some(value | ULP_START))?; + let value = self.read_mac(FEXTNVM7)?; + self.write_mac(FEXTNVM7, value & !DISABLE_SMB_PERST) + } + /// `e1000_read_phy_reg_hv_locked(CV_SMB_CTRL)`: as + /// `__e1000_read_phy_reg_hv`, the page select is part of the read, so + /// a PHY the MAC cannot reach (the PHY in SMBus mode, the MAC in PCIe + /// mode) fails that first cycle, and Linux's forced-SMBus retry is for + /// it as much as for the read. The read, or the failure and whether + /// the retry is for it. + fn spt_smb_control(&mut self) -> Result { + if let Err(error) = self.page(SMB_CONTROL.page) { + let unreachable = matches!(error, Fault::MdicTimeout | Fault::MdicResponse(_)); + return Err((unreachable, error)); + } + self.mdic(1, SMB_CONTROL.index, None) + .map_err(|error| (smbus_read_unavailable(error), error)) } } fn smbus_response_error(error: Fault) -> bool { diff --git a/crates/stela-driver-net/src/e1000e/pch/cold/spt/tests.rs b/crates/stela-driver-net/src/e1000e/pch/cold/spt/tests.rs index e12c36e2f8..fd4fb6e3d6 100644 --- a/crates/stela-driver-net/src/e1000e/pch/cold/spt/tests.rs +++ b/crates/stela-driver-net/src/e1000e/pch/cold/spt/tests.rs @@ -363,9 +363,13 @@ fn every_spt_cold_access_failure_keeps_owner_and_prevents_packet_dma() { for at in 0..count { let (state, released, io, timer) = fixture_spt(); state.borrow_mut().fail_at = Some(at); + let error = start_spt(0x1570, io, timer).err(); + assert!(error.is_some(), "lost SPT cold access{at}"); + // The fault itself is named, never the `Poisoned` of an access + // after it (the forced ULP exit used to hide its own fault so). assert!( - start_spt(0x1570, io, timer).is_err(), - "lost SPT cold access{at}" + !matches!(&error, Some(Error::Phy(e)) if e.primary == Fault::Poisoned), + "SPT cold access{at} reported {error:?}" ); assert_eq!(released.load(Ordering::SeqCst), 0, "released SPT owner{at}"); assert!(!state.borrow().operations.iter().any(|o| o[0] == 1 @@ -513,3 +517,140 @@ fn an_i219_the_me_manages_leaves_ulp_through_the_me() { drop(controller); assert_eq!(released.load(Ordering::SeqCst), 1); } + +fn lanphypc_toggles(state: &Rc>) -> usize { + state + .borrow() + .operations + .iter() + .filter(|o| o[0] == 1 && o[1] == super::super::CTRL && o[2] & LANPHYPC_OVERRIDE != 0) + .count() +} +/// The Raptor Lake I219-V (0dc6, `board_pch_adp`) a tester's PC has, and +/// the initial SPT cohort. +const I219_DEVICES: [u16; 2] = [0x0dc6, 0x156f]; +fn start_device(device: u16, io: Io, timer: Timer) -> Result, Error> { + // SAFETY: one synchronous modeled Function/config/PHY/flash. + unsafe { Controller::new_i219(device, io, timer) } +} + +/// `e1000_disable_ulp_lpt_lp`: a PHY still in SMBus mode after the toggle, +/// with the MAC in PCIe mode, answers no MDIO cycle, so the CV_SMB_CTRL +/// read's page select fails first. Linux's read includes that select and +/// retries with the MAC forced to SMBus; the exit used to give up at the +/// select, poison the PHY epoch and report "an earlier PHY failure left it +/// unusable" for the access check after it. +#[test] +fn a_phy_left_in_smbus_mode_is_reached_through_forced_smbus_from_the_page_select() { + for device in I219_DEVICES { + let (state, released, io, timer) = fixture_spt(); + { + let mut m = state.borrow_mut(); + m.smbus_only = true; + m.phy.insert((1, 769, 23), 0x7f01); + } + let controller = start_device(device, io, timer).unwrap(); + assert!(!controller.ulp_exit_failed(), "{device:04x}"); + assert!(!controller.is_poisoned()); + { + let m = state.borrow(); + assert_eq!(m.phy[&(1, 769, 23)] & 1, 0); + assert_eq!(m.mac[&CTRL_EXT] & FORCE_SMBUS, 0); + assert_eq!(m.phy[&(1, 779, 16)] & ULP_CLEAR, 0); + assert!( + m.operations + .iter() + .any(|o| o[0] == 1 && o[1] == CTRL_EXT && o[2] & FORCE_SMBUS != 0), + "the exit never forced the MAC to SMBus" + ); + } + assert_eq!(lanphypc_toggles(&state), 1); + drop(controller); + assert_eq!(released.load(Ordering::SeqCst), 1); + } +} + +/// `e1000_init_phy_workarounds_pchlan`: a ULP exit whose PHY does not +/// answer is logged and the start goes on. Linux's exit releases the +/// semaphore, resets the PHY and waits 50 ms (`release:`), and the access +/// checks after it wake the PHY with another LANPHYPC toggle. A PHY that +/// does not answer is no transport fault: the epoch stays usable, where it +/// was poisoned and the start refused. +#[test] +fn a_phy_still_asleep_after_the_ulp_exit_is_woken_by_the_access_checks() { + for device in I219_DEVICES { + let (state, released, io, timer) = fixture_spt(); + { + let mut m = state.borrow_mut(); + m.phy_asleep = true; + m.toggles_ignored = 1; + } + let mut controller = start_device(device, io, timer).unwrap(); + assert!(controller.ulp_exit_failed(), "{device:04x}"); + assert!(!controller.is_poisoned()); + assert_eq!(controller.identity().id, 0x0154_00a0); + assert_eq!(lanphypc_toggles(&state), 2); + { + let m = state.borrow(); + let toggles: alloc::vec::Vec = m + .operations + .iter() + .enumerate() + .filter(|(_, o)| { + o[0] == 1 && o[1] == super::super::CTRL && o[2] & LANPHYPC_OVERRIDE != 0 + }) + .map(|(at, _)| at) + .collect(); + assert!( + m.operations[toggles[0]..toggles[1]] + .iter() + .any(|o| o[0] == 1 + && o[1] == super::super::CTRL + && o[2] & super::super::PHY_RESET != 0), + "no PHY reset after the failed exit, before the access checks" + ); + assert_eq!(m.mac[&CTRL_EXT] & FORCE_SMBUS, 0); + assert_eq!( + m.mac[&super::super::super::EXTCNF_CTRL] & super::super::super::SWFLAG, + 0 + ); + } + let line = controller.state(); + assert!(line.contains(" ulp_exit=lanphypc:failed("), "{line}"); + drop(controller); + assert_eq!(released.load(Ordering::SeqCst), 1); + } +} + +/// A start that fails after a failed ULP exit names both, the exit first +/// cause, where only the last step's reason reached the log. +#[test] +fn a_start_failing_after_a_failed_ulp_exit_names_the_exit_too() { + let (state, released, io, timer) = fixture_spt(); + { + let mut m = state.borrow_mut(); + m.phy_asleep = true; + m.toggles_ignored = 1; + // The ME blocks the PHY reset and so the LANPHYPC wake. + m.mac.insert(super::super::super::FWSM, 0); + } + let error = start_device(0x0dc6, io, timer).err().unwrap(); + let Error::AfterUlpExit { how, exit, then } = &error else { + panic!("{error:?}"); + }; + assert_eq!(*how, "lanphypc"); + assert!( + matches!(**exit, Error::Phy(e) if e.primary == Fault::MdicTimeout), + "{exit:?}" + ); + assert_eq!(**then, Error::RecoveryBlocked); + let text = alloc::format!("{error}"); + assert!( + text.starts_with("the PHY does not answer, and the Intel ME blocks") + && text.contains("after the PHY did not leave its ultra-low-power state (lanphypc: ") + && text.contains("MDIO timeout"), + "{text}" + ); + assert_eq!(lanphypc_toggles(&state), 1); + assert_eq!(released.load(Ordering::SeqCst), 0); +} diff --git a/crates/stela-driver-net/src/e1000e/pch/cold/tests.rs b/crates/stela-driver-net/src/e1000e/pch/cold/tests.rs index 4ef2440b16..c930ee5d54 100644 --- a/crates/stela-driver-net/src/e1000e/pch/cold/tests.rs +++ b/crates/stela-driver-net/src/e1000e/pch/cold/tests.rs @@ -24,6 +24,12 @@ pub(super) struct Model { pub(super) phy_asleep: bool, /// An Intel ME that never finishes taking the PHY out of ULP. pub(super) me_stuck: bool, + /// SPT and later: this many LANPHYPC toggles leave a sleeping PHY + /// asleep, as one left by the last OS can stay after the first. + pub(super) toggles_ignored: usize, + /// SPT and later: a PHY in SMBus mode, reachable only while the MAC + /// forces SMBus too, until its CV_SMB_CTRL force bit is cleared. + pub(super) smbus_only: bool, pub(super) flush_after_tx: bool, pub(super) flush_after_rx: bool, pub(super) phy: BTreeMap<(u8, u16, u16), u16>, @@ -93,6 +99,8 @@ impl Model { ulp_stuck: false, phy_asleep: false, me_stuck: false, + toggles_ignored: 0, + smbus_only: false, flush_after_tx: false, flush_after_rx: false, phy: BTreeMap::from([((2, 0, 2), 0x154), ((2, 0, 3), 0x93)]), @@ -245,7 +253,11 @@ unsafe impl Registers for Io { m.mac.insert(at, value); } else if m.spt && at == CTRL && previous & (1 << 16) != 0 && value & (1 << 16) == 0 { m.power_pending = true; - m.phy_asleep = false; + if m.toggles_ignored > 0 { + m.toggles_ignored -= 1; + } else { + m.phy_asleep = false; + } if m.smb_hidden_after_power { m.smb_hidden = true; let value = m.phy.get(&(1, 769, 23)).copied().unwrap_or(0) | 1; @@ -266,7 +278,10 @@ unsafe impl Registers for Io { m.kmrn.insert(index, value as u16); m.mac.insert(at, value); } - } else if at == super::super::MDIC && m.phy_asleep { + } else if at == super::super::MDIC + && (m.phy_asleep + || (m.smbus_only && m.mac.get(&CTRL_EXT).copied().unwrap_or(0) & FORCE_SMBUS == 0)) + { m.mac.insert(at, value & !super::super::MDIC_READY); } else if at == super::super::MDIC { let index = ((value >> 16) & 31) as u16; @@ -275,6 +290,9 @@ unsafe impl Registers for Io { let mut mdi_error = false; let data = if value & super::super::MDIC_WRITE != 0 { let switching = smb && m.phy_load(address, index) & 1 != 0 && value & 1 == 0; + if smb && value & 1 == 0 { + m.smbus_only = false; + } m.phy_store(address, index, value as u16); if switching { m.smb_hidden = false; diff --git a/crates/stela-driver-net/src/wifi/intel/boot.rs b/crates/stela-driver-net/src/wifi/intel/boot.rs index 26c57250a3..c3e2626373 100644 --- a/crates/stela-driver-net/src/wifi/intel/boot.rs +++ b/crates/stela-driver-net/src/wifi/intel/boot.rs @@ -109,6 +109,17 @@ pub trait FunctionOwner { /// [`BootIo::reset_function`], the claim and BAR mapping kept throughout. fn reset(&self) -> Result; } +/// The bytes of BAR0 the boot reaches: all 16 KiB, which hold the MSI-X +/// registers at 0x2000 (`CSR_MSIX_BASE`) above the CSRs' first 8 KiB. +pub const WINDOW: u32 = 16384; +/// Whether an access of `width` bytes at `register` is aligned and inside +/// [`WINDOW`]. +pub fn reach(register: u32, width: u32) -> Result { + match register.checked_add(width) { + Some(end) if register.is_multiple_of(width) && end <= WINDOW => Ok(register as usize), + _ => Err(power::AccessError::Bounds), + } +} #[derive(Clone)] pub struct NativeBootIo { registers: Mmio, @@ -125,7 +136,7 @@ impl NativeBootIo { /// context. Nominal clocks cannot supply it. The window stays mapped through /// the owner's final Drop, including deliberate quarantine on failure. pub unsafe fn from_window( - window: NonNull<[u8; 16384]>, + window: NonNull<[u8; WINDOW as usize]>, owner: Rc, minimum: Rc, ) -> Result { @@ -137,7 +148,7 @@ impl NativeBootIo { } Ok(Self { // SAFETY: covered by this function's own safety contract. - registers: unsafe { Mmio::new(window.as_ptr().cast::() as u64, 16384) }, + registers: unsafe { Mmio::new(window.as_ptr().cast::() as u64, WINDOW as usize) }, minimum, owner, }) @@ -145,16 +156,10 @@ impl NativeBootIo { } impl Csr for NativeBootIo { fn read32(&mut self, register: u32) -> Result { - if !register.is_multiple_of(4) || register > 8188 { - return Err(power::AccessError::Bounds); - } - Ok(self.registers.read32(register as usize)) + Ok(self.registers.read32(reach(register, 4)?)) } fn write32(&mut self, register: u32, value: u32) -> Result<(), power::AccessError> { - if !register.is_multiple_of(4) || register > 8188 { - return Err(power::AccessError::Bounds); - } - self.registers.write32(register as usize, value); + self.registers.write32(reach(register, 4)?, value); Ok(()) } fn delay_us(&mut self, microseconds: u32) -> Result<(), power::AccessError> { @@ -166,10 +171,7 @@ impl Csr for NativeBootIo { // SAFETY: construction requires the owned exclusive requester/BAR. unsafe impl BootIo for NativeBootIo { fn write8(&mut self, register: u32, value: u8) -> Result<(), power::AccessError> { - if register >= 8192 { - return Err(power::AccessError::Bounds); - } - self.registers.write8(register as usize, value); + self.registers.write8(reach(register, 1)?, value); Ok(()) } fn reset_function(&mut self) -> Result { diff --git a/crates/stela-driver-net/src/wifi/intel/boot/tests.rs b/crates/stela-driver-net/src/wifi/intel/boot/tests.rs index 69812fe1b0..828e5c721b 100644 --- a/crates/stela-driver-net/src/wifi/intel/boot/tests.rs +++ b/crates/stela-driver-net/src/wifi/intel/boot/tests.rs @@ -127,3 +127,37 @@ mod rom_retirement; mod setup; mod transport; mod unified_fixture; + +/// Asimose's AX200 (0.6.0) stopped at `Boot(Access(Bounds))`: the window +/// refused the MSI-X registers at 0x2800 and up, which `route_interrupts` +/// and `causes` reach on a function with a vector. +#[test] +fn the_msix_registers_every_family_routes_through_are_inside_the_window() { + use super::super::interrupts; + for family in [Family::Ax200, Family::Ax210, Family::Bz, Family::Sc] { + let routes = interrupts::routes(family); + for ivar in routes.ivars { + assert_eq!(reach(ivar, 1), Ok(ivar as usize), "{family:?} {ivar:#x}"); + } + for register in [ + interrupts::FH_CAUSES, + interrupts::FH_MASK, + interrupts::HW_CAUSES, + interrupts::HW_MASK, + interrupts::AUTOMASK, + ] { + assert_eq!(reach(register, 4), Ok(register as usize)); + } + } + assert_eq!(reach(WINDOW - 4, 4), Ok(WINDOW as usize - 4)); + assert_eq!(reach(WINDOW - 1, 1), Ok(WINDOW as usize - 1)); + for (register, width) in [ + (WINDOW, 4), + (WINDOW, 1), + (WINDOW - 2, 4), + (0x2802, 4), + (u32::MAX, 1), + ] { + assert_eq!(reach(register, width), Err(power::AccessError::Bounds)); + } +} diff --git a/crates/stela-driver-net/src/wifi/intel/boot/tests/model.rs b/crates/stela-driver-net/src/wifi/intel/boot/tests/model.rs index 2127ea35a1..357b98b0a4 100644 --- a/crates/stela-driver-net/src/wifi/intel/boot/tests/model.rs +++ b/crates/stela-driver-net/src/wifi/intel/boot/tests/model.rs @@ -56,6 +56,17 @@ impl Model { &mut self, op: Op, ) -> Result, power::AccessError> { + // The bounds `NativeBootIo` keeps, so no fixture reaches a register + // the real BAR window refuses. + match op { + Op::Read(register) | Op::Write(register, _) => { + reach(register, 4)?; + } + Op::Write8(register, _) => { + reach(register, 1)?; + } + Op::Delay(_) | Op::Reset => {} + } let mut state = self.state.lock().unwrap(); let index = state.ops.len(); state.ops.push(op); diff --git a/crates/stela-drivers/src/probe.rs b/crates/stela-drivers/src/probe.rs index 404f9a00e2..7b5ae26767 100644 --- a/crates/stela-drivers/src/probe.rs +++ b/crates/stela-drivers/src/probe.rs @@ -287,7 +287,7 @@ impl fmt::Display for PlatformError { Self::Refused(why) => f.write_str(why), Self::Ps2(error) => error.fmt(f), Self::Native(error) => error.fmt(f), - // Stela assigns no PCI BARs: one the firmware left at 0 stays + // Stambha assigns no PCI BARs: one the firmware left at 0 stays // unmapped where Linux would assign it. Self::PciBar { index, @@ -296,8 +296,8 @@ impl fmt::Display for PlatformError { error, } => write!( f, - "BAR{index} ({bytes:#x} bytes) left unassigned by the firmware, and Stela assigns \ - none yet: {error}" + "BAR{index} ({bytes:#x} bytes) left unassigned by the firmware, and Stambha \ + assigns none yet: {error}" ), Self::PciBar { index, @@ -1042,7 +1042,8 @@ const XHCI_DIED_AGAIN: &str = "xHCI: the controller stopped answering again afte its devices are out of reach for this boot"; /// Why a Wi-Fi adapter is left alone. -const NO_WIFI_NETWORK: &str = "Wi-Fi adapter stays off: no --wifi network"; +const NO_WIFI_NETWORK: &str = + "Wi-Fi adapter stays off: no network is chosen (press W at the boot menu to choose one)"; /// Said when an RTL8852CE's MAC was found powered on. const RTW89_WAS_ON: &str = @@ -5018,9 +5019,10 @@ mod tests { format!("{}", bar(0x40_1700_0000)), "BAR0 at 0x4017000000 (0x1000 bytes): outside" ); - assert!( - format!("{}", bar(0)) - .starts_with("BAR0 (0x1000 bytes) left unassigned by the firmware") + assert_eq!( + format!("{}", bar(0)), + "BAR0 (0x1000 bytes) left unassigned by the firmware, and Stambha assigns none yet: \ + outside" ); } } diff --git a/crates/stela-engine/src/machine/engine/native_failure.rs b/crates/stela-engine/src/machine/engine/native_failure.rs index 1d8233bbf6..1164e03066 100644 --- a/crates/stela-engine/src/machine/engine/native_failure.rs +++ b/crates/stela-engine/src/machine/engine/native_failure.rs @@ -180,10 +180,18 @@ impl Machine { // store let go is not read at a fault: the entry's bytes in guest // memory compile its rows again. let record = key.and_then(|key| self.stored_record(physical, &key)); + // Nor is a record that no longer holds the entry: once the pack is + // retired, a lookup gives only the pieces of a record still in + // memory (`Store::stored`), so the bytes compile the rows then too. + let held = record.as_deref().is_some_and(|record| { + self.code + .blocks + .recovery() + .get(&index) + .is_some_and(|owner| owner.stored_in(record)) + }); let mut memory = alloc::vec::Vec::new(); - if record.is_none() - && let Some(bytes) = input_bytes - { + if !held && let Some(bytes) = input_bytes { memory.resize(bytes, 0); if !self.host.read_ram(physical, &mut memory) { memory.clear(); diff --git a/crates/stela-engine/src/machine/engine/recovery.rs b/crates/stela-engine/src/machine/engine/recovery.rs index 32ed28d427..5388902265 100644 --- a/crates/stela-engine/src/machine/engine/recovery.rs +++ b/crates/stela-engine/src/machine/engine/recovery.rs @@ -382,6 +382,18 @@ impl CodeRecovery { } } + /// Whether `record` holds this owner's entry, from which its first fault + /// qualifies; else the entry's bytes in guest memory do + /// ([`Self::qualify`]). An owner with no stored entry to find needs none. + pub(super) fn stored_in(&self, record: &StoredRecord) -> bool { + match &self.rows { + Rows::Stored { origin, offset, .. } if origin.kept.is_none() => { + record.contains(*offset, &origin.context) + } + _ => true, + } + } + /// The rows, qualifying a stored record's on its first fault at `pc`, the /// block's entry: in the dispatcher, before any guest projection. `record` /// is the one [`Self::stored_key`] names; without it, `memory` holds the diff --git a/crates/stela-engine/src/machine/engine/recovery/tests.rs b/crates/stela-engine/src/machine/engine/recovery/tests.rs index fe7b979e69..4f41efc085 100644 --- a/crates/stela-engine/src/machine/engine/recovery/tests.rs +++ b/crates/stela-engine/src/machine/engine/recovery/tests.rs @@ -212,6 +212,100 @@ fn a_stored_block_whose_record_went_qualifies_from_its_bytes_in_memory() { ); } +/// A record of the block's page that no longer holds its entry (after the +/// pack is retired, a lookup gives only the pieces of the record still in +/// memory) is no record of it: the fault reads the entry's bytes from guest +/// memory, as for a record the store let go, and gets the block's rows. +#[test] +fn a_stored_block_whose_record_lost_its_entry_qualifies_from_its_bytes_in_memory() { + let preparation = Arc::new(prepare::test_preparation()); + let source: Vec = [0x9100_0400u32, 0xf940_0043, 0xd400_0001] + .into_iter() + .flat_map(u32::to_le_bytes) + .collect(); + let mut page = [0u8; crate::translations::PAGE_BYTES]; + page[..source.len()].copy_from_slice(&source); + let key = Digest::of(&page); + let context = preparation.context(BASE); + let compile = |pc: u64, input: &[u8]| { + Offer::compile(key, BASE, pc, context, input.to_vec(), preparation.clone()).unwrap() + }; + let offer = compile(BASE, &source); + let expected = offer.block().fault_recovery.clone(); + assert!(!expected.is_empty()); + let translator = translator_id(); + let encode = |offer: &Offer| { + let mut record = Record::new(translator, key); + record.insert(offer.entry().unwrap()); + Record::decode(&record.encode(), &translator, &key).unwrap() + }; + let whole = encode(&offer); + // The same page's record, holding only another block's entry. + let partial = encode(&compile(BASE + 8, &source[8..])); + let (whole, partial) = ( + crate::translations::StoredRecord::of(&whole), + crate::translations::StoredRecord::of(&partial), + ); + let origin = Arc::new(StoredOrigin { + key, + context, + page: BASE, + preparation: preparation.clone(), + kept: None, + }); + let entry = whole.find(0, &context).unwrap(); + let mut relocated = crate::translations::Relocated::default(); + assert!(entry.relocate(BASE, offer.input(), &mut relocated)); + let mut owner = Template::stored(&entry, &relocated, origin).installed(); + assert!(owner.stored_in(&whole)); + assert!(!owner.stored_in(&partial)); + let bytes = owner.stored_input_bytes().unwrap(); + // The partial record alone gives no rows: what the fault was. + assert_eq!( + owner + .qualify(BASE, Some(&partial), None) + .map(|rows| rows.rows()), + Err(NativeFailureReason::StoredRecord) + ); + assert_eq!( + owner + .qualify(BASE, Some(&partial), Some(&source[..bytes])) + .unwrap() + .rows(), + expected + ); +} + +/// Retired, a lookup of a key with a piece left in the file gives the +/// pieces in memory alone, where before it gave none: a record that can lack +/// an entry the boot installed from the whole record, which a fault must not +/// take for that entry's (`CodeRecovery::stored_in`). Asimose's 0.6.0 +/// stopped at `NativeFailureReason::StoredRecord` 2 s after a retirement. +#[test] +fn a_retired_store_gives_a_record_of_only_its_pieces_in_memory() { + use crate::translations::pack::{Layout, Pack, Piece, Store, prefix_bytes}; + let translator = translator_id(); + let keys: Vec = (0..64u32).map(|n| Digest::of(&n.to_le_bytes())).collect(); + let layout = |keys: &[Digest]| { + let records = keys + .iter() + .map(|&key| (key, Piece::New(Record::new(translator, key).encode()))) + .collect(); + Layout::new(&translator, records).to_vec() + }; + // Every key in a segment left in the file, half of them in one in memory. + let bytes = [layout(&keys), layout(&keys[..32])]; + let prefix = prefix_bytes(&bytes[0], &translator).unwrap(); + let disk = Pack::index_only(&bytes[0][..prefix], &translator).unwrap(); + let whole = Pack::parse(&bytes[1], &translator).unwrap(); + let mut store = Store::over(translator, alloc::vec![disk, whole]); + assert!(store.stored(&keys[3]).is_none()); + assert!(store.stored(&keys[40]).is_none()); + store.retire(); + assert!(store.stored(&keys[3]).is_some()); + assert!(store.stored(&keys[40]).is_none()); +} + /// An entry proven during the boot qualifies from itself, at the page it /// was rebased to: the rows of the block compiled at that page. #[test] diff --git a/guest/stela-app/Sources/Stela/ThisPCView.swift b/guest/stela-app/Sources/Stela/ThisPCView.swift index ef48ea3343..298d53645f 100644 --- a/guest/stela-app/Sources/Stela/ThisPCView.swift +++ b/guest/stela-app/Sources/Stela/ThisPCView.swift @@ -16,7 +16,7 @@ .accessibilityHidden(true) Text("macOS \(model.osVersion)").font(Style.title) if let version = model.host?.stelaVersion { - Text("Stela \(version)").font(Style.caption).foregroundStyle(.secondary) + Text("Stambha \(version)").font(Style.caption).foregroundStyle(.secondary) } } .padding(.bottom, Style.spacing) @@ -24,7 +24,7 @@ if let host = model.host { cards(host) } else { - Card(label: "Hardware", value: "No PC description from Stela") + Card(label: "Hardware", value: "No PC description from Stambha") } if let presented = model.presented { diff --git a/guest/stela-app/Sources/Stela/UpdatesView.swift b/guest/stela-app/Sources/Stela/UpdatesView.swift index 2bb00a186a..e5b4213a15 100644 --- a/guest/stela-app/Sources/Stela/UpdatesView.swift +++ b/guest/stela-app/Sources/Stela/UpdatesView.swift @@ -10,7 +10,7 @@ VStack(alignment: .leading, spacing: Style.spacing) { Surface { Rows(rows: [ - ("Stela", model.host?.stelaVersion, false), + ("Stambha", model.host?.stelaVersion, false), ("Translator", model.host?.translatorID, true), ("App", model.appVersion, false), ("Revision", model.appBuild, true), diff --git a/guest/stela-app/Sources/StelaSystem/HostInventory.swift b/guest/stela-app/Sources/StelaSystem/HostInventory.swift index 5f3a97345a..3991abb461 100644 --- a/guest/stela-app/Sources/StelaSystem/HostInventory.swift +++ b/guest/stela-app/Sources/StelaSystem/HostInventory.swift @@ -206,7 +206,7 @@ public struct HostInventory: Codable, Equatable, Sendable { } } if let translatorTarget { lines.append("Target: \(translatorTarget)") } - if let stelaVersion { lines.append("Stela \(stelaVersion)") } + if let stelaVersion { lines.append("Stambha \(stelaVersion)") } let presented = [presentedModel, presentedChip].compactMap { $0 } if !presented.isEmpty { lines.append("Presented as \(presented.joined(separator: ", "))") } return lines.joined(separator: "\n") diff --git a/guest/stela-app/Tests/StelaSystemTests/HostInventoryTests.swift b/guest/stela-app/Tests/StelaSystemTests/HostInventoryTests.swift index ba26ee3aa0..15479ce94e 100644 --- a/guest/stela-app/Tests/StelaSystemTests/HostInventoryTests.swift +++ b/guest/stela-app/Tests/StelaSystemTests/HostInventoryTests.swift @@ -84,7 +84,7 @@ final class HostInventoryTests: XCTestCase { Translation: AVX2, FMA Extensions: F16C, AES-NI, SHA, PCLMUL, BMI2, LZCNT, POPCNT, MOVBE, GFNI Target: x86_64-baseline+ssse3+sse4.1+sse4.2+pclmulqdq+fma+f16c+popcnt+bmi1+aes+sha+atomic-load16+cx8+cx16+avx2+lzcnt+bmi2+fast-pdep+movbe+gfni - Stela 0.1.0 + Stambha 0.1.0 Presented as Mac14,3, Apple M2 """) XCTAssertEqual(