Add a speed() method to phy::Device as a getter counterpart to the existing set_speed(). This is needed by PHY drivers that need to detect speed changes, such as drivers that must reconfigure hardware registers when the link speed changes. Signed-off-by: Artem Lytkin --- rust/kernel/net/phy.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index 3ca99db5cccf..b86939b163e3 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -158,6 +158,14 @@ pub fn is_autoneg_completed(&self) -> bool { bit_field.get(15, 1) == AUTONEG_COMPLETED } + /// Gets the negotiated speed of the PHY. + pub fn speed(&self) -> i32 { + let phydev = self.0.get(); + // SAFETY: The struct invariant ensures that we may access + // this field without additional synchronization. + unsafe { (*phydev).speed } + } + /// Sets the speed of the PHY. pub fn set_speed(&mut self, speed: u32) { let phydev = self.0.get(); -- 2.43.0