# \[PATCH net-next v2 1/3\] rust: net: phy: add speed() getter to Device

- From: Artem Lytkin \<hidden\>
- Date: 2026-02-24 04:32:15 
- List: netdev
- Page: https://ratatoskr.run/netdev/2026/02/3423973
- Thread: https://ratatoskr.run/netdev/2026/02/3423636/t.md

```text
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 <redacted>
---
 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

```
