[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240415104701.4772-2-fujita.tomonori@gmail.com>
Date: Mon, 15 Apr 2024 19:46:58 +0900
From: FUJITA Tomonori <fujita.tomonori@...il.com>
To: netdev@...r.kernel.org
Cc: andrew@...n.ch,
rust-for-linux@...r.kernel.org,
tmgross@...ch.edu
Subject: [PATCH net-next v1 1/4] rust: net::phy support config_init driver callback
This patch adds phy_driver's config_init callback support for
initializing the hardware.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@...il.com>
---
rust/kernel/net/phy.rs | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs
index 96e09c6e8530..44b59bbf1a52 100644
--- a/rust/kernel/net/phy.rs
+++ b/rust/kernel/net/phy.rs
@@ -338,6 +338,22 @@ impl<T: Driver> Adapter<T> {
})
}
+ /// # Safety
+ ///
+ /// `phydev` must be passed by the corresponding callback in `phy_driver`.
+ unsafe extern "C" fn config_init_callback(
+ phydev: *mut bindings::phy_device,
+ ) -> core::ffi::c_int {
+ from_result(|| {
+ // SAFETY: This callback is called only in contexts
+ // where we hold `phy_device->lock`, so the accessors on
+ // `Device` are okay to call.
+ let dev = unsafe { Device::from_raw(phydev) };
+ T::config_init(dev)?;
+ Ok(0)
+ })
+ }
+
/// # Safety
///
/// `phydev` must be passed by the corresponding callback in `phy_driver`.
@@ -511,6 +527,11 @@ pub const fn create_phy_driver<T: Driver>() -> DriverVTable {
} else {
None
},
+ config_init: if T::HAS_CONFIG_INIT {
+ Some(Adapter::<T>::config_init_callback)
+ } else {
+ None
+ },
get_features: if T::HAS_GET_FEATURES {
Some(Adapter::<T>::get_features_callback)
} else {
@@ -583,6 +604,11 @@ fn soft_reset(_dev: &mut Device) -> Result {
kernel::build_error(VTABLE_DEFAULT_ERROR)
}
+ /// Initializes the hardware, including after a reset.
+ fn config_init(_dev: &mut Device) -> Result {
+ kernel::build_error(VTABLE_DEFAULT_ERROR)
+ }
+
/// Probes the hardware to determine what abilities it has.
fn get_features(_dev: &mut Device) -> Result {
kernel::build_error(VTABLE_DEFAULT_ERROR)
--
2.34.1
Powered by blists - more mailing lists