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
82 * Set phydev->irq to PHY_POLL if interrupts are not supported,
83 * or not desired for this PHY. Set to PHY_MAC_INTERRUPT if
86 #define PHY_POLL -1
87 #define PHY_MAC_INTERRUPT -2
96 * enum phy_interface_t - Interface Mode definitions
98 * @PHY_INTERFACE_MODE_NA: Not Applicable - don't touch
99 * @PHY_INTERFACE_MODE_INTERNAL: No interface, MAC and PHY combined
100 * @PHY_INTERFACE_MODE_MII: Media-independent interface
101 * @PHY_INTERFACE_MODE_GMII: Gigabit media-independent interface
102 * @PHY_INTERFACE_MODE_SGMII: Serial gigabit media-independent interface
106 * @PHY_INTERFACE_MODE_REVRMII: Reduced Media Independent Interface in PHY role
107 * @PHY_INTERFACE_MODE_RGMII: Reduced gigabit media-independent interface
113 * @PHY_INTERFACE_MODE_XGMII: 10 gigabit media-independent interface
114 * @PHY_INTERFACE_MODE_XLGMII:40 gigabit media-independent interface
128 * @PHY_INTERFACE_MODE_10GKR: 10GBASE-KR - with Clause 73 AN
130 * @PHY_INTERFACE_MODE_1000BASEKX: 1000Base-KX - with Clause 73 AN
131 * @PHY_INTERFACE_MODE_10G_QXGMII: 10G-QXGMII - 4 ports over 10G USXGMII
134 * Describes the interface between the MAC and PHY.
164 /* 10GBASE-R, XFI, SFI - single lane 10G Serdes */
168 /* 10GBASE-KR - with Clause 73 AN */
176 /* PHY interface mode bitmap handling */
211 * phy_supported_speeds - return all speeds currently supported by a PHY device
213 unsigned int phy_supported_speeds(struct phy_device *phy,
218 * phy_modes - map phy_interface_t enum to device tree binding of phy-mode
222 * into the device tree binding of 'phy-mode', so that Ethernet
223 * device driver can get PHY interface from device tree.
241 return "rev-mii"; in phy_modes()
245 return "rev-rmii"; in phy_modes()
249 return "rgmii-id"; in phy_modes()
251 return "rgmii-rxid"; in phy_modes()
253 return "rgmii-txid"; in phy_modes()
271 return "1000base-x"; in phy_modes()
273 return "1000base-kx"; in phy_modes()
275 return "2500base-x"; in phy_modes()
277 return "5gbase-r"; in phy_modes()
283 return "10gbase-r"; in phy_modes()
285 return "25gbase-r"; in phy_modes()
289 return "10gbase-kr"; in phy_modes()
291 return "100base-x"; in phy_modes()
295 return "10g-qxgmii"; in phy_modes()
306 /* Used when trying to connect to a specific phy (mii bus id:phy device id) */
319 * struct mdio_bus_stats - Statistics counters for MDIO busses
336 * struct phy_package_shared - Shared information in PHY packages
337 * @base_addr: Base PHY address of PHY package used to combine PHYs
338 * in one package and for offset calculation of phy_package_read/write
339 * @np: Pointer to the Device Node if PHY package defined in DT
341 * @flags: Initialization of PHY package
343 * @priv: Driver private data shared across a PHY package
346 * package, for example a quad PHY. See phy_package_join() and
351 /* With PHY package defined in DT this points to the PHY package node */
371 * struct mii_bus - Represents an MDIO bus
423 /** @phy_mask: PHY addresses to be ignored when probing */
426 /** @phy_ignore_ta_mask: PHY addresses to ignore the TA/read failure */
430 * @irq: An array of interrupts, each PHY's interrupt at the index
453 * mdiobus_alloc - Allocate an MDIO bus structure
485 * enum phy_state - PHY state machine states:
487 * @PHY_DOWN: PHY device and driver are not ready for anything. probe
488 * should be called if and only if the PHY is in this state,
489 * given that the PHY device exists.
490 * - PHY driver probe function will set the state to @PHY_READY
492 * @PHY_READY: PHY is ready to send and receive packets, but the
495 * - start will set the state to UP
497 * @PHY_UP: The PHY and attached device are ready to do work.
499 * - timer moves to @PHY_NOLINK or @PHY_RUNNING
501 * @PHY_NOLINK: PHY is up, but not currently plugged in.
502 * - irq or timer will set @PHY_RUNNING if link comes back
503 * - phy_stop moves to @PHY_HALTED
505 * @PHY_RUNNING: PHY is currently up, running, and possibly sending
507 * - irq or timer will set @PHY_NOLINK if link goes down
508 * - phy_stop moves to @PHY_HALTED
510 * @PHY_CABLETEST: PHY is performing a cable test. Packet reception/sending
511 * is not expected to work, carrier will be indicated as down. PHY will be
513 * Once complete, move to UP to restart the PHY.
514 * - phy_stop aborts the running test and moves to @PHY_HALTED
516 * @PHY_HALTED: PHY is up, but no polling or interrupts are done.
517 * - phy_start moves to @PHY_UP
519 * @PHY_ERROR: PHY is up, but is in an error state.
520 * - phy_stop moves to @PHY_HALTED
536 * struct phy_c45_device_ids - 802.3-c45 Device Identifiers
537 * @devices_in_package: IEEE 802.3 devices in package register value.
551 * struct phy_device - An instance of a PHY
553 * @mdio: MDIO bus this PHY is on
554 * @drv: Pointer to the driver for this PHY instance
555 * @devlink: Create a link between phy dev and mac dev, if the external phy
557 * @phyindex: Unique id across the phy's parent tree of phys to address the PHY
558 * from userspace, similar to ifindex. A zero index means the PHY
561 * @c45_ids: 802.3-c45 Device Identifiers if is_c45.
562 * @is_c45: Set to true if this PHY uses clause 45 addressing.
563 * @is_internal: Set to true if this PHY is internal to a MAC.
564 * @is_pseudo_fixed_link: Set to true if this PHY is an Ethernet switch, etc.
565 * @is_gigabit_capable: Set to true if PHY supports 1000Mbps
566 * @has_fixups: Set to true if this PHY has fixups/quirks.
567 * @suspended: Set to true if this PHY has been suspended successfully.
568 * @suspended_by_mdio_bus: Set to true if this PHY was suspended by MDIO bus.
570 * @loopback_enabled: Set true if this PHY has been loopbacked successfully.
572 * @is_on_sfp_module: Set true if PHY is located on an SFP module.
573 * @mac_managed_pm: Set true if MAC driver takes of suspending/resuming PHY
574 * @wol_enabled: Set to true if the PHY or the attached MAC have Wake-on-LAN
576 * @state: State of the PHY for management purposes
577 * @dev_flags: Device-specific flags used by the PHY driver.
579 * - Bits [15:0] are free to use by the PHY driver to communicate
581 * - Bits [23:16] are currently reserved for future use.
582 * - Bits [31:24] are reserved for defining generic
583 * PHY driver behavior.
584 * @irq: IRQ number of the PHY's interrupt (-1 if none)
585 * @phylink: Pointer to phylink instance for this PHY
587 * @sfp_bus: SFP bus attached to this PHY's fiber port
599 * @supported: Combined MAC/PHY supported linkmodes
602 * @supported_eee: supported PHY EEE linkmodes
605 * @enable_tx_lpi: When True, MAC should transmit LPI to PHY
608 * @host_interfaces: PHY interface modes supported by host
609 * @eee_broken_modes: Energy efficient ethernet modes which should be prohibited
618 * @irq_suspended: Flag indicating PHY is suspended and therefore interrupt
619 * handling shall be postponed until PHY has resumed
620 * @irq_rerun: Flag indicating interrupts occurred while PHY was suspended,
622 * @default_timestamp: Flag indicating whether we are using the phy
625 * @possible_interfaces: bitmap if interface modes that the attached PHY
634 * @leds: list of PHY LED structures
640 * @lock: Mutex for serialization access to PHY
643 * @shared: Pointer to private data shared by phys in one package
651 * handling, as well as handling shifts in PHY hardware state
656 /* Information about the PHY type */
714 /* Union of PHY and Attached devices' supported link modes */
726 /* Host supported PHY interface types. Should be ignored if empty. */
729 /* Energy efficient ethernet modes which should be prohibited */
744 * Interrupt number for this PHY
745 * -1 means no interrupt
754 /* For use by PHYs inside the same package that need a shared state. */
801 * struct phy_tdr_config - Configuration of a TDR raw test
819 #define PHY_PAIR_ALL -1
822 * struct phy_plca_cfg - Configuration of the PLCA (Physical Layer Collision
825 * @version: read-only PLCA register map version. -1 = not available. Ignored
827 * IDVER register (31.CA00). -1 = not available.
828 * @enabled: PLCA configured mode (enabled/disabled). -1 = not available / don't
830 * @node_id: the PLCA local node identifier. -1 = not available / don't set.
833 * meaningful for the coordinator (node_id = 0). -1 = not available / don't
835 * @to_tmr: The value of the PLCA to_timer in bit-times, which determines the
838 * -1 = not available / don't set. Allowed values [0 .. 255].
842 * per TO, and so on. -1 = not available / don't set.
846 * greater than the MAC inter-packet gap (which is typically 96 bits).
847 * -1 = not available / don't set. Allowed values [0 .. 255].
864 * struct phy_plca_status - Status of the PLCA (Physical Layer Collision
878 /* Modes for PHY LED configuration */
888 * struct phy_led: An LED driven by the PHY
891 * @phydev: PHY this LED is attached to
905 * struct phy_driver - Driver structure for a particular PHY type
908 * @phy_id: The result of reading the UID registers of this PHY
911 * @name: The friendly name of this PHY type
914 * supported by this PHY
915 * @flags: A bitfield defining certain other features this PHY
920 * are not implemented, the phy core uses the genphy versions.
937 * @soft_reset: Called to issue a PHY software reset
942 * @config_init: Called to initialize the PHY,
949 * up device-specific structures, if any
955 * abilities it has. Should only set phydev->supported.
961 * particular phy interface. This is used by phy consumers to determine
962 * whether to advertise lower-speed modes for that interface. It is
965 * supported by the phy. If the interface is not supported, this should
971 /* PHY Power Management */
979 * autonegotiation if phydev->autoneg is on,
981 * if phydev->autoneg is off
1012 * @set_wol: Some devices (e.g. qnap TS-119P II) require PHY
1014 * provided to be called in the ethernet driver's set_wol
1026 * @link_change_notify: Called to inform a PHY device driver
1031 * PHY device structure in their implementations.
1036 * @read_mmd: PHY specific driver override for reading a MMD
1037 * register. This function is optional for PHY specific
1042 * PHY device, regnum is the register within the selected MMD
1048 * @write_mmd: PHY specific driver override for writing a MMD
1049 * register. This function is optional for PHY specific
1054 * PHY device, regnum is the register within the selected MMD
1060 /** @read_page: Return the current PHY register page number */
1062 /** @write_page: Set the current PHY register page number */
1067 * within a plug-in module
1073 * @module_eeprom: Get the eeprom information from the plug-in
1092 /* Get statistics from the PHY using ethtool */
1101 /* Get and Set PHY tunables */
1109 /** @set_loopback: Set the loopback mood of the PHY */
1128 * @led_brightness_set: Set a PHY LED brightness. Index
1137 * @led_blink_set: Set a PHY LED blinking. Index indicates
1149 * @dev: PHY device which has the LED
1150 * @index: Which LED of the PHY device
1153 * Return 0 if yes, -EOPNOTSUPP if not, or an error code.
1159 * @dev: PHY device which has the LED
1160 * @index: Which LED of the PHY device
1169 * @dev: PHY device which has the LED
1170 * @index: Which LED of the PHY device
1182 * @dev: PHY device which has the LED
1183 * @index: Which LED of the PHY device
1197 #define PHY_ANY_ID "MATCH ANY PHY"
1205 * phy_id_compare - compare @id1 with @id2 taking account of @mask
1206 * @id1: first PHY ID
1207 * @id2: second PHY ID
1208 * @mask: the PHY ID mask, set bits are significant in matching
1219 * phydev_id_compare - compare @id with the PHY's Clause 22 ID
1220 * @phydev: the PHY device
1221 * @id: the PHY ID to be matched
1229 return phy_id_compare(id, phydev->phy_id, phydev->drv->phy_id_mask); in phydev_id_compare()
1232 /* A Structure for boards to register fixups with the PHY Lib */
1266 * phy_is_started - Convenience function to check whether PHY is started
1271 return phydev->state >= PHY_UP; in phy_is_started()
1279 * phy_read - Convenience function for reading a given PHY register
1289 return mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, regnum); in phy_read()
1307 * __phy_read - convenience function for reading a given PHY register
1315 return __mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, regnum); in __phy_read()
1319 * phy_write - Convenience function for writing a given PHY register
1330 return mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, regnum, val); in phy_write()
1334 * __phy_write - Convenience function for writing a given PHY register
1343 return __mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, regnum, in __phy_write()
1348 * __phy_modify_changed() - Convenience function for modifying a PHY register
1354 * Unlocked helper function which allows a PHY register to be modified as
1362 return __mdiobus_modify_changed(phydev->mdio.bus, phydev->mdio.addr, in __phy_modify_changed()
1367 * phy_read_mmd - Convenience function for reading a register
1368 * from an MMD on a given PHY.
1373 * phy_read_mmd_poll_timeout - Periodically poll a PHY register until a
1382 * tight-loops). Should be less than ~20ms since usleep_range
1383 * is used (see Documentation/timers/timers-howto.rst).
1386 * Returns 0 on success and -ETIMEDOUT upon a timeout. In either
1406 * __phy_read_mmd - Convenience function for reading a register
1407 * from an MMD on a given PHY.
1412 * phy_write_mmd - Convenience function for writing a register
1413 * on an MMD on a given PHY.
1418 * __phy_write_mmd - Convenience function for writing a register
1419 * on an MMD on a given PHY.
1440 * __phy_set_bits - Convenience function for setting bits in a PHY register
1453 * __phy_clear_bits - Convenience function for clearing bits in a PHY register
1467 * phy_set_bits - Convenience function for setting bits in a PHY register
1478 * phy_clear_bits - Convenience function for clearing bits in a PHY register
1489 * __phy_set_bits_mmd - Convenience function for setting bits in a register
1505 * __phy_clear_bits_mmd - Convenience function for clearing bits in a register
1521 * phy_set_bits_mmd - Convenience function for setting bits in a register
1535 * phy_clear_bits_mmd - Convenience function for clearing bits in a register
1549 * phy_interrupt_is_valid - Convenience function for testing a given PHY irq
1557 return phydev->irq != PHY_POLL && phydev->irq != PHY_MAC_INTERRUPT; in phy_interrupt_is_valid()
1561 * phy_polling_mode - Convenience function for testing whether polling is
1562 * used to detect PHY status changes
1567 if (phydev->state == PHY_CABLETEST) in phy_polling_mode()
1568 if (phydev->drv->flags & PHY_POLL_CABLE_TEST) in phy_polling_mode()
1571 return phydev->irq == PHY_POLL; in phy_polling_mode()
1575 * phy_has_hwtstamp - Tests whether a PHY time stamp configuration.
1580 return phydev && phydev->mii_ts && phydev->mii_ts->hwtstamp; in phy_has_hwtstamp()
1584 * phy_has_rxtstamp - Tests whether a PHY supports receive time stamping.
1589 return phydev && phydev->mii_ts && phydev->mii_ts->rxtstamp; in phy_has_rxtstamp()
1593 * phy_has_tsinfo - Tests whether a PHY reports time stamping and/or
1599 return phydev && phydev->mii_ts && phydev->mii_ts->ts_info; in phy_has_tsinfo()
1603 * phy_has_txtstamp - Tests whether a PHY supports transmit time stamping.
1608 return phydev && phydev->mii_ts && phydev->mii_ts->txtstamp; in phy_has_txtstamp()
1615 return phydev->mii_ts->hwtstamp(phydev->mii_ts, cfg, extack); in phy_hwtstamp()
1621 return phydev->mii_ts->rxtstamp(phydev->mii_ts, skb, type); in phy_rxtstamp()
1627 return phydev->mii_ts->ts_info(phydev->mii_ts, tsinfo); in phy_ts_info()
1633 phydev->mii_ts->txtstamp(phydev->mii_ts, skb, type); in phy_txtstamp()
1637 * phy_is_default_hwtstamp - Is the PHY hwtstamp the default timestamp
1644 * Return: True if phy is the default hw timestamp, false otherwise.
1648 return phy_has_hwtstamp(phydev) && phydev->default_timestamp; in phy_is_default_hwtstamp()
1652 * phy_is_internal - Convenience function for testing if a PHY is internal
1657 return phydev->is_internal; in phy_is_internal()
1661 * phy_on_sfp - Convenience function for testing if a PHY is on an SFP module
1666 return phydev->is_on_sfp_module; in phy_on_sfp()
1670 * phy_interface_mode_is_rgmii - Convenience function for testing if a
1671 * PHY interface mode is RGMII (all variants)
1681 * phy_interface_mode_is_8023z() - does the PHY interface mode use 802.3z
1685 * Returns true if the PHY interface mode uses the 16-bit negotiation
1686 * word as defined in 802.3z. (See 802.3-2015 37.2.1 Config_Reg encoding)
1695 * phy_interface_is_rgmii - Convenience function for testing if a PHY interface
1701 return phy_interface_mode_is_rgmii(phydev->interface); in phy_interface_is_rgmii()
1705 * phy_is_pseudo_fixed_link - Convenience function for testing if this
1706 * PHY is the CPU port facing side of an Ethernet switch, or similar.
1711 return phydev->is_pseudo_fixed_link; in phy_is_pseudo_fixed_link()
1734 int phy_device_register(struct phy_device *phy);
1770 static inline int phy_device_register(struct phy_device *phy) in phy_device_register() argument
1784 int phy_sfp_connect_phy(void *upstream, struct phy_device *phy);
1785 void phy_sfp_disconnect_phy(void *upstream, struct phy_device *phy);
1828 return -EOPNOTSUPP; in phy_start_cable_test()
1836 return -EOPNOTSUPP; in phy_start_cable_test_tdr()
1842 mdio_device_reset(&phydev->mdio, value); in phy_device_reset()
1846 dev_err(&_phydev->mdio.dev, format, ##args)
1849 dev_err_probe(&_phydev->mdio.dev, err, format, ##args)
1852 dev_info(&_phydev->mdio.dev, format, ##args)
1855 dev_warn(&_phydev->mdio.dev, format, ##args)
1858 dev_dbg(&_phydev->mdio.dev, format, ##args)
1862 return dev_name(&phydev->mdio.dev); in phydev_name()
1867 mutex_lock(&phydev->mdio.bus->mdio_lock); in phy_lock_mdio_bus()
1872 mutex_unlock(&phydev->mdio.bus->mdio_lock); in phy_unlock_mdio_bus()
1881 /* Clause 22 PHY */
1918 /* Clause 45 PHY */
1958 /* Generic C45 PHY driver */
1966 if (!phydev->drv) in phy_read_status()
1967 return -EIO; in phy_read_status()
1969 if (phydev->drv->read_status) in phy_read_status()
1970 return phydev->drv->read_status(phydev); in phy_read_status()
2075 struct phy_package_shared *shared = phydev->shared; in phy_package_address()
2076 u8 base_addr = shared->base_addr; in phy_package_address()
2078 if (addr_offset >= PHY_MAX_ADDR - base_addr) in phy_package_address()
2079 return -EIO; in phy_package_address()
2095 return mdiobus_read(phydev->mdio.bus, addr, regnum); in phy_package_read()
2106 return __mdiobus_read(phydev->mdio.bus, addr, regnum); in __phy_package_read()
2118 return mdiobus_write(phydev->mdio.bus, addr, regnum, val); in phy_package_write()
2130 return __mdiobus_write(phydev->mdio.bus, addr, regnum, val); in __phy_package_write()
2152 struct phy_package_shared *shared = phydev->shared; in __phy_package_set_once()
2157 return !test_and_set_bit(b, &shared->flags); in __phy_package_set_once()
2192 * phy_module_driver() - Helper macro for registering PHY drivers
2193 * @__phy_drivers: array of PHY drivers to register
2196 * Helper macro for PHY drivers which do not do anything special in module