Lines Matching +full:phy +full:- +full:device
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
68 // unique for every instance of [`Device`]. `PHYLIB` uses a different serialization technique for
74 pub struct Device(Opaque<bindings::phy_device>); struct
76 impl Device { implementation
77 /// Creates a new [`Device`] instance from a raw pointer.
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()
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()
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()
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.
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()
206 /// Resolves the advertisements into PHY settings.
214 /// Executes software reset the PHY via `BMCR_RESET` bit.
215 pub fn genphy_soft_reset(&mut self) -> Result { in genphy_soft_reset()
222 /// Initializes the PHY.
223 pub fn init_hw(&mut self) -> Result { in init_hw()
230 /// Starts auto-negotiation.
231 pub fn start_aneg(&mut self) -> Result { in start_aneg()
238 /// Resumes the PHY via `BMCR_PDOWN` bit.
239 pub fn genphy_resume(&mut self) -> Result { in genphy_resume()
246 /// Suspends the PHY via `BMCR_PDOWN` bit.
247 pub fn genphy_suspend(&mut self) -> Result { 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()
268 pub fn genphy_read_lpa(&mut self) -> Result { in genphy_read_lpa()
275 /// Reads PHY abilities.
276 pub fn genphy_read_abilities(&mut self) -> Result { in genphy_read_abilities()
284 impl AsRef<kernel::device::Device> for Device { implementation
285 fn as_ref(&self) -> &kernel::device::Device { in as_ref() argument
288 unsafe { kernel::device::Device::as_ref(addr_of_mut!((*phydev).mdio.dev)) } in as_ref()
292 /// Defines certain other features this PHY supports (like interrupts).
296 /// PHY is internal.
298 /// PHY needs to be reset after the refclk is enabled.
300 /// Polling is used to detect PHY status changes.
306 /// An adapter for the registration of a PHY driver.
317 ) -> core::ffi::c_int { in soft_reset_callback()
320 // where we hold `phy_device->lock`, so the accessors on in soft_reset_callback()
321 // `Device` are okay to call. in soft_reset_callback()
322 let dev = unsafe { Device::from_raw(phydev) }; in soft_reset_callback()
331 unsafe extern "C" fn probe_callback(phydev: *mut bindings::phy_device) -> core::ffi::c_int { in probe_callback()
335 // it's not published yet, so the accessors on `Device` are okay in probe_callback()
337 let dev = unsafe { Device::from_raw(phydev) }; in probe_callback()
348 ) -> core::ffi::c_int { in get_features_callback()
351 // where we hold `phy_device->lock`, so the accessors on in get_features_callback()
352 // `Device` are okay to call. in get_features_callback()
353 let dev = unsafe { Device::from_raw(phydev) }; in get_features_callback()
362 unsafe extern "C" fn suspend_callback(phydev: *mut bindings::phy_device) -> core::ffi::c_int { in suspend_callback()
365 // `Device` are okay to call even though `phy_device->lock` in suspend_callback()
367 let dev = unsafe { Device::from_raw(phydev) }; in suspend_callback()
376 unsafe extern "C" fn resume_callback(phydev: *mut bindings::phy_device) -> core::ffi::c_int { in resume_callback()
379 // `Device` are okay to call even though `phy_device->lock` in resume_callback()
381 let dev = unsafe { Device::from_raw(phydev) }; in resume_callback()
392 ) -> core::ffi::c_int { in config_aneg_callback()
395 // where we hold `phy_device->lock`, so the accessors on in config_aneg_callback()
396 // `Device` are okay to call. in config_aneg_callback()
397 let dev = unsafe { Device::from_raw(phydev) }; in config_aneg_callback()
408 ) -> core::ffi::c_int { in read_status_callback()
411 // where we hold `phy_device->lock`, so the accessors on in read_status_callback()
412 // `Device` are okay to call. in read_status_callback()
413 let dev = unsafe { Device::from_raw(phydev) }; in read_status_callback()
424 ) -> core::ffi::c_int { in match_phy_device_callback()
426 // where we hold `phy_device->lock`, so the accessors on in match_phy_device_callback()
427 // `Device` are okay to call. in match_phy_device_callback()
428 let dev = unsafe { Device::from_raw(phydev) }; in match_phy_device_callback()
439 ) -> i32 { in read_mmd_callback()
442 // where we hold `phy_device->lock`, so the accessors on in read_mmd_callback()
443 // `Device` are okay to call. in read_mmd_callback()
444 let dev = unsafe { Device::from_raw(phydev) }; in read_mmd_callback()
459 ) -> i32 { in write_mmd_callback()
462 // where we hold `phy_device->lock`, so the accessors on in write_mmd_callback()
463 // `Device` are okay to call. in write_mmd_callback()
464 let dev = unsafe { Device::from_raw(phydev) }; in write_mmd_callback()
475 // where we hold `phy_device->lock`, so the accessors on in link_change_notify_callback()
476 // `Device` are okay to call. in link_change_notify_callback()
477 let dev = unsafe { Device::from_raw(phydev) }; 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
504 pub const fn create_phy_driver<T: Driver>() -> DriverVTable { 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() argument
636 fn write_mmd(_dev: &mut Device, _devnum: u8, _regnum: u16, _val: u16) -> Result { in write_mmd() argument
641 fn link_change_notify(_dev: &mut Device) {} in link_change_notify() argument
644 /// Registration structure for PHY drivers.
660 /// Registers a PHY driver.
664 ) -> Result<Self> { in register()
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()
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 ThisModule) -> Result<Self> {
842 /// let mut reg = ::kernel::net::phy::Registration::register(
888 _reg: $crate::net::phy::Registration,
897 static mut DRIVERS: [$crate::net::phy::DriverVTable;
899 [$($crate::net::phy::create_phy_driver::<$driver>()),+];
902 fn init(module: &'static ThisModule) -> Result<Self> {
906 let mut reg = $crate::net::phy::Registration::register(