Lines Matching +full:phy +full:- +full:bindings

1 // SPDX-License-Identifier: GPL-2.0
5 //! Network PHY device.
7 //! C headers: [`include/linux/phy.h`](srctree/include/linux/phy.h).
14 /// PHY state machine states.
18 /// Some of PHY drivers access to the state of PHY's software state machine.
20 /// [`enum phy_state`]: srctree/include/linux/phy.h
23 /// PHY device and driver are not ready for anything.
25 /// PHY is ready to send and receive packets.
27 /// PHY is up, but no polling or interrupts are done.
29 /// PHY is up, but is in an error state.
31 /// PHY and attached device are ready to do work.
33 /// PHY is currently running.
35 /// PHY is up, but not currently plugged in.
37 /// PHY is performing a cable test.
43 /// PHY drivers get duplex information from hardware and update the current state.
45 /// PHY is in full-duplex mode.
47 /// PHY is in half-duplex mode.
49 /// PHY is in unknown duplex mode.
53 /// An instance of a PHY device.
57 /// A [`Device`] instance is created when a callback in [`Driver`] is executed. A PHY driver
62 /// - Referencing a `phy_device` using this struct asserts that you are in
64 /// - This struct always has a valid `self.0.mdio.dev`.
66 /// [`struct phy_device`]: srctree/include/linux/phy.h
74 pub struct Device(Opaque<bindings::phy_device>);
82 /// - the pointer must point at a valid `phy_device`, and the caller
85 /// - `(*ptr).mdio.dev` must be a valid.
86 unsafe fn from_raw<'a>(ptr: *mut bindings::phy_device) -> &'a mut Self { in from_raw()
87 // CAST: `Self` is a `repr(transparent)` wrapper around `bindings::phy_device`. in from_raw()
94 /// Gets the id of the PHY.
95 pub fn phy_id(&self) -> u32 { in phy_id()
102 /// Gets the state of PHY state machine states.
103 pub fn state(&self) -> DeviceState { in state()
111 bindings::phy_state_PHY_DOWN => DeviceState::Down, in state()
112 bindings::phy_state_PHY_READY => DeviceState::Ready, in state()
113 bindings::phy_state_PHY_HALTED => DeviceState::Halted, in state()
114 bindings::phy_state_PHY_ERROR => DeviceState::Error, in state()
115 bindings::phy_state_PHY_UP => DeviceState::Up, in state()
116 bindings::phy_state_PHY_RUNNING => DeviceState::Running, in state()
117 bindings::phy_state_PHY_NOLINK => DeviceState::NoLink, in state()
118 bindings::phy_state_PHY_CABLETEST => DeviceState::CableTest, in state()
126 pub fn is_link_up(&self) -> bool { in is_link_up()
136 /// Gets the current auto-negotiation configuration.
138 /// It returns true if auto-negotiation is enabled.
139 pub fn is_autoneg_enabled(&self) -> bool { in is_autoneg_enabled()
145 bit_field.get(13, 1) == bindings::AUTONEG_ENABLE as u64 in is_autoneg_enabled()
148 /// Gets the current auto-negotiation state.
150 /// It returns true if auto-negotiation is completed.
151 pub fn is_autoneg_completed(&self) -> bool { in is_autoneg_completed()
161 /// Sets the speed of the PHY.
173 DuplexMode::Full => bindings::DUPLEX_FULL as i32, in set_duplex()
174 DuplexMode::Half => bindings::DUPLEX_HALF as i32, in set_duplex()
175 DuplexMode::Unknown => bindings::DUPLEX_UNKNOWN as i32, in set_duplex()
182 /// Reads a PHY register.
184 pub fn read<R: reg::Register>(&mut self, reg: R) -> Result<u16> { in read()
188 /// Writes a PHY register.
189 pub fn write<R: reg::Register>(&mut self, reg: R, val: u16) -> Result { in write()
194 pub fn read_paged(&mut self, page: u16, regnum: u16) -> Result<u16> { in read_paged()
198 let ret = unsafe { bindings::phy_read_paged(phydev, page.into(), regnum.into()) }; in read_paged()
206 /// Resolves the advertisements into PHY settings.
211 unsafe { bindings::phy_resolve_aneg_linkmode(phydev) }; in resolve_aneg_linkmode()
214 /// Executes software reset the PHY via `BMCR_RESET` bit.
215 pub fn genphy_soft_reset(&mut self) -> Result { in genphy_soft_reset()
219 to_result(unsafe { bindings::genphy_soft_reset(phydev) }) in genphy_soft_reset()
222 /// Initializes the PHY.
223 pub fn init_hw(&mut self) -> Result { in init_hw()
227 to_result(unsafe { bindings::phy_init_hw(phydev) }) in init_hw()
230 /// Starts auto-negotiation.
231 pub fn start_aneg(&mut self) -> Result { in start_aneg()
235 to_result(unsafe { bindings::_phy_start_aneg(phydev) }) in start_aneg()
238 /// Resumes the PHY via `BMCR_PDOWN` bit.
239 pub fn genphy_resume(&mut self) -> Result { in genphy_resume()
243 to_result(unsafe { bindings::genphy_resume(phydev) }) in genphy_resume()
246 /// Suspends the PHY via `BMCR_PDOWN` bit.
247 pub fn genphy_suspend(&mut self) -> Result { in genphy_suspend()
251 to_result(unsafe { bindings::genphy_suspend(phydev) }) in genphy_suspend()
255 pub fn genphy_read_status<R: reg::Register>(&mut self) -> Result<u16> { in genphy_read_status()
260 pub fn genphy_update_link(&mut self) -> Result { in genphy_update_link()
264 to_result(unsafe { bindings::genphy_update_link(phydev) }) in genphy_update_link()
268 pub fn genphy_read_lpa(&mut self) -> Result { in genphy_read_lpa()
272 to_result(unsafe { bindings::genphy_read_lpa(phydev) }) in genphy_read_lpa()
275 /// Reads PHY abilities.
276 pub fn genphy_read_abilities(&mut self) -> Result { in genphy_read_abilities()
280 to_result(unsafe { bindings::genphy_read_abilities(phydev) }) in genphy_read_abilities()
285 fn as_ref(&self) -> &kernel::device::Device { in as_ref()
292 /// Defines certain other features this PHY supports (like interrupts).
296 /// PHY is internal.
297 pub const IS_INTERNAL: u32 = bindings::PHY_IS_INTERNAL;
298 /// PHY needs to be reset after the refclk is enabled.
299 pub const RST_AFTER_CLK_EN: u32 = bindings::PHY_RST_AFTER_CLK_EN;
300 /// Polling is used to detect PHY status changes.
301 pub const POLL_CABLE_TEST: u32 = bindings::PHY_POLL_CABLE_TEST;
303 pub const ALWAYS_CALL_SUSPEND: u32 = bindings::PHY_ALWAYS_CALL_SUSPEND;
306 /// An adapter for the registration of a PHY driver.
316 phydev: *mut bindings::phy_device, in soft_reset_callback()
317 ) -> crate::ffi::c_int { in soft_reset_callback()
320 // where we hold `phy_device->lock`, so the accessors on in soft_reset_callback()
331 unsafe extern "C" fn probe_callback(phydev: *mut bindings::phy_device) -> crate::ffi::c_int { in probe_callback()
347 phydev: *mut bindings::phy_device, in get_features_callback()
348 ) -> crate::ffi::c_int { in get_features_callback()
351 // where we hold `phy_device->lock`, so the accessors on in get_features_callback()
362 unsafe extern "C" fn suspend_callback(phydev: *mut bindings::phy_device) -> crate::ffi::c_int { in suspend_callback()
365 // `Device` are okay to call even though `phy_device->lock` in suspend_callback()
376 unsafe extern "C" fn resume_callback(phydev: *mut bindings::phy_device) -> crate::ffi::c_int { in resume_callback()
379 // `Device` are okay to call even though `phy_device->lock` in resume_callback()
391 phydev: *mut bindings::phy_device, in config_aneg_callback()
392 ) -> crate::ffi::c_int { in config_aneg_callback()
395 // where we hold `phy_device->lock`, so the accessors on in config_aneg_callback()
407 phydev: *mut bindings::phy_device, in read_status_callback()
408 ) -> crate::ffi::c_int { in read_status_callback()
411 // where we hold `phy_device->lock`, so the accessors on in read_status_callback()
423 phydev: *mut bindings::phy_device, in match_phy_device_callback()
424 ) -> crate::ffi::c_int { in match_phy_device_callback()
426 // where we hold `phy_device->lock`, so the accessors on in match_phy_device_callback()
436 phydev: *mut bindings::phy_device, in read_mmd_callback()
439 ) -> i32 { in read_mmd_callback()
442 // where we hold `phy_device->lock`, so the accessors on in read_mmd_callback()
455 phydev: *mut bindings::phy_device, in write_mmd_callback()
459 ) -> i32 { in write_mmd_callback()
462 // where we hold `phy_device->lock`, so the accessors on in write_mmd_callback()
473 unsafe extern "C" fn link_change_notify_callback(phydev: *mut bindings::phy_device) { in link_change_notify_callback()
475 // where we hold `phy_device->lock`, so the accessors on in link_change_notify_callback()
482 /// Driver structure for a particular PHY type.
485 /// This is used to register a driver for a particular PHY type with the kernel.
491 /// [`struct phy_driver`]: srctree/include/linux/phy.h
493 pub struct DriverVTable(Opaque<bindings::phy_driver>);
504 pub const fn create_phy_driver<T: Driver>() -> DriverVTable { in create_phy_driver()
506 DriverVTable(Opaque::new(bindings::phy_driver { in create_phy_driver()
568 ..unsafe { core::mem::MaybeUninit::<bindings::phy_driver>::zeroed().assume_init() } in create_phy_driver()
572 /// Driver implementation for a particular PHY type.
577 /// Defines certain other features this PHY supports.
581 /// The friendly name of this PHY type.
588 /// Issues a PHY software reset.
589 fn soft_reset(_dev: &mut Device) -> Result { in soft_reset()
593 /// Sets up device-specific structures during discovery.
594 fn probe(_dev: &mut Device) -> Result { in probe()
599 fn get_features(_dev: &mut Device) -> Result { in get_features()
605 fn match_phy_device(_dev: &Device) -> bool { in match_phy_device()
609 /// Configures the advertisement and resets auto-negotiation
610 /// if auto-negotiation is enabled.
611 fn config_aneg(_dev: &mut Device) -> Result { in config_aneg()
616 fn read_status(_dev: &mut Device) -> Result<u16> { in read_status()
621 fn suspend(_dev: &mut Device) -> Result { in suspend()
626 fn resume(_dev: &mut Device) -> Result { in resume()
631 fn read_mmd(_dev: &mut Device, _devnum: u8, _regnum: u16) -> Result<u16> { in read_mmd()
636 fn write_mmd(_dev: &mut Device, _devnum: u8, _regnum: u16, _val: u16) -> Result { in write_mmd()
644 /// Registration structure for PHY drivers.
660 /// Registers a PHY driver.
664 ) -> Result<Self> { in register()
672 bindings::phy_drivers_register(drivers[0].0.get(), drivers.len().try_into()?, module.0) in register()
684 bindings::phy_drivers_unregister(self.drivers[0].0.get(), self.drivers.len() as i32) in drop()
689 /// An identifier for PHY devices on an MDIO/MII bus.
692 /// PHY driver.
700 pub const fn new_with_exact_mask(id: u32) -> Self { in new_with_exact_mask()
708 pub const fn new_with_model_mask(id: u32) -> Self { in new_with_model_mask()
716 pub const fn new_with_vendor_mask(id: u32) -> Self { in new_with_vendor_mask()
724 pub const fn new_with_custom_mask(id: u32, mask: u32) -> Self { in new_with_custom_mask()
732 pub const fn new_with_driver<T: Driver>() -> Self { in new_with_driver()
737 pub const fn mask_as_int(&self) -> u32 { in mask_as_int()
743 pub const fn mdio_device_id(&self) -> bindings::mdio_device_id { in mdio_device_id()
744 bindings::mdio_device_id { in mdio_device_id()
763 const fn as_int(&self) -> u32 { in as_int()
784 /// use kernel::net::phy::{self, DeviceId};
801 /// impl phy::Driver for PhySample {
803 /// const PHY_DEVICE_ID: phy::DeviceId = phy::DeviceId::new_with_exact_mask(0x00000001);
812 /// use kernel::net::phy::{self, DeviceId};
816 /// _reg: ::kernel::net::phy::Registration,
830 /// impl phy::Driver for PhySample {
832 /// const PHY_DEVICE_ID: phy::DeviceId = phy::DeviceId::new_with_exact_mask(0x00000001);
836 /// static mut DRIVERS: [::kernel::net::phy::DriverVTable; 1] =
837 /// [::kernel::net::phy::create_phy_driver::<PhySample>()];
840 /// fn init(module: &'static ::kernel::ThisModule) -> Result<Self> {
842 /// let mut reg = ::kernel::net::phy::Registration::register(
851 /// const _DEVICE_TABLE: [::kernel::bindings::mdio_device_id; 2] = [
852 /// ::kernel::bindings::mdio_device_id {
856 /// ::kernel::bindings::mdio_device_id {
863 /// static __mod_device_table__mdio__phydev: [::kernel::bindings::mdio_device_id; 2] = _DEVICE_TABL…
875 const _DEVICE_TABLE: [$crate::bindings::mdio_device_id;
878 $crate::bindings::mdio_device_id {
886 static __mod_device_table__mdio__phydev: [$crate::bindings::mdio_device_id;
892 _reg: $crate::net::phy::Registration,
901 static mut DRIVERS: [$crate::net::phy::DriverVTable;
903 [$($crate::net::phy::create_phy_driver::<$driver>()),+];
906 fn init(module: &'static $crate::ThisModule) -> Result<Self> {
910 let mut reg = $crate::net::phy::Registration::register(