Lines Matching +full:t +full:- +full:phy

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
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()
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.
298 /// PHY needs to be reset after the refclk is enabled.
300 /// Polling is used to detect PHY status changes.
302 /// Don't suspend.
306 /// An adapter for the registration of a PHY driver.
307 struct Adapter<T: Driver> {
308 _p: PhantomData<T>,
311 impl<T: Driver> Adapter<T> {
317 ) -> core::ffi::c_int { in soft_reset_callback()
320 // where we hold `phy_device->lock`, so the accessors on in soft_reset_callback()
323 T::soft_reset(dev)?; in soft_reset_callback()
331 unsafe extern "C" fn probe_callback(phydev: *mut bindings::phy_device) -> core::ffi::c_int { in probe_callback()
338 T::probe(dev)?; 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()
354 T::get_features(dev)?; 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()
368 T::suspend(dev)?; 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()
382 T::resume(dev)?; 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()
398 T::config_aneg(dev)?; 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()
414 T::read_status(dev)?; 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()
429 T::match_phy_device(dev) as i32 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()
446 let ret = T::read_mmd(dev, devnum as u8, regnum)?; 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()
465 T::write_mmd(dev, devnum as u8, regnum, val)?; in write_mmd_callback()
475 // where we hold `phy_device->lock`, so the accessors on in link_change_notify_callback()
478 T::link_change_notify(dev); 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
495 // SAFETY: `DriverVTable` doesn't expose any &self method to access internal data, so it's safe to
504 pub const fn create_phy_driver<T: Driver>() -> DriverVTable { in create_phy_driver()
507 name: T::NAME.as_char_ptr().cast_mut(), in create_phy_driver()
508 flags: T::FLAGS, in create_phy_driver()
509 phy_id: T::PHY_DEVICE_ID.id, in create_phy_driver()
510 phy_id_mask: T::PHY_DEVICE_ID.mask_as_int(), in create_phy_driver()
511 soft_reset: if T::HAS_SOFT_RESET { in create_phy_driver()
512 Some(Adapter::<T>::soft_reset_callback) in create_phy_driver()
516 probe: if T::HAS_PROBE { in create_phy_driver()
517 Some(Adapter::<T>::probe_callback) in create_phy_driver()
521 get_features: if T::HAS_GET_FEATURES { in create_phy_driver()
522 Some(Adapter::<T>::get_features_callback) in create_phy_driver()
526 match_phy_device: if T::HAS_MATCH_PHY_DEVICE { in create_phy_driver()
527 Some(Adapter::<T>::match_phy_device_callback) in create_phy_driver()
531 suspend: if T::HAS_SUSPEND { in create_phy_driver()
532 Some(Adapter::<T>::suspend_callback) in create_phy_driver()
536 resume: if T::HAS_RESUME { in create_phy_driver()
537 Some(Adapter::<T>::resume_callback) in create_phy_driver()
541 config_aneg: if T::HAS_CONFIG_ANEG { in create_phy_driver()
542 Some(Adapter::<T>::config_aneg_callback) in create_phy_driver()
546 read_status: if T::HAS_READ_STATUS { in create_phy_driver()
547 Some(Adapter::<T>::read_status_callback) in create_phy_driver()
551 read_mmd: if T::HAS_READ_MMD { in create_phy_driver()
552 Some(Adapter::<T>::read_mmd_callback) in create_phy_driver()
556 write_mmd: if T::HAS_WRITE_MMD { in create_phy_driver()
557 Some(Adapter::<T>::write_mmd_callback) in create_phy_driver()
561 link_change_notify: if T::HAS_LINK_CHANGE_NOTIFY { in create_phy_driver()
562 Some(Adapter::<T>::link_change_notify_callback) 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()
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()
733 T::PHY_DEVICE_ID 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(