From: Artem Lytkin <iprintercanon@gmail.com>
To: netdev@vger.kernel.org, rust-for-linux@vger.kernel.org
Cc: fujita.tomonori@gmail.com, andrew@lunn.ch, hkallweit1@gmail.com,
tmgross@umich.edu, ojeda@kernel.org, dakr@kernel.org
Subject: [PATCH net-next v2 1/5] rust: phy: add read-only device field accessors
Date: Tue, 24 Mar 2026 18:52:45 +0300 [thread overview]
Message-ID: <20260324155249.15098-2-iprintercanon@gmail.com> (raw)
In-Reply-To: <20260324155249.15098-1-iprintercanon@gmail.com>
Add getter methods for commonly needed PHY device fields:
- speed(): Returns the current link speed as i32, matching the
C struct field type (int speed).
- duplex(): Returns the current duplex mode as DuplexMode enum.
Only the setter (set_duplex) existed previously.
- interface(): Returns the PHY interface mode (RGMII, SGMII, etc.)
as a raw phy_interface_t value. A typed Rust enum is future work
since phy_interface_t has 40+ variants tied to DT bindings.
- irq(): Returns the PHY's IRQ number.
These accessors are needed by Rust PHY drivers that must inspect
hardware state, particularly during config_init and read_status
callbacks.
Signed-off-by: Artem Lytkin <iprintercanon@gmail.com>
---
rust/kernel/net/phy.rs | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs
index 3ca99db5cccf2..646b2a78a2710 100644
--- a/rust/kernel/net/phy.rs
+++ b/rust/kernel/net/phy.rs
@@ -179,6 +179,47 @@ pub fn set_duplex(&mut self, mode: DuplexMode) {
unsafe { (*phydev).duplex = v as c_int };
}
+ /// Gets the current speed setting.
+ 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 }
+ }
+
+ /// Gets the current duplex mode.
+ pub fn duplex(&self) -> DuplexMode {
+ let phydev = self.0.get();
+ // SAFETY: The struct invariant ensures that we may access
+ // this field without additional synchronization.
+ let v = unsafe { (*phydev).duplex };
+ match v as u32 {
+ bindings::DUPLEX_FULL => DuplexMode::Full,
+ bindings::DUPLEX_HALF => DuplexMode::Half,
+ _ => DuplexMode::Unknown,
+ }
+ }
+
+ /// Gets the PHY interface mode as a raw `phy_interface_t` value.
+ ///
+ /// Common values include `bindings::phy_interface_t_PHY_INTERFACE_MODE_RGMII`,
+ /// `bindings::phy_interface_t_PHY_INTERFACE_MODE_SGMII`, etc.
+ /// A typed Rust enum is planned for future work.
+ pub fn interface(&self) -> u32 {
+ let phydev = self.0.get();
+ // SAFETY: The struct invariant ensures that we may access
+ // this field without additional synchronization.
+ unsafe { (*phydev).interface }
+ }
+
+ /// Gets the PHY's IRQ number.
+ pub fn irq(&self) -> i32 {
+ let phydev = self.0.get();
+ // SAFETY: The struct invariant ensures that we may access
+ // this field without additional synchronization.
+ unsafe { (*phydev).irq }
+ }
+
/// Reads a PHY register.
// This function reads a hardware register and updates the stats so takes `&mut self`.
pub fn read<R: reg::Register>(&mut self, reg: R) -> Result<u16> {
--
2.43.0
next prev parent reply other threads:[~2026-03-24 15:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-24 15:52 [PATCH net-next v2 0/5] rust: phy: extend abstractions for real-world PHY drivers Artem Lytkin
2026-03-24 15:52 ` Artem Lytkin [this message]
2026-03-24 15:52 ` [PATCH net-next v2 2/5] rust: phy: add paged register access and bit manipulation helpers Artem Lytkin
2026-03-24 15:52 ` [PATCH net-next v2 3/5] rust: phy: add config_init, read_page, and write_page callbacks Artem Lytkin
2026-03-24 15:52 ` [PATCH net-next v2 4/5] rust: phy: add interrupt support Artem Lytkin
2026-03-24 15:52 ` [PATCH net-next v2 5/5] net: phy: realtek: add Rust RTL8211F PHY driver Artem Lytkin
2026-03-24 15:57 ` Andrew Lunn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260324155249.15098-2-iprintercanon@gmail.com \
--to=iprintercanon@gmail.com \
--cc=andrew@lunn.ch \
--cc=dakr@kernel.org \
--cc=fujita.tomonori@gmail.com \
--cc=hkallweit1@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.