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`](../../../../../../../include/linux/phy.h).
13 /// PHY state machine states.
17 /// Some of PHY drivers access to the state of PHY's software state machine.
19 /// [`enum phy_state`]: ../../../../../../../include/linux/phy.h
22 /// PHY device and driver are not ready for anything.
24 /// PHY is ready to send and receive packets.
26 /// PHY is up, but no polling or interrupts are done.
28 /// PHY is up, but is in an error state.
30 /// PHY and attached device are ready to do work.
32 /// PHY is currently running.
34 /// PHY is up, but not currently plugged in.
36 /// PHY is performing a cable test.
42 /// PHY drivers get duplex information from hardware and update the current state.
44 /// PHY is in full-duplex mode.
46 /// PHY is in half-duplex mode.
48 /// PHY is in unknown duplex mode.
52 /// An instance of a PHY device.
56 /// A [`Device`] instance is created when a callback in [`Driver`] is executed. A PHY driver
64 /// [`struct phy_device`]: ../../../../../../../include/linux/phy.h
82 unsafe fn from_raw<'a>(ptr: *mut bindings::phy_device) -> &'a mut Self { in from_raw()
90 /// Gets the id of the PHY.
91 pub fn phy_id(&self) -> u32 { in phy_id()
98 /// Gets the state of PHY state machine states.
99 pub fn state(&self) -> DeviceState { in state()
122 pub fn is_link_up(&self) -> bool { in is_link_up()
132 /// Gets the current auto-negotiation configuration.
134 /// It returns true if auto-negotiation is enabled.
135 pub fn is_autoneg_enabled(&self) -> bool { in is_autoneg_enabled()
144 /// Gets the current auto-negotiation state.
146 /// It returns true if auto-negotiation is completed.
147 pub fn is_autoneg_completed(&self) -> bool { in is_autoneg_completed()
157 /// Sets the speed of the PHY.
178 /// Reads a given C22 PHY register.
180 pub fn read(&mut self, regnum: u16) -> Result<u16> { in read()
195 /// Writes a given C22 PHY register.
196 pub fn write(&mut self, regnum: u16, val: u16) -> Result { in write()
207 pub fn read_paged(&mut self, page: u16, regnum: u16) -> Result<u16> { in read_paged()
219 /// Resolves the advertisements into PHY settings.
227 /// Executes software reset the PHY via `BMCR_RESET` bit.
228 pub fn genphy_soft_reset(&mut self) -> Result { in genphy_soft_reset()
235 /// Initializes the PHY.
236 pub fn init_hw(&mut self) -> Result { in init_hw()
243 /// Starts auto-negotiation.
244 pub fn start_aneg(&mut self) -> Result { in start_aneg()
251 /// Resumes the PHY via `BMCR_PDOWN` bit.
252 pub fn genphy_resume(&mut self) -> Result { in genphy_resume()
259 /// Suspends the PHY via `BMCR_PDOWN` bit.
260 pub fn genphy_suspend(&mut self) -> Result { in genphy_suspend()
268 pub fn genphy_read_status(&mut self) -> Result<u16> { in genphy_read_status()
281 pub fn genphy_update_link(&mut self) -> Result { in genphy_update_link()
289 pub fn genphy_read_lpa(&mut self) -> Result { in genphy_read_lpa()
296 /// Reads PHY abilities.
297 pub fn genphy_read_abilities(&mut self) -> Result { in genphy_read_abilities()
305 /// Defines certain other features this PHY supports (like interrupts).
309 /// PHY is internal.
311 /// PHY needs to be reset after the refclk is enabled.
313 /// Polling is used to detect PHY status changes.
315 /// Don't suspend.
319 /// An adapter for the registration of a PHY driver.
320 struct Adapter<T: Driver> {
321 _p: PhantomData<T>,
324 impl<T: Driver> Adapter<T> {
330 ) -> core::ffi::c_int { in soft_reset_callback()
333 // where we hold `phy_device->lock`, so the accessors on in soft_reset_callback()
336 T::soft_reset(dev)?; in soft_reset_callback()
346 ) -> core::ffi::c_int { in get_features_callback()
349 // where we hold `phy_device->lock`, so the accessors on in get_features_callback()
352 T::get_features(dev)?; in get_features_callback()
360 unsafe extern "C" fn suspend_callback(phydev: *mut bindings::phy_device) -> core::ffi::c_int { in suspend_callback()
363 // `Device` are okay to call even though `phy_device->lock` in suspend_callback()
366 T::suspend(dev)?; in suspend_callback()
374 unsafe extern "C" fn resume_callback(phydev: *mut bindings::phy_device) -> core::ffi::c_int { in resume_callback()
377 // `Device` are okay to call even though `phy_device->lock` in resume_callback()
380 T::resume(dev)?; in resume_callback()
390 ) -> core::ffi::c_int { in config_aneg_callback()
393 // where we hold `phy_device->lock`, so the accessors on in config_aneg_callback()
396 T::config_aneg(dev)?; in config_aneg_callback()
406 ) -> core::ffi::c_int { in read_status_callback()
409 // where we hold `phy_device->lock`, so the accessors on in read_status_callback()
412 T::read_status(dev)?; in read_status_callback()
422 ) -> core::ffi::c_int { in match_phy_device_callback()
424 // where we hold `phy_device->lock`, so the accessors on in match_phy_device_callback()
427 T::match_phy_device(dev) as i32 in match_phy_device_callback()
437 ) -> i32 { in read_mmd_callback()
440 // where we hold `phy_device->lock`, so the accessors on in read_mmd_callback()
444 let ret = T::read_mmd(dev, devnum as u8, regnum)?; in read_mmd_callback()
457 ) -> i32 { in write_mmd_callback()
460 // where we hold `phy_device->lock`, so the accessors on in write_mmd_callback()
463 T::write_mmd(dev, devnum as u8, regnum, val)?; in write_mmd_callback()
473 // where we hold `phy_device->lock`, so the accessors on in link_change_notify_callback()
476 T::link_change_notify(dev); in link_change_notify_callback()
480 /// Driver structure for a particular PHY type.
483 /// This is used to register a driver for a particular PHY type with the kernel.
489 /// [`struct phy_driver`]: ../../../../../../../include/linux/phy.h
493 // SAFETY: `DriverVTable` doesn't expose any &self method to access internal data, so it's safe to
502 pub const fn create_phy_driver<T: Driver>() -> DriverVTable { in create_phy_driver()
505 name: T::NAME.as_char_ptr().cast_mut(), in create_phy_driver()
506 flags: T::FLAGS, in create_phy_driver()
507 phy_id: T::PHY_DEVICE_ID.id, in create_phy_driver()
508 phy_id_mask: T::PHY_DEVICE_ID.mask_as_int(), in create_phy_driver()
509 soft_reset: if T::HAS_SOFT_RESET { in create_phy_driver()
510 Some(Adapter::<T>::soft_reset_callback) in create_phy_driver()
514 get_features: if T::HAS_GET_FEATURES { in create_phy_driver()
515 Some(Adapter::<T>::get_features_callback) in create_phy_driver()
519 match_phy_device: if T::HAS_MATCH_PHY_DEVICE { in create_phy_driver()
520 Some(Adapter::<T>::match_phy_device_callback) in create_phy_driver()
524 suspend: if T::HAS_SUSPEND { in create_phy_driver()
525 Some(Adapter::<T>::suspend_callback) in create_phy_driver()
529 resume: if T::HAS_RESUME { in create_phy_driver()
530 Some(Adapter::<T>::resume_callback) in create_phy_driver()
534 config_aneg: if T::HAS_CONFIG_ANEG { in create_phy_driver()
535 Some(Adapter::<T>::config_aneg_callback) in create_phy_driver()
539 read_status: if T::HAS_READ_STATUS { in create_phy_driver()
540 Some(Adapter::<T>::read_status_callback) in create_phy_driver()
544 read_mmd: if T::HAS_READ_MMD { in create_phy_driver()
545 Some(Adapter::<T>::read_mmd_callback) in create_phy_driver()
549 write_mmd: if T::HAS_WRITE_MMD { in create_phy_driver()
550 Some(Adapter::<T>::write_mmd_callback) in create_phy_driver()
554 link_change_notify: if T::HAS_LINK_CHANGE_NOTIFY { in create_phy_driver()
555 Some(Adapter::<T>::link_change_notify_callback) in create_phy_driver()
565 /// Driver implementation for a particular PHY type.
570 /// Defines certain other features this PHY supports.
574 /// The friendly name of this PHY type.
581 /// Issues a PHY software reset.
582 fn soft_reset(_dev: &mut Device) -> Result { in soft_reset()
587 fn get_features(_dev: &mut Device) -> Result { in get_features()
593 fn match_phy_device(_dev: &Device) -> bool { in match_phy_device()
597 /// Configures the advertisement and resets auto-negotiation
598 /// if auto-negotiation is enabled.
599 fn config_aneg(_dev: &mut Device) -> Result { in config_aneg()
604 fn read_status(_dev: &mut Device) -> Result<u16> { in read_status()
609 fn suspend(_dev: &mut Device) -> Result { in suspend()
614 fn resume(_dev: &mut Device) -> Result { in resume()
619 fn read_mmd(_dev: &mut Device, _devnum: u8, _regnum: u16) -> Result<u16> { in read_mmd()
624 fn write_mmd(_dev: &mut Device, _devnum: u8, _regnum: u16, _val: u16) -> Result { in write_mmd()
632 /// Registration structure for PHY drivers.
644 /// Registers a PHY driver.
648 ) -> Result<Self> { in register()
673 /// An identifier for PHY devices on an MDIO/MII bus.
676 /// PHY driver.
684 pub const fn new_with_exact_mask(id: u32) -> Self { in new_with_exact_mask()
692 pub const fn new_with_model_mask(id: u32) -> Self { in new_with_model_mask()
700 pub const fn new_with_vendor_mask(id: u32) -> Self { in new_with_vendor_mask()
708 pub const fn new_with_custom_mask(id: u32, mask: u32) -> Self { in new_with_custom_mask()
716 pub const fn new_with_driver<T: Driver>() -> Self { in new_with_driver()
717 T::PHY_DEVICE_ID in new_with_driver()
721 pub const fn mask_as_int(&self) -> u32 { in mask_as_int()
727 pub const fn mdio_device_id(&self) -> bindings::mdio_device_id { in mdio_device_id()
747 const fn as_int(&self) -> u32 { in as_int()
768 /// use kernel::net::phy::{self, DeviceId};
785 /// impl phy::Driver for PhySample {
787 /// const PHY_DEVICE_ID: phy::DeviceId = phy::DeviceId::new_with_exact_mask(0x00000001);
796 /// use kernel::net::phy::{self, DeviceId};
800 /// _reg: ::kernel::net::phy::Registration,
814 /// impl phy::Driver for PhySample {
816 /// const PHY_DEVICE_ID: phy::DeviceId = phy::DeviceId::new_with_exact_mask(0x00000001);
820 /// static mut DRIVERS: [::kernel::net::phy::DriverVTable; 1] =
821 /// [::kernel::net::phy::create_phy_driver::<PhySample>()];
824 /// fn init(module: &'static ThisModule) -> Result<Self> {
826 /// let mut reg = ::kernel::net::phy::Registration::register(
872 _reg: $crate::net::phy::Registration,
881 static mut DRIVERS: [$crate::net::phy::DriverVTable;
883 [$($crate::net::phy::create_phy_driver::<$driver>()),+];
886 fn init(module: &'static ThisModule) -> Result<Self> {
890 let mut reg = $crate::net::phy::Registration::register(