Lines Matching +full:ethernet +full:- +full:phy +full:- +full:package

1 /* SPDX-License-Identifier: GPL-2.0-or-later */
4 * Based on code in sungem_phy.c and (long-removed) gianfar_phy.c
56 * Set phydev->irq to PHY_POLL if interrupts are not supported,
57 * or not desired for this PHY. Set to PHY_MAC_INTERRUPT if
60 #define PHY_POLL -1
61 #define PHY_MAC_INTERRUPT -2
70 * enum phy_interface_t - Interface Mode definitions
72 * @PHY_INTERFACE_MODE_NA: Not Applicable - don't touch
73 * @PHY_INTERFACE_MODE_INTERNAL: No interface, MAC and PHY combined
74 * @PHY_INTERFACE_MODE_MII: Media-independent interface
75 * @PHY_INTERFACE_MODE_GMII: Gigabit media-independent interface
76 * @PHY_INTERFACE_MODE_SGMII: Serial gigabit media-independent interface
80 * @PHY_INTERFACE_MODE_REVRMII: Reduced Media Independent Interface in PHY role
81 * @PHY_INTERFACE_MODE_RGMII: Reduced gigabit media-independent interface
87 * @PHY_INTERFACE_MODE_XGMII: 10 gigabit media-independent interface
88 * @PHY_INTERFACE_MODE_XLGMII:40 gigabit media-independent interface
102 * @PHY_INTERFACE_MODE_10GKR: 10GBASE-KR - with Clause 73 AN
104 * @PHY_INTERFACE_MODE_1000BASEKX: 1000Base-KX - with Clause 73 AN
105 * @PHY_INTERFACE_MODE_10G_QXGMII: 10G-QXGMII - 4 ports over 10G USXGMII
108 * Describes the interface between the MAC and PHY.
138 /* 10GBASE-R, XFI, SFI - single lane 10G Serdes */
142 /* 10GBASE-KR - with Clause 73 AN */
150 /* PHY interface mode bitmap handling */
185 * phy_modes - map phy_interface_t enum to device tree binding of phy-mode
189 * into the device tree binding of 'phy-mode', so that Ethernet
190 * device driver can get PHY interface from device tree.
208 return "rev-mii"; in phy_modes()
212 return "rev-rmii"; in phy_modes()
216 return "rgmii-id"; in phy_modes()
218 return "rgmii-rxid"; in phy_modes()
220 return "rgmii-txid"; in phy_modes()
238 return "1000base-x"; in phy_modes()
240 return "1000base-kx"; in phy_modes()
242 return "2500base-x"; in phy_modes()
244 return "5gbase-r"; in phy_modes()
250 return "10gbase-r"; in phy_modes()
252 return "25gbase-r"; in phy_modes()
256 return "10gbase-kr"; in phy_modes()
258 return "100base-x"; in phy_modes()
262 return "10g-qxgmii"; in phy_modes()
269 * rgmii_clock - map link speed to the clock rate
287 return -EINVAL; in rgmii_clock()
293 /* Used when trying to connect to a specific phy (mii bus id:phy device id) */
307 * struct mdio_bus_stats - Statistics counters for MDIO busses
324 * struct mii_bus - Represents an MDIO bus
376 /** @phy_mask: PHY addresses to be ignored when probing */
379 /** @phy_ignore_ta_mask: PHY addresses to ignore the TA/read failure */
383 * @irq: An array of interrupts, each PHY's interrupt at the index
406 * mdiobus_alloc - Allocate an MDIO bus structure
438 * enum phy_state - PHY state machine states:
440 * @PHY_DOWN: PHY device and driver are not ready for anything. probe
441 * should be called if and only if the PHY is in this state,
442 * given that the PHY device exists.
443 * - PHY driver probe function will set the state to @PHY_READY
445 * @PHY_READY: PHY is ready to send and receive packets, but the
448 * - start will set the state to UP
450 * @PHY_UP: The PHY and attached device are ready to do work.
452 * - timer moves to @PHY_NOLINK or @PHY_RUNNING
454 * @PHY_NOLINK: PHY is up, but not currently plugged in.
455 * - irq or timer will set @PHY_RUNNING if link comes back
456 * - phy_stop moves to @PHY_HALTED
458 * @PHY_RUNNING: PHY is currently up, running, and possibly sending
460 * - irq or timer will set @PHY_NOLINK if link goes down
461 * - phy_stop moves to @PHY_HALTED
463 * @PHY_CABLETEST: PHY is performing a cable test. Packet reception/sending
464 * is not expected to work, carrier will be indicated as down. PHY will be
466 * Once complete, move to UP to restart the PHY.
467 * - phy_stop aborts the running test and moves to @PHY_HALTED
469 * @PHY_HALTED: PHY is up, but no polling or interrupts are done.
470 * - phy_start moves to @PHY_UP
472 * @PHY_ERROR: PHY is up, but is in an error state.
473 * - phy_stop moves to @PHY_HALTED
489 * struct phy_c45_device_ids - 802.3-c45 Device Identifiers
490 * @devices_in_package: IEEE 802.3 devices in package register value.
504 * struct phy_device - An instance of a PHY
506 * @mdio: MDIO bus this PHY is on
507 * @drv: Pointer to the driver for this PHY instance
508 * @devlink: Create a link between phy dev and mac dev, if the external phy
510 * @phyindex: Unique id across the phy's parent tree of phys to address the PHY
511 * from userspace, similar to ifindex. A zero index means the PHY
514 * @c45_ids: 802.3-c45 Device Identifiers if is_c45.
515 * @is_c45: Set to true if this PHY uses clause 45 addressing.
516 * @is_internal: Set to true if this PHY is internal to a MAC.
517 * @is_pseudo_fixed_link: Set to true if this PHY is an Ethernet switch, etc.
518 * @is_gigabit_capable: Set to true if PHY supports 1000Mbps
519 * @has_fixups: Set to true if this PHY has fixups/quirks.
520 * @suspended: Set to true if this PHY has been suspended successfully.
521 * @suspended_by_mdio_bus: Set to true if this PHY was suspended by MDIO bus.
523 * @loopback_enabled: Set true if this PHY has been loopbacked successfully.
525 * @is_on_sfp_module: Set true if PHY is located on an SFP module.
526 * @mac_managed_pm: Set true if MAC driver takes of suspending/resuming PHY
527 * @wol_enabled: Set to true if the PHY or the attached MAC have Wake-on-LAN
529 * @state: State of the PHY for management purposes
530 * @dev_flags: Device-specific flags used by the PHY driver.
532 * - Bits [15:0] are free to use by the PHY driver to communicate
534 * - Bits [23:16] are currently reserved for future use.
535 * - Bits [31:24] are reserved for defining generic
536 * PHY driver behavior.
537 * @irq: IRQ number of the PHY's interrupt (-1 if none)
538 * @phylink: Pointer to phylink instance for this PHY
540 * @sfp_bus: SFP bus attached to this PHY's fiber port
552 * @supported: Combined MAC/PHY supported linkmodes
555 * @supported_eee: supported PHY EEE linkmodes
557 * @enable_tx_lpi: When True, MAC should transmit LPI to PHY
561 * @host_interfaces: PHY interface modes supported by host
562 * @eee_disabled_modes: Energy efficient ethernet modes not to be advertised
571 * @irq_suspended: Flag indicating PHY is suspended and therefore interrupt
572 * handling shall be postponed until PHY has resumed
573 * @irq_rerun: Flag indicating interrupts occurred while PHY was suspended,
575 * @default_timestamp: Flag indicating whether we are using the phy
578 * @possible_interfaces: bitmap if interface modes that the attached PHY
587 * @leds: list of PHY LED structures
593 * @lock: Mutex for serialization access to PHY
596 * @shared: Pointer to private data shared by phys in one package
604 * handling, as well as handling shifts in PHY hardware state
609 /* Information about the PHY type */
667 /* Union of PHY and Attached devices' supported link modes */
677 /* Energy efficient ethernet modes which should be prohibited */
683 /* Host supported PHY interface types. Should be ignored if empty. */
696 * Interrupt number for this PHY
697 * -1 means no interrupt
706 /* For use by PHYs inside the same package that need a shared state. */
753 * struct phy_tdr_config - Configuration of a TDR raw test
771 #define PHY_PAIR_ALL -1
774 * enum link_inband_signalling - in-band signalling modes that are supported
776 * @LINK_INBAND_DISABLE: in-band signalling can be disabled
777 * @LINK_INBAND_ENABLE: in-band signalling can be enabled without bypass
778 * @LINK_INBAND_BYPASS: in-band signalling can be enabled with bypass
792 * struct phy_plca_cfg - Configuration of the PLCA (Physical Layer Collision
795 * @version: read-only PLCA register map version. -1 = not available. Ignored
797 * IDVER register (31.CA00). -1 = not available.
798 * @enabled: PLCA configured mode (enabled/disabled). -1 = not available / don't
800 * @node_id: the PLCA local node identifier. -1 = not available / don't set.
803 * meaningful for the coordinator (node_id = 0). -1 = not available / don't
805 * @to_tmr: The value of the PLCA to_timer in bit-times, which determines the
808 * -1 = not available / don't set. Allowed values [0 .. 255].
812 * per TO, and so on. -1 = not available / don't set.
816 * greater than the MAC inter-packet gap (which is typically 96 bits).
817 * -1 = not available / don't set. Allowed values [0 .. 255].
834 * struct phy_plca_status - Status of the PLCA (Physical Layer Collision
848 /* Modes for PHY LED configuration */
859 * struct phy_led: An LED driven by the PHY
862 * @phydev: PHY this LED is attached to
876 * struct phy_driver - Driver structure for a particular PHY type
879 * @phy_id: The result of reading the UID registers of this PHY
882 * @name: The friendly name of this PHY type
885 * supported by this PHY
886 * @flags: A bitfield defining certain other features this PHY
891 * are not implemented, the phy core uses the genphy versions.
908 * @soft_reset: Called to issue a PHY software reset
913 * @config_init: Called to initialize the PHY,
920 * up device-specific structures, if any
926 * abilities it has. Should only set phydev->supported.
931 * @inband_caps: query whether in-band is supported for the given PHY
939 * @config_inband: configure in-band mode for the PHY
945 * particular phy interface. This is used by phy consumers to determine
946 * whether to advertise lower-speed modes for that interface. It is
949 * supported by the phy. If the interface is not supported, this should
955 /* PHY Power Management */
963 * autonegotiation if phydev->autoneg is on,
965 * if phydev->autoneg is off
996 * @set_wol: Some devices (e.g. qnap TS-119P II) require PHY
998 * provided to be called in the ethernet driver's set_wol
1010 * @link_change_notify: Called to inform a PHY device driver
1015 * PHY device structure in their implementations.
1020 * @read_mmd: PHY specific driver override for reading a MMD
1021 * register. This function is optional for PHY specific
1026 * PHY device, regnum is the register within the selected MMD
1032 * @write_mmd: PHY specific driver override for writing a MMD
1033 * register. This function is optional for PHY specific
1038 * PHY device, regnum is the register within the selected MMD
1044 /** @read_page: Return the current PHY register page number */
1046 /** @write_page: Set the current PHY register page number */
1051 * within a plug-in module
1057 * @module_eeprom: Get the eeprom information from the plug-in
1076 /* Get statistics from the PHY using ethtool */
1078 * @get_phy_stats: Retrieve PHY statistics.
1079 * @dev: The PHY device for which the statistics are retrieved.
1080 * @eth_stats: structure where Ethernet PHY stats will be stored.
1081 * @stats: structure where additional PHY-specific stats will be stored.
1083 * Retrieves the supported PHY statistics and populates the provided
1084 * structures. The input structures are pre-initialized with
1095 * @dev: The PHY device for which the statistics are retrieved.
1096 * @link_stats: structure where link-specific stats will be stored.
1098 * Retrieves link-related statistics for the given PHY device. The input
1099 * structure is pre-initialized with `ETHTOOL_STAT_NOT_SET`, and the
1109 * @dev: The PHY device for which statistics updates are triggered.
1111 * Periodically gathers statistics from the PHY device to update locally
1112 * maintained 64-bit counters. This is necessary for PHYs that implement
1113 * reduced-width counters (e.g., 16-bit or 32-bit) which can overflow
1114 * more frequently compared to 64-bit counters. By invoking this
1116 * overflow detection, and accumulate the results into local 64-bit
1132 /* Get and Set PHY tunables */
1141 * @set_loopback: Set the loopback mode of the PHY
1167 * @led_brightness_set: Set a PHY LED brightness. Index
1176 * @led_blink_set: Set a PHY LED blinking. Index indicates
1188 * @dev: PHY device which has the LED
1189 * @index: Which LED of the PHY device
1192 * Return 0 if yes, -EOPNOTSUPP if not, or an error code.
1198 * @dev: PHY device which has the LED
1199 * @index: Which LED of the PHY device
1208 * @dev: PHY device which has the LED
1209 * @index: Which LED of the PHY device
1221 * @dev: PHY device which has the LED
1222 * @index: Which LED of the PHY device
1235 * @dev: PHY device
1238 * update event for the PHY state machine. Allows PHY drivers to
1254 * phy_id_compare - compare @id1 with @id2 taking account of @mask
1255 * @id1: first PHY ID
1256 * @id2: second PHY ID
1257 * @mask: the PHY ID mask, set bits are significant in matching
1268 * phydev_id_compare - compare @id with the PHY's Clause 22 ID
1269 * @phydev: the PHY device
1270 * @id: the PHY ID to be matched
1278 return phy_id_compare(id, phydev->phy_id, phydev->drv->phy_id_mask); in phydev_id_compare()
1288 * phy_is_started - Convenience function to check whether PHY is started
1293 return phydev->state >= PHY_UP; in phy_is_started()
1297 * phy_disable_eee_mode - Don't advertise an EEE mode.
1305 linkmode_set_bit(link_mode, phydev->eee_disabled_modes); in phy_disable_eee_mode()
1306 linkmode_clear_bit(link_mode, phydev->advertising_eee); in phy_disable_eee_mode()
1313 * phy_read - Convenience function for reading a given PHY register
1323 return mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, regnum); in phy_read()
1341 * __phy_read - convenience function for reading a given PHY register
1349 return __mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, regnum); in __phy_read()
1353 * phy_write - Convenience function for writing a given PHY register
1364 return mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, regnum, val); in phy_write()
1368 * __phy_write - Convenience function for writing a given PHY register
1377 return __mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, regnum, in __phy_write()
1382 * __phy_modify_changed() - Convenience function for modifying a PHY register
1388 * Unlocked helper function which allows a PHY register to be modified as
1396 return __mdiobus_modify_changed(phydev->mdio.bus, phydev->mdio.addr, in __phy_modify_changed()
1401 * phy_read_mmd - Convenience function for reading a register
1402 * from an MMD on a given PHY.
1407 * phy_read_mmd_poll_timeout - Periodically poll a PHY register until a
1415 * @sleep_us: Maximum time to sleep between reads in us (0 tight-loops). Please
1421 * Returns: 0 on success and -ETIMEDOUT upon a timeout. In either
1441 * __phy_read_mmd - Convenience function for reading a register
1442 * from an MMD on a given PHY.
1447 * phy_write_mmd - Convenience function for writing a register
1448 * on an MMD on a given PHY.
1453 * __phy_write_mmd - Convenience function for writing a register
1454 * on an MMD on a given PHY.
1475 * __phy_set_bits - Convenience function for setting bits in a PHY register
1488 * __phy_clear_bits - Convenience function for clearing bits in a PHY register
1502 * phy_set_bits - Convenience function for setting bits in a PHY register
1513 * phy_clear_bits - Convenience function for clearing bits in a PHY register
1524 * __phy_set_bits_mmd - Convenience function for setting bits in a register
1540 * __phy_clear_bits_mmd - Convenience function for clearing bits in a register
1556 * phy_set_bits_mmd - Convenience function for setting bits in a register
1570 * phy_clear_bits_mmd - Convenience function for clearing bits in a register
1584 * phy_interrupt_is_valid - Convenience function for testing a given PHY irq
1592 return phydev->irq != PHY_POLL && phydev->irq != PHY_MAC_INTERRUPT; in phy_interrupt_is_valid()
1596 * phy_polling_mode - Convenience function for testing whether polling is
1597 * used to detect PHY status changes
1602 if (phydev->state == PHY_CABLETEST) in phy_polling_mode()
1603 if (phydev->drv->flags & PHY_POLL_CABLE_TEST) in phy_polling_mode()
1606 if (phydev->drv->update_stats) in phy_polling_mode()
1609 return phydev->irq == PHY_POLL; in phy_polling_mode()
1613 * phy_has_hwtstamp - Tests whether a PHY time stamp configuration.
1618 return phydev && phydev->mii_ts && phydev->mii_ts->hwtstamp; in phy_has_hwtstamp()
1622 * phy_has_rxtstamp - Tests whether a PHY supports receive time stamping.
1627 return phydev && phydev->mii_ts && phydev->mii_ts->rxtstamp; in phy_has_rxtstamp()
1631 * phy_has_tsinfo - Tests whether a PHY reports time stamping and/or
1637 return phydev && phydev->mii_ts && phydev->mii_ts->ts_info; in phy_has_tsinfo()
1641 * phy_has_txtstamp - Tests whether a PHY supports transmit time stamping.
1646 return phydev && phydev->mii_ts && phydev->mii_ts->txtstamp; in phy_has_txtstamp()
1653 return phydev->mii_ts->hwtstamp(phydev->mii_ts, cfg, extack); in phy_hwtstamp()
1659 return phydev->mii_ts->rxtstamp(phydev->mii_ts, skb, type); in phy_rxtstamp()
1665 return phydev->mii_ts->ts_info(phydev->mii_ts, tsinfo); in phy_ts_info()
1671 phydev->mii_ts->txtstamp(phydev->mii_ts, skb, type); in phy_txtstamp()
1675 * phy_is_default_hwtstamp - Is the PHY hwtstamp the default timestamp
1682 * Return: True if phy is the default hw timestamp, false otherwise.
1686 return phy_has_hwtstamp(phydev) && phydev->default_timestamp; in phy_is_default_hwtstamp()
1690 * phy_on_sfp - Convenience function for testing if a PHY is on an SFP module
1695 return phydev->is_on_sfp_module; in phy_on_sfp()
1699 * phy_interface_mode_is_rgmii - Convenience function for testing if a
1700 * PHY interface mode is RGMII (all variants)
1710 * phy_interface_mode_is_8023z() - does the PHY interface mode use 802.3z
1714 * Returns true if the PHY interface mode uses the 16-bit negotiation
1715 * word as defined in 802.3z. (See 802.3-2015 37.2.1 Config_Reg encoding)
1724 * phy_interface_is_rgmii - Convenience function for testing if a PHY interface
1730 return phy_interface_mode_is_rgmii(phydev->interface); in phy_interface_is_rgmii()
1734 * phy_is_pseudo_fixed_link - Convenience function for testing if this
1735 * PHY is the CPU port facing side of an Ethernet switch, or similar.
1740 return phydev->is_pseudo_fixed_link; in phy_is_pseudo_fixed_link()
1763 int phy_device_register(struct phy_device *phy);
1799 static inline int phy_device_register(struct phy_device *phy) in phy_device_register() argument
1813 int phy_sfp_connect_phy(void *upstream, struct phy_device *phy);
1814 void phy_sfp_disconnect_phy(void *upstream, struct phy_device *phy);
1860 return -EOPNOTSUPP; in phy_start_cable_test()
1868 return -EOPNOTSUPP; in phy_start_cable_test_tdr()
1874 mdio_device_reset(&phydev->mdio, value); in phy_device_reset()
1878 dev_err(&_phydev->mdio.dev, format, ##args)
1881 dev_err_probe(&_phydev->mdio.dev, err, format, ##args)
1884 dev_info(&_phydev->mdio.dev, format, ##args)
1887 dev_warn(&_phydev->mdio.dev, format, ##args)
1890 dev_dbg(&_phydev->mdio.dev, format, ##args)
1894 return dev_name(&phydev->mdio.dev); in phydev_name()
1899 mutex_lock(&phydev->mdio.bus->mdio_lock); in phy_lock_mdio_bus()
1904 mutex_unlock(&phydev->mdio.bus->mdio_lock); in phy_unlock_mdio_bus()
1913 /* Clause 22 PHY */
1949 /* Clause 45 PHY */
1986 /* Generic C45 PHY driver */
1994 if (!phydev->drv) in phy_read_status()
1995 return -EIO; in phy_read_status()
1997 if (phydev->drv->read_status) in phy_read_status()
1998 return phydev->drv->read_status(phydev); in phy_read_status()
2126 * phy_module_driver() - Helper macro for registering PHY drivers
2127 * @__phy_drivers: array of PHY drivers to register
2130 * Helper macro for PHY drivers which do not do anything special in module