[PATCH net-next v3 1/2] rust: net: phy: add speed() getter to Device

From: Artem Lytkin

Date: Tue Feb 24 2026 - 12:00:03 EST


Add a speed() getter to phy::Device that reads the current link speed
from the phy_device struct. This is needed by PHY drivers that must
detect speed changes in their read_status callback.

Signed-off-by: Artem Lytkin <iprintercanon@xxxxxxxxx>
---
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..3812f8fd3e49 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 current link speed.
+ 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