2 * Framework and drivers for configuring and reading different PHYs
3 * Based on code in sungem_phy.c and gianfar_phy.c
7 * Copyright (c) 2004 Freescale Semiconductor, Inc.
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
19 #include <linux/compiler.h>
20 #include <linux/spinlock.h>
21 #include <linux/ethtool.h>
22 #include <linux/mdio.h>
23 #include <linux/mii.h>
24 #include <linux/module.h>
25 #include <linux/timer.h>
26 #include <linux/workqueue.h>
27 #include <linux/mod_devicetable.h>
29 #include <linux/atomic.h>
31 #define PHY_DEFAULT_FEATURES (SUPPORTED_Autoneg | \
35 #define PHY_10BT_FEATURES (SUPPORTED_10baseT_Half | \
36 SUPPORTED_10baseT_Full)
38 #define PHY_100BT_FEATURES (SUPPORTED_100baseT_Half | \
39 SUPPORTED_100baseT_Full)
41 #define PHY_1000BT_FEATURES (SUPPORTED_1000baseT_Half | \
42 SUPPORTED_1000baseT_Full)
44 #define PHY_BASIC_FEATURES (PHY_10BT_FEATURES | \
45 PHY_100BT_FEATURES | \
48 #define PHY_GBIT_FEATURES (PHY_BASIC_FEATURES | \
53 * Set phydev->irq to PHY_POLL if interrupts are not supported,
54 * or not desired for this PHY. Set to PHY_IGNORE_INTERRUPT if
55 * the attached driver handles the interrupt
58 #define PHY_IGNORE_INTERRUPT -2
60 #define PHY_HAS_INTERRUPT 0x00000001
61 #define PHY_IS_INTERNAL 0x00000002
62 #define MDIO_DEVICE_IS_PHY 0x80000000
64 /* Interface Mode definitions */
66 PHY_INTERFACE_MODE_NA,
67 PHY_INTERFACE_MODE_MII,
68 PHY_INTERFACE_MODE_GMII,
69 PHY_INTERFACE_MODE_SGMII,
70 PHY_INTERFACE_MODE_TBI,
71 PHY_INTERFACE_MODE_REVMII,
72 PHY_INTERFACE_MODE_RMII,
73 PHY_INTERFACE_MODE_RGMII,
74 PHY_INTERFACE_MODE_RGMII_ID,
75 PHY_INTERFACE_MODE_RGMII_RXID,
76 PHY_INTERFACE_MODE_RGMII_TXID,
77 PHY_INTERFACE_MODE_RTBI,
78 PHY_INTERFACE_MODE_SMII,
79 PHY_INTERFACE_MODE_XGMII,
80 PHY_INTERFACE_MODE_MOCA,
81 PHY_INTERFACE_MODE_QSGMII,
82 PHY_INTERFACE_MODE_TRGMII,
83 PHY_INTERFACE_MODE_1000BASEX,
84 PHY_INTERFACE_MODE_2500BASEX,
85 PHY_INTERFACE_MODE_RXAUI,
86 PHY_INTERFACE_MODE_XAUI,
87 /* 10GBASE-KR, XFI, SFI - single lane 10G Serdes */
88 PHY_INTERFACE_MODE_10GKR,
89 PHY_INTERFACE_MODE_MAX,
93 * phy_supported_speeds - return all speeds currently supported by a phy device
94 * @phy: The phy device to return supported speeds of.
95 * @speeds: buffer to store supported speeds in.
96 * @size: size of speeds buffer.
98 * Description: Returns the number of supported speeds, and
99 * fills the speeds * buffer with the supported speeds. If speeds buffer is
100 * too small to contain * all currently supported speeds, will return as
101 * many speeds as can fit.
103 unsigned int phy_supported_speeds(struct phy_device *phy,
104 unsigned int *speeds,
108 * It maps 'enum phy_interface_t' found in include/linux/phy.h
109 * into the device tree binding of 'phy-mode', so that Ethernet
110 * device driver can get phy interface from device tree.
112 static inline const char *phy_modes(phy_interface_t interface)
115 case PHY_INTERFACE_MODE_NA:
117 case PHY_INTERFACE_MODE_MII:
119 case PHY_INTERFACE_MODE_GMII:
121 case PHY_INTERFACE_MODE_SGMII:
123 case PHY_INTERFACE_MODE_TBI:
125 case PHY_INTERFACE_MODE_REVMII:
127 case PHY_INTERFACE_MODE_RMII:
129 case PHY_INTERFACE_MODE_RGMII:
131 case PHY_INTERFACE_MODE_RGMII_ID:
133 case PHY_INTERFACE_MODE_RGMII_RXID:
135 case PHY_INTERFACE_MODE_RGMII_TXID:
137 case PHY_INTERFACE_MODE_RTBI:
139 case PHY_INTERFACE_MODE_SMII:
141 case PHY_INTERFACE_MODE_XGMII:
143 case PHY_INTERFACE_MODE_MOCA:
145 case PHY_INTERFACE_MODE_QSGMII:
147 case PHY_INTERFACE_MODE_TRGMII:
149 case PHY_INTERFACE_MODE_1000BASEX:
151 case PHY_INTERFACE_MODE_2500BASEX:
153 case PHY_INTERFACE_MODE_RXAUI:
155 case PHY_INTERFACE_MODE_XAUI:
157 case PHY_INTERFACE_MODE_10GKR:
165 #define PHY_INIT_TIMEOUT 100000
166 #define PHY_STATE_TIME 1
167 #define PHY_FORCE_TIMEOUT 10
168 #define PHY_AN_TIMEOUT 10
170 #define PHY_MAX_ADDR 32
172 /* Used when trying to connect to a specific phy (mii bus id:phy device id) */
173 #define PHY_ID_FMT "%s:%02x"
175 #define MII_BUS_ID_SIZE 61
177 /* Or MII_ADDR_C45 into regnum for read/write on mii_bus to enable the 21 bit
178 IEEE 802.3ae clause 45 addressing mode used by 10GIGE phy chips. */
179 #define MII_ADDR_C45 (1<<30)
185 * The Bus class for PHYs. Devices which provide access to
186 * PHYs should register using this structure
189 struct module *owner;
191 char id[MII_BUS_ID_SIZE];
193 int (*read)(struct mii_bus *bus, int addr, int regnum);
194 int (*write)(struct mii_bus *bus, int addr, int regnum, u16 val);
195 int (*reset)(struct mii_bus *bus);
198 * A lock to ensure that only one thing can read/write
199 * the MDIO bus at a time
201 struct mutex mdio_lock;
203 struct device *parent;
205 MDIOBUS_ALLOCATED = 1,
207 MDIOBUS_UNREGISTERED,
212 /* list of all PHYs on bus */
213 struct mdio_device *mdio_map[PHY_MAX_ADDR];
215 /* PHY addresses to be ignored when probing */
218 /* PHY addresses to ignore the TA/read failure */
219 u32 phy_ignore_ta_mask;
222 * An array of interrupts, each PHY's interrupt at the index
223 * matching its address
225 int irq[PHY_MAX_ADDR];
227 /* GPIO reset pulse width in microseconds */
229 /* RESET GPIO descriptor pointer */
230 struct gpio_desc *reset_gpiod;
232 #define to_mii_bus(d) container_of(d, struct mii_bus, dev)
234 struct mii_bus *mdiobus_alloc_size(size_t);
235 static inline struct mii_bus *mdiobus_alloc(void)
237 return mdiobus_alloc_size(0);
240 int __mdiobus_register(struct mii_bus *bus, struct module *owner);
241 #define mdiobus_register(bus) __mdiobus_register(bus, THIS_MODULE)
242 void mdiobus_unregister(struct mii_bus *bus);
243 void mdiobus_free(struct mii_bus *bus);
244 struct mii_bus *devm_mdiobus_alloc_size(struct device *dev, int sizeof_priv);
245 static inline struct mii_bus *devm_mdiobus_alloc(struct device *dev)
247 return devm_mdiobus_alloc_size(dev, 0);
250 void devm_mdiobus_free(struct device *dev, struct mii_bus *bus);
251 struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr);
253 #define PHY_INTERRUPT_DISABLED 0x0
254 #define PHY_INTERRUPT_ENABLED 0x80000000
256 /* PHY state machine states:
258 * DOWN: PHY device and driver are not ready for anything. probe
259 * should be called if and only if the PHY is in this state,
260 * given that the PHY device exists.
261 * - PHY driver probe function will, depending on the PHY, set
262 * the state to STARTING or READY
264 * STARTING: PHY device is coming up, and the ethernet driver is
265 * not ready. PHY drivers may set this in the probe function.
266 * If they do, they are responsible for making sure the state is
267 * eventually set to indicate whether the PHY is UP or READY,
268 * depending on the state when the PHY is done starting up.
269 * - PHY driver will set the state to READY
270 * - start will set the state to PENDING
272 * READY: PHY is ready to send and receive packets, but the
273 * controller is not. By default, PHYs which do not implement
274 * probe will be set to this state by phy_probe(). If the PHY
275 * driver knows the PHY is ready, and the PHY state is STARTING,
276 * then it sets this STATE.
277 * - start will set the state to UP
279 * PENDING: PHY device is coming up, but the ethernet driver is
280 * ready. phy_start will set this state if the PHY state is
282 * - PHY driver will set the state to UP when the PHY is ready
284 * UP: The PHY and attached device are ready to do work.
285 * Interrupts should be started here.
286 * - timer moves to AN
288 * AN: The PHY is currently negotiating the link state. Link is
289 * therefore down for now. phy_timer will set this state when it
290 * detects the state is UP. config_aneg will set this state
291 * whenever called with phydev->autoneg set to AUTONEG_ENABLE.
292 * - If autonegotiation finishes, but there's no link, it sets
293 * the state to NOLINK.
294 * - If aneg finishes with link, it sets the state to RUNNING,
295 * and calls adjust_link
296 * - If autonegotiation did not finish after an arbitrary amount
297 * of time, autonegotiation should be tried again if the PHY
298 * supports "magic" autonegotiation (back to AN)
299 * - If it didn't finish, and no magic_aneg, move to FORCING.
301 * NOLINK: PHY is up, but not currently plugged in.
302 * - If the timer notes that the link comes back, we move to RUNNING
303 * - config_aneg moves to AN
304 * - phy_stop moves to HALTED
306 * FORCING: PHY is being configured with forced settings
307 * - if link is up, move to RUNNING
308 * - If link is down, we drop to the next highest setting, and
309 * retry (FORCING) after a timeout
310 * - phy_stop moves to HALTED
312 * RUNNING: PHY is currently up, running, and possibly sending
313 * and/or receiving packets
314 * - timer will set CHANGELINK if we're polling (this ensures the
315 * link state is polled every other cycle of this state machine,
316 * which makes it every other second)
317 * - irq will set CHANGELINK
318 * - config_aneg will set AN
319 * - phy_stop moves to HALTED
321 * CHANGELINK: PHY experienced a change in link state
322 * - timer moves to RUNNING if link
323 * - timer moves to NOLINK if the link is down
324 * - phy_stop moves to HALTED
326 * HALTED: PHY is up, but no polling or interrupts are done. Or
327 * PHY is in an error state.
329 * - phy_start moves to RESUMING
331 * RESUMING: PHY was halted, but now wants to run again.
332 * - If we are forcing, or aneg is done, timer moves to RUNNING
333 * - If aneg is not done, timer moves to AN
334 * - phy_stop moves to HALTED
352 * struct phy_c45_device_ids - 802.3-c45 Device Identifiers
353 * @devices_in_package: Bit vector of devices present.
354 * @device_ids: The device identifer for each present device.
356 struct phy_c45_device_ids {
357 u32 devices_in_package;
361 /* phy_device: An instance of a PHY
363 * drv: Pointer to the driver for this PHY instance
364 * phy_id: UID for this device found during discovery
365 * c45_ids: 802.3-c45 Device Identifers if is_c45.
366 * is_c45: Set to true if this phy uses clause 45 addressing.
367 * is_internal: Set to true if this phy is internal to a MAC.
368 * is_pseudo_fixed_link: Set to true if this phy is an Ethernet switch, etc.
369 * has_fixups: Set to true if this phy has fixups/quirks.
370 * suspended: Set to true if this phy has been suspended successfully.
371 * sysfs_links: Internal boolean tracking sysfs symbolic links setup/removal.
372 * state: state of the PHY for management purposes
373 * dev_flags: Device-specific flags used by the PHY driver.
374 * link_timeout: The number of timer firings to wait before the
375 * giving up on the current attempt at acquiring a link
376 * irq: IRQ number of the PHY's interrupt (-1 if none)
377 * phy_timer: The timer for handling the state machine
378 * phy_queue: A work_queue for the phy_mac_interrupt
379 * attached_dev: The attached enet driver's device instance ptr
380 * adjust_link: Callback for the enet controller to respond to
381 * changes in the link state.
383 * speed, duplex, pause, supported, advertising, lp_advertising,
384 * and autoneg are used like in mii_if_info
386 * interrupts currently only supports enabled or disabled,
387 * but could be changed in the future to support enabling
388 * and disabling specific interrupts
390 * Contains some infrastructure for polling and interrupt
391 * handling, as well as handling shifts in PHY hardware state
394 struct mdio_device mdio;
396 /* Information about the PHY type */
397 /* And management functions */
398 struct phy_driver *drv;
402 struct phy_c45_device_ids c45_ids;
405 bool is_pseudo_fixed_link;
410 enum phy_state state;
414 phy_interface_t interface;
417 * forced speed & duplex (no autoneg)
418 * partner speed & duplex & pause (autoneg)
425 /* The most recently read link state */
428 /* Enabled Interrupts */
431 /* Union of PHY and Attached devices' supported modes */
432 /* See mii.h for more info */
437 /* Energy efficient ethernet modes which should be prohibited */
438 u32 eee_broken_modes;
444 #ifdef CONFIG_LED_TRIGGER_PHY
445 struct phy_led_trigger *phy_led_triggers;
446 unsigned int phy_num_led_triggers;
447 struct phy_led_trigger *last_triggered;
451 * Interrupt number for this PHY
452 * -1 means no interrupt
456 /* private data pointer */
457 /* For use by PHYs to maintain extra state */
460 /* Interrupt and Polling infrastructure */
461 struct work_struct phy_queue;
462 struct delayed_work state_queue;
463 atomic_t irq_disable;
467 struct net_device *attached_dev;
472 void (*adjust_link)(struct net_device *dev);
474 #define to_phy_device(d) container_of(to_mdio_device(d), \
475 struct phy_device, mdio)
477 /* struct phy_driver: Driver structure for a particular PHY type
479 * driver_data: static driver data
480 * phy_id: The result of reading the UID registers of this PHY
481 * type, and ANDing them with the phy_id_mask. This driver
482 * only works for PHYs with IDs which match this field
483 * name: The friendly name of this PHY type
484 * phy_id_mask: Defines the important bits of the phy_id
485 * features: A list of features (speed, duplex, etc) supported
487 * flags: A bitfield defining certain other features this PHY
488 * supports (like interrupts)
490 * The drivers must implement config_aneg and read_status. All
491 * other functions are optional. Note that none of these
492 * functions should be called from interrupt time. The goal is
493 * for the bus read/write functions to be able to block when the
494 * bus transaction is happening, and be freed up by an interrupt
495 * (The MPC85xx has this ability, though it is not currently
496 * supported in the driver).
499 struct mdio_driver_common mdiodrv;
502 unsigned int phy_id_mask;
505 const void *driver_data;
508 * Called to issue a PHY software reset
510 int (*soft_reset)(struct phy_device *phydev);
513 * Called to initialize the PHY,
514 * including after a reset
516 int (*config_init)(struct phy_device *phydev);
519 * Called during discovery. Used to set
520 * up device-specific structures, if any
522 int (*probe)(struct phy_device *phydev);
524 /* PHY Power Management */
525 int (*suspend)(struct phy_device *phydev);
526 int (*resume)(struct phy_device *phydev);
529 * Configures the advertisement and resets
530 * autonegotiation if phydev->autoneg is on,
531 * forces the speed to the current settings in phydev
532 * if phydev->autoneg is off
534 int (*config_aneg)(struct phy_device *phydev);
536 /* Determines the auto negotiation result */
537 int (*aneg_done)(struct phy_device *phydev);
539 /* Determines the negotiated speed and duplex */
540 int (*read_status)(struct phy_device *phydev);
542 /* Clears any pending interrupts */
543 int (*ack_interrupt)(struct phy_device *phydev);
545 /* Enables or disables interrupts */
546 int (*config_intr)(struct phy_device *phydev);
549 * Checks if the PHY generated an interrupt.
550 * For multi-PHY devices with shared PHY interrupt pin
552 int (*did_interrupt)(struct phy_device *phydev);
554 /* Clears up any memory if needed */
555 void (*remove)(struct phy_device *phydev);
557 /* Returns true if this is a suitable driver for the given
558 * phydev. If NULL, matching is based on phy_id and
561 int (*match_phy_device)(struct phy_device *phydev);
563 /* Handles ethtool queries for hardware time stamping. */
564 int (*ts_info)(struct phy_device *phydev, struct ethtool_ts_info *ti);
566 /* Handles SIOCSHWTSTAMP ioctl for hardware time stamping. */
567 int (*hwtstamp)(struct phy_device *phydev, struct ifreq *ifr);
570 * Requests a Rx timestamp for 'skb'. If the skb is accepted,
571 * the phy driver promises to deliver it using netif_rx() as
572 * soon as a timestamp becomes available. One of the
573 * PTP_CLASS_ values is passed in 'type'. The function must
574 * return true if the skb is accepted for delivery.
576 bool (*rxtstamp)(struct phy_device *dev, struct sk_buff *skb, int type);
579 * Requests a Tx timestamp for 'skb'. The phy driver promises
580 * to deliver it using skb_complete_tx_timestamp() as soon as a
581 * timestamp becomes available. One of the PTP_CLASS_ values
582 * is passed in 'type'.
584 void (*txtstamp)(struct phy_device *dev, struct sk_buff *skb, int type);
586 /* Some devices (e.g. qnap TS-119P II) require PHY register changes to
587 * enable Wake on LAN, so set_wol is provided to be called in the
588 * ethernet driver's set_wol function. */
589 int (*set_wol)(struct phy_device *dev, struct ethtool_wolinfo *wol);
591 /* See set_wol, but for checking whether Wake on LAN is enabled. */
592 void (*get_wol)(struct phy_device *dev, struct ethtool_wolinfo *wol);
595 * Called to inform a PHY device driver when the core is about to
596 * change the link state. This callback is supposed to be used as
597 * fixup hook for drivers that need to take action when the link
598 * state changes. Drivers are by no means allowed to mess with the
599 * PHY device structure in their implementations.
601 void (*link_change_notify)(struct phy_device *dev);
604 * Phy specific driver override for reading a MMD register.
605 * This function is optional for PHY specific drivers. When
606 * not provided, the default MMD read function will be used
607 * by phy_read_mmd(), which will use either a direct read for
608 * Clause 45 PHYs or an indirect read for Clause 22 PHYs.
609 * devnum is the MMD device number within the PHY device,
610 * regnum is the register within the selected MMD device.
612 int (*read_mmd)(struct phy_device *dev, int devnum, u16 regnum);
615 * Phy specific driver override for writing a MMD register.
616 * This function is optional for PHY specific drivers. When
617 * not provided, the default MMD write function will be used
618 * by phy_write_mmd(), which will use either a direct write for
619 * Clause 45 PHYs, or an indirect write for Clause 22 PHYs.
620 * devnum is the MMD device number within the PHY device,
621 * regnum is the register within the selected MMD device.
622 * val is the value to be written.
624 int (*write_mmd)(struct phy_device *dev, int devnum, u16 regnum,
627 /* Get the size and type of the eeprom contained within a plug-in
629 int (*module_info)(struct phy_device *dev,
630 struct ethtool_modinfo *modinfo);
632 /* Get the eeprom information from the plug-in module */
633 int (*module_eeprom)(struct phy_device *dev,
634 struct ethtool_eeprom *ee, u8 *data);
636 /* Get statistics from the phy using ethtool */
637 int (*get_sset_count)(struct phy_device *dev);
638 void (*get_strings)(struct phy_device *dev, u8 *data);
639 void (*get_stats)(struct phy_device *dev,
640 struct ethtool_stats *stats, u64 *data);
642 /* Get and Set PHY tunables */
643 int (*get_tunable)(struct phy_device *dev,
644 struct ethtool_tunable *tuna, void *data);
645 int (*set_tunable)(struct phy_device *dev,
646 struct ethtool_tunable *tuna,
649 #define to_phy_driver(d) container_of(to_mdio_common_driver(d), \
650 struct phy_driver, mdiodrv)
652 #define PHY_ANY_ID "MATCH ANY PHY"
653 #define PHY_ANY_UID 0xffffffff
655 /* A Structure for boards to register fixups with the PHY Lib */
657 struct list_head list;
658 char bus_id[MII_BUS_ID_SIZE + 3];
661 int (*run)(struct phy_device *phydev);
665 * phy_read_mmd - Convenience function for reading a register
666 * from an MMD on a given PHY.
667 * @phydev: The phy_device struct
668 * @devad: The MMD to read from
669 * @regnum: The register on the MMD to read
671 * Same rules as for phy_read();
673 int phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum);
676 * phy_read - Convenience function for reading a given PHY register
677 * @phydev: the phy_device struct
678 * @regnum: register number to read
680 * NOTE: MUST NOT be called from interrupt context,
681 * because the bus read/write functions may wait for an interrupt
682 * to conclude the operation.
684 static inline int phy_read(struct phy_device *phydev, u32 regnum)
686 return mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, regnum);
690 * phy_write - Convenience function for writing a given PHY register
691 * @phydev: the phy_device struct
692 * @regnum: register number to write
693 * @val: value to write to @regnum
695 * NOTE: MUST NOT be called from interrupt context,
696 * because the bus read/write functions may wait for an interrupt
697 * to conclude the operation.
699 static inline int phy_write(struct phy_device *phydev, u32 regnum, u16 val)
701 return mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, regnum, val);
705 * phy_interrupt_is_valid - Convenience function for testing a given PHY irq
706 * @phydev: the phy_device struct
708 * NOTE: must be kept in sync with addition/removal of PHY_POLL and
709 * PHY_IGNORE_INTERRUPT
711 static inline bool phy_interrupt_is_valid(struct phy_device *phydev)
713 return phydev->irq != PHY_POLL && phydev->irq != PHY_IGNORE_INTERRUPT;
717 * phy_is_internal - Convenience function for testing if a PHY is internal
718 * @phydev: the phy_device struct
720 static inline bool phy_is_internal(struct phy_device *phydev)
722 return phydev->is_internal;
726 * phy_interface_mode_is_rgmii - Convenience function for testing if a
727 * PHY interface mode is RGMII (all variants)
728 * @mode: the phy_interface_t enum
730 static inline bool phy_interface_mode_is_rgmii(phy_interface_t mode)
732 return mode >= PHY_INTERFACE_MODE_RGMII &&
733 mode <= PHY_INTERFACE_MODE_RGMII_TXID;
737 * phy_interface_is_rgmii - Convenience function for testing if a PHY interface
738 * is RGMII (all variants)
739 * @phydev: the phy_device struct
741 static inline bool phy_interface_is_rgmii(struct phy_device *phydev)
743 return phy_interface_mode_is_rgmii(phydev->interface);
747 * phy_is_pseudo_fixed_link - Convenience function for testing if this
748 * PHY is the CPU port facing side of an Ethernet switch, or similar.
749 * @phydev: the phy_device struct
751 static inline bool phy_is_pseudo_fixed_link(struct phy_device *phydev)
753 return phydev->is_pseudo_fixed_link;
757 * phy_write_mmd - Convenience function for writing a register
758 * on an MMD on a given PHY.
759 * @phydev: The phy_device struct
760 * @devad: The MMD to read from
761 * @regnum: The register on the MMD to read
762 * @val: value to write to @regnum
764 * Same rules as for phy_write();
766 int phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val);
768 struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
770 struct phy_c45_device_ids *c45_ids);
771 #if IS_ENABLED(CONFIG_PHYLIB)
772 struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45);
773 int phy_device_register(struct phy_device *phy);
774 void phy_device_free(struct phy_device *phydev);
777 struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45)
782 static inline int phy_device_register(struct phy_device *phy)
787 static inline void phy_device_free(struct phy_device *phydev) { }
788 #endif /* CONFIG_PHYLIB */
789 void phy_device_remove(struct phy_device *phydev);
790 int phy_init_hw(struct phy_device *phydev);
791 int phy_suspend(struct phy_device *phydev);
792 int phy_resume(struct phy_device *phydev);
793 struct phy_device *phy_attach(struct net_device *dev, const char *bus_id,
794 phy_interface_t interface);
795 struct phy_device *phy_find_first(struct mii_bus *bus);
796 int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
797 u32 flags, phy_interface_t interface);
798 int phy_connect_direct(struct net_device *dev, struct phy_device *phydev,
799 void (*handler)(struct net_device *),
800 phy_interface_t interface);
801 struct phy_device *phy_connect(struct net_device *dev, const char *bus_id,
802 void (*handler)(struct net_device *),
803 phy_interface_t interface);
804 void phy_disconnect(struct phy_device *phydev);
805 void phy_detach(struct phy_device *phydev);
806 void phy_start(struct phy_device *phydev);
807 void phy_stop(struct phy_device *phydev);
808 int phy_start_aneg(struct phy_device *phydev);
809 int phy_aneg_done(struct phy_device *phydev);
811 int phy_stop_interrupts(struct phy_device *phydev);
812 int phy_restart_aneg(struct phy_device *phydev);
814 static inline int phy_read_status(struct phy_device *phydev)
819 return phydev->drv->read_status(phydev);
822 #define phydev_err(_phydev, format, args...) \
823 dev_err(&_phydev->mdio.dev, format, ##args)
825 #define phydev_dbg(_phydev, format, args...) \
826 dev_dbg(&_phydev->mdio.dev, format, ##args);
828 static inline const char *phydev_name(const struct phy_device *phydev)
830 return dev_name(&phydev->mdio.dev);
833 void phy_attached_print(struct phy_device *phydev, const char *fmt, ...)
835 void phy_attached_info(struct phy_device *phydev);
838 int genphy_config_init(struct phy_device *phydev);
839 int genphy_setup_forced(struct phy_device *phydev);
840 int genphy_restart_aneg(struct phy_device *phydev);
841 int genphy_config_aneg(struct phy_device *phydev);
842 int genphy_aneg_done(struct phy_device *phydev);
843 int genphy_update_link(struct phy_device *phydev);
844 int genphy_read_status(struct phy_device *phydev);
845 int genphy_suspend(struct phy_device *phydev);
846 int genphy_resume(struct phy_device *phydev);
847 int genphy_soft_reset(struct phy_device *phydev);
848 static inline int genphy_no_soft_reset(struct phy_device *phydev)
854 int genphy_c45_restart_aneg(struct phy_device *phydev);
855 int genphy_c45_aneg_done(struct phy_device *phydev);
856 int genphy_c45_read_link(struct phy_device *phydev, u32 mmd_mask);
857 int genphy_c45_read_lpa(struct phy_device *phydev);
858 int genphy_c45_read_pma(struct phy_device *phydev);
859 int genphy_c45_pma_setup_forced(struct phy_device *phydev);
860 int genphy_c45_an_disable_aneg(struct phy_device *phydev);
862 void phy_driver_unregister(struct phy_driver *drv);
863 void phy_drivers_unregister(struct phy_driver *drv, int n);
864 int phy_driver_register(struct phy_driver *new_driver, struct module *owner);
865 int phy_drivers_register(struct phy_driver *new_driver, int n,
866 struct module *owner);
867 void phy_state_machine(struct work_struct *work);
868 void phy_change(struct phy_device *phydev);
869 void phy_change_work(struct work_struct *work);
870 void phy_mac_interrupt(struct phy_device *phydev, int new_link);
871 void phy_start_machine(struct phy_device *phydev);
872 void phy_stop_machine(struct phy_device *phydev);
873 void phy_trigger_machine(struct phy_device *phydev, bool sync);
874 int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd);
875 void phy_ethtool_ksettings_get(struct phy_device *phydev,
876 struct ethtool_link_ksettings *cmd);
877 int phy_ethtool_ksettings_set(struct phy_device *phydev,
878 const struct ethtool_link_ksettings *cmd);
879 int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd);
880 int phy_start_interrupts(struct phy_device *phydev);
881 void phy_print_status(struct phy_device *phydev);
882 int phy_set_max_speed(struct phy_device *phydev, u32 max_speed);
884 int phy_register_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask,
885 int (*run)(struct phy_device *));
886 int phy_register_fixup_for_id(const char *bus_id,
887 int (*run)(struct phy_device *));
888 int phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask,
889 int (*run)(struct phy_device *));
891 int phy_unregister_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask);
892 int phy_unregister_fixup_for_id(const char *bus_id);
893 int phy_unregister_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask);
895 int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable);
896 int phy_get_eee_err(struct phy_device *phydev);
897 int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data);
898 int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_eee *data);
899 int phy_ethtool_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol);
900 void phy_ethtool_get_wol(struct phy_device *phydev,
901 struct ethtool_wolinfo *wol);
902 int phy_ethtool_get_link_ksettings(struct net_device *ndev,
903 struct ethtool_link_ksettings *cmd);
904 int phy_ethtool_set_link_ksettings(struct net_device *ndev,
905 const struct ethtool_link_ksettings *cmd);
906 int phy_ethtool_nway_reset(struct net_device *ndev);
908 #if IS_ENABLED(CONFIG_PHYLIB)
909 int __init mdio_bus_init(void);
910 void mdio_bus_exit(void);
913 extern struct bus_type mdio_bus_type;
915 struct mdio_board_info {
917 char modalias[MDIO_NAME_SIZE];
919 const void *platform_data;
922 #if IS_ENABLED(CONFIG_MDIO_DEVICE)
923 int mdiobus_register_board_info(const struct mdio_board_info *info,
926 static inline int mdiobus_register_board_info(const struct mdio_board_info *i,
935 * module_phy_driver() - Helper macro for registering PHY drivers
936 * @__phy_drivers: array of PHY drivers to register
938 * Helper macro for PHY drivers which do not do anything special in module
939 * init/exit. Each module may only use this macro once, and calling it
940 * replaces module_init() and module_exit().
942 #define phy_module_driver(__phy_drivers, __count) \
943 static int __init phy_module_init(void) \
945 return phy_drivers_register(__phy_drivers, __count, THIS_MODULE); \
947 module_init(phy_module_init); \
948 static void __exit phy_module_exit(void) \
950 phy_drivers_unregister(__phy_drivers, __count); \
952 module_exit(phy_module_exit)
954 #define module_phy_driver(__phy_drivers) \
955 phy_module_driver(__phy_drivers, ARRAY_SIZE(__phy_drivers))