fix(net): start an igb or igc adapter whose PHY reset management firmware blocks, skipping only the PHY reset and link setup as Linux does, and pass a PHY reset completion that never comes

This commit is contained in:
Tyler Smith committed 2026-11-12 04:07:33 -05:00
1 parent 7444837c12
commit 48dfd5dfec
5 files changed
+119 -36

No files matched your search

@@ -61,9 +61,6 @@ impl<'a, R: RegisterIo, T: Timer> Hardware<'a, R, T> {
"igb SGMII/SerDes media requires a separate PHY path",
));
}
if self.io.read(MANC) & MANC_BLOCK_PHY != 0 {
return Err(BlockError::Unsupported("igb firmware blocks PHY reset"));
}
self.io
.write(CTRL_EXT, self.io.read(CTRL_EXT) & !CTRL_EXT_I2C);
self.check_nvm()?;
+15 -5
View File
@@ -54,9 +54,11 @@ impl<R: RegisterIo, T: Timer> Hardware<'_, R, T> {
})
}
/// igb_phy_hw_reset; a reset management firmware blocks is skipped
/// (igb_check_reset_block), never refused.
fn hardware_reset_phy(&mut self) -> Result<(), BlockError> {
if self.io.read(MANC) & MANC_BLOCK_PHY != 0 {
return Err(BlockError::Unsupported("igb firmware blocks PHY reset"));
if self.reset_blocked() {
return Ok(());
}
self.synchronized(self.phy_mask(), |hardware| {
let control = hardware.io.read(CTRL);
@@ -89,10 +91,13 @@ impl<R: RegisterIo, T: Timer> Hardware<'_, R, T> {
last.map(|_| ())
}
/// igb_check_reset_block: an SOL/IDE-R session of the management
/// firmware owns the PHY and has its link up.
fn reset_blocked(&self) -> bool {
self.io.read(MANC) & MANC_BLOCK_PHY != 0
}
pub(super) fn configure_phy(&mut self) -> Result<(), BlockError> {
if self.io.read(MANC) & MANC_BLOCK_PHY != 0 {
return Err(BlockError::Unsupported("igb firmware blocks PHY reset"));
}
if !self.chip.old_reset() && self.io.read(MDICNFG) & (1 << 31) != 0 {
return Err(BlockError::Unsupported(
"igb external MDIO PHY is not implemented",
@@ -118,6 +123,11 @@ impl<R: RegisterIo, T: Timer> Hardware<'_, R, T> {
self.io
.write(CTRL, (control | CTRL_SLU) & !(CTRL_FRCSPD | CTRL_FRCDPX));
let control = self.read_phy(PHY_CONTROL)?;
if self.reset_blocked() {
// igb_power_up_phy_copper still runs; igb_setup_link leaves the
// firmware's link as it is.
return self.write_phy(PHY_CONTROL, control & !PHY_POWERDOWN);
}
self.write_phy(
PHY_CONTROL,
control & !(PHY_POWERDOWN | PHY_ISOLATE | PHY_LOOPBACK),
+28 -5
View File
@@ -460,14 +460,10 @@ fn i210_recovers_a_stale_smbi_latch_only_once() {
}
#[test]
fn unknown_phy_media_and_firmware_owned_reset_do_not_start_a_link() {
fn unknown_phy_and_media_do_not_start_a_link() {
let unknown = Model::new(Chip::I82576, 0x1234_5670, true);
assert!(initialize(&unknown, Chip::I82576).is_err());
assert_eq!(unknown.phy_value(PHY_ADVERTISE), 0);
let firmware_owned = Model::new(Chip::I82576, PHY_IGP3, true);
firmware_owned.set(MANC, MANC_BLOCK_PHY);
assert!(initialize(&firmware_owned, Chip::I82576).is_err());
assert!(firmware_owned.mdio_writes.borrow().is_empty());
let media = Model::new(Chip::I82576, PHY_IGP3, true);
media.set(CTRL_EXT, CTRL_EXT_MODE);
assert!(initialize(&media, Chip::I82576).is_err());
@@ -476,6 +472,33 @@ fn unknown_phy_media_and_firmware_owned_reset_do_not_start_a_link() {
assert!(initialize(&mismatch, Chip::I350).is_err());
}
#[test]
fn a_management_owned_phy_is_powered_up_but_neither_reset_nor_renegotiated() {
// igb_check_reset_block: an SOL/IDE-R session owns the PHY and its link.
// Linux skips igb_phy_hw_reset and igb_setup_link, and starts the MAC.
for (chip, phy) in [
(Chip::I82576, PHY_IGP3),
(Chip::I350, PHY_I350),
(Chip::I210, PHY_I210),
] {
let owned = Model::new(chip, phy, true);
owned.set(MANC, MANC_BLOCK_PHY);
initialize(&owned, chip).unwrap_or_else(|error| panic!("{error:?}"));
assert!(
!owned
.writes
.borrow()
.iter()
.any(|&(register, value)| register == CTRL && value & CTRL_PHY_RST != 0)
);
assert_eq!(owned.phy_value(PHY_ADVERTISE), 0);
assert_eq!(owned.phy_value(PHY_GIGABIT), 0x1f00);
assert_eq!(owned.phy_value(PHY_CONTROL) & PHY_POWERDOWN, 0);
assert_eq!(owned.phy_value(PHY_CONTROL) & PHY_RESTART, 0);
owned.assert_released();
}
}
#[test]
fn all_i350_checksum_regions_and_82580_compatibility_mode_are_checked() {
for chip in [Chip::I350, Chip::I82580] {
+29 -16
View File
@@ -110,6 +110,10 @@ const STATUS_SPEED_2500: u32 = 1 << 22;
const CTRL_RFCE: u32 = 1 << 27;
const CTRL_TFCE: u32 = 1 << 28;
const MANC_RCV_TCO_EN: u32 = 1 << 17;
/// IGC_MANC_BLK_PHY_RST_ON_IDE.
const MANC_BLOCK_PHY_RESET: u32 = 1 << 18;
/// IGC_PHY_RST_COMP in PHPM.
const PHY_RESET_COMPLETE: u32 = 1 << 8;
const RFCTL_IPV6_EX_DIS: u32 = 1 << 16;
const RFCTL_LEF: u32 = 1 << 18;
const RCTL_EN: u32 = 1 << 1;
@@ -546,23 +550,29 @@ impl<'a, R: Registers, T: Timer> Hardware<'a, R, T> {
}
fn phy(&mut self) -> Result<u32, BlockError> {
if self.read(MANC)? & (1 << 18) != 0 {
return Err(BlockError::Unsupported(
"igc PHY reset blocked by management firmware",
));
// igc_check_reset_block: management firmware (SOL/IDE-R) owns the
// PHY. igc_phy_hw_reset then skips the reset and igc_setup_link the
// link setup: the firmware has already brought the link up.
let blocked = self.read(MANC)? & MANC_BLOCK_PHY_RESET != 0;
if !blocked {
self.synchronized(PHY_SYNC, |hw| {
let ctrl = hw.read(CTRL)?;
hw.registers.write(CTRL, ctrl | PHY_RESET);
hw.read(STATUS)?;
hw.timer.delay(100)?;
hw.registers.write(CTRL, ctrl);
hw.read(STATUS)?;
hw.timer.delay(100)?;
// igc_phy_hw_reset only logs a reset completion that never
// came; the identity read below still proves the PHY answers.
match hw.poll(PHPM, PHY_RESET_COMPLETE, true, 10_000, 1) {
Ok(_) | Err(BlockError::Timeout) => {}
Err(error) => return Err(error),
}
hw.timer.delay(100)?;
Ok(())
})?;
}
self.synchronized(PHY_SYNC, |hw| {
let ctrl = hw.read(CTRL)?;
hw.registers.write(CTRL, ctrl | PHY_RESET);
hw.read(STATUS)?;
hw.timer.delay(100)?;
hw.registers.write(CTRL, ctrl);
hw.read(STATUS)?;
hw.timer.delay(100)?;
hw.poll(PHPM, 1 << 8, true, 10_000, 1)?;
hw.timer.delay(100)?;
Ok(())
})?;
self.synchronized(PHY_SYNC, |hw| {
let upper = hw.mdio(2, None)?;
hw.timer.delay(200)?;
@@ -574,6 +584,9 @@ impl<'a, R: Registers, T: Timer> Hardware<'a, R, T> {
// Source igc_power_up_phy_copper, followed by advertisement.
let control = hw.mdio(PHY_CONTROL, None)?;
hw.mdio(PHY_CONTROL, Some(control & !(1 << 11)))?;
if blocked {
return Ok(identity);
}
let adv = hw.mdio(PHY_ADVERTISEMENT, None)?;
let gigabit = hw.mdio(PHY_GIGABIT, None)?;
let multigig = hw.mmd(MMD_AN, MMD_MULTIGIG, None)?;
@@ -233,13 +233,12 @@ fn complete_initialization_replaces_inherited_phy_and_mac_state_for_all_declared
#[test]
fn drain_mac_reset_autoload_and_phy_reset_deadlines_never_look_successful() {
for failure in 0..4 {
for failure in 0..3 {
let model = Model::ready(false);
match failure {
0 => model.master_stuck.set(true),
1 => model.reset_stuck.set(true),
2 => model.autoload_stuck.set(true),
_ => model.phy_reset_stuck.set(true),
_ => model.autoload_stuck.set(true),
}
let mut hw = Hardware::new(&model, &model).unwrap();
assert_eq!(hw.initialize(), Err(BlockError::Timeout));
@@ -257,6 +256,21 @@ fn drain_mac_reset_autoload_and_phy_reset_deadlines_never_look_successful() {
}
}
#[test]
fn a_phy_reset_completion_that_never_comes_is_waited_for_then_passed() {
// igc_phy_hw_reset logs the missing PHY_RST_COMP and carries on; the
// PHY identity read that follows still proves the PHY answers.
let model = Model::ready(false);
model.phy_reset_stuck.set(true);
assert_eq!(
Hardware::new(&model, &model).unwrap().initialize(),
Ok(0x67c9_dc01)
);
assert!(model.elapsed.get() >= 10_000 && model.elapsed.get() < 2_000_000);
// Powered up (BMCR power-down clear), autonegotiation restarted.
assert_eq!(model.state.borrow().phy[&0] & 0x1a00, 0x1200);
}
#[test]
fn every_failed_register_read_refuses_initialization() {
let model = Model::ready(true);
@@ -289,14 +303,40 @@ fn mdio_failures_release_software_ownership() {
);
}
#[test]
fn management_owned_phy_is_neither_reset_nor_renegotiated() {
// igc_check_reset_block: SOL/IDE-R firmware owns the PHY and its link;
// Linux skips the PHY reset and the link setup and starts the MAC.
let model = Model::ready(false);
model
.state
.borrow_mut()
.registers
.insert(MANC, MANC_BLOCK_PHY_RESET);
let advertised = model.state.borrow().phy[&4];
assert_eq!(
Hardware::new(&model, &model).unwrap().initialize(),
Ok(0x67c9_dc01)
);
let state = model.state.borrow();
assert!(
!state
.writes
.iter()
.any(|&(r, v)| r == CTRL && v & PHY_RESET != 0)
);
assert_eq!(state.phy[&4], advertised);
// igc_power_up_link still powers the PHY up; autonegotiation is not
// restarted under the firmware's link.
assert_eq!(state.phy[&0], 0);
assert!(state.writes.iter().any(|&(r, _)| r == RXPBS));
}
#[test]
fn firmware_management_and_semaphore_refusals_cannot_be_bypassed() {
for failure in 0..4 {
for failure in 1..4 {
let model = Model::ready(false);
match failure {
0 => {
model.state.borrow_mut().registers.insert(MANC, 1 << 18);
}
1 => model.firmware_busy.set(true),
2 => model.software_busy.set(true),
_ => model.sw_semaphore_refused.set(true),