1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Framework and drivers for configuring and reading different PHYs
4 * Based on code in sungem_phy.c and (long-removed) gianfar_phy.c
8 * Copyright (c) 2004 Freescale Semiconductor, Inc.
14 #include <linux/compiler.h>
15 #include <linux/spinlock.h>
16 #include <linux/ethtool.h>
17 #include <linux/linkmode.h>
18 #include <linux/netlink.h>
19 #include <linux/mdio.h>
20 #include <linux/mii.h>
21 #include <linux/mii_timestamper.h>
22 #include <linux/module.h>
23 #include <linux/timer.h>
24 #include <linux/workqueue.h>
25 #include <linux/mod_devicetable.h>
26 #include <linux/u64_stats_sync.h>
27 #include <linux/irqreturn.h>
28 #include <linux/iopoll.h>
29 #include <linux/refcount.h>
31 #include <linux/atomic.h>
33 #define PHY_DEFAULT_FEATURES (SUPPORTED_Autoneg | \
37 #define PHY_10BT_FEATURES (SUPPORTED_10baseT_Half | \
38 SUPPORTED_10baseT_Full)
40 #define PHY_100BT_FEATURES (SUPPORTED_100baseT_Half | \
41 SUPPORTED_100baseT_Full)
43 #define PHY_1000BT_FEATURES (SUPPORTED_1000baseT_Half | \
44 SUPPORTED_1000baseT_Full)
46 extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_basic_features) __ro_after_init;
47 extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_basic_t1_features) __ro_after_init;
48 extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_basic_t1s_p2mp_features) __ro_after_init;
49 extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_gbit_features) __ro_after_init;
50 extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_gbit_fibre_features) __ro_after_init;
51 extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_gbit_all_ports_features) __ro_after_init;
52 extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_10gbit_features) __ro_after_init;
53 extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_10gbit_fec_features) __ro_after_init;
54 extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_10gbit_full_features) __ro_after_init;
55 extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_eee_cap1_features) __ro_after_init;
57 #define PHY_BASIC_FEATURES ((unsigned long *)&phy_basic_features)
58 #define PHY_BASIC_T1_FEATURES ((unsigned long *)&phy_basic_t1_features)
59 #define PHY_BASIC_T1S_P2MP_FEATURES ((unsigned long *)&phy_basic_t1s_p2mp_features)
60 #define PHY_GBIT_FEATURES ((unsigned long *)&phy_gbit_features)
61 #define PHY_GBIT_FIBRE_FEATURES ((unsigned long *)&phy_gbit_fibre_features)
62 #define PHY_GBIT_ALL_PORTS_FEATURES ((unsigned long *)&phy_gbit_all_ports_features)
63 #define PHY_10GBIT_FEATURES ((unsigned long *)&phy_10gbit_features)
64 #define PHY_10GBIT_FEC_FEATURES ((unsigned long *)&phy_10gbit_fec_features)
65 #define PHY_10GBIT_FULL_FEATURES ((unsigned long *)&phy_10gbit_full_features)
66 #define PHY_EEE_CAP1_FEATURES ((unsigned long *)&phy_eee_cap1_features)
68 extern const int phy_basic_ports_array[3];
69 extern const int phy_fibre_port_array[1];
70 extern const int phy_all_ports_features_array[7];
71 extern const int phy_10_100_features_array[4];
72 extern const int phy_basic_t1_features_array[3];
73 extern const int phy_basic_t1s_p2mp_features_array[2];
74 extern const int phy_gbit_features_array[2];
75 extern const int phy_10gbit_features_array[1];
78 * Set phydev->irq to PHY_POLL if interrupts are not supported,
79 * or not desired for this PHY. Set to PHY_MAC_INTERRUPT if
80 * the attached MAC driver handles the interrupt
83 #define PHY_MAC_INTERRUPT -2
85 #define PHY_IS_INTERNAL 0x00000001
86 #define PHY_RST_AFTER_CLK_EN 0x00000002
87 #define PHY_POLL_CABLE_TEST 0x00000004
88 #define MDIO_DEVICE_IS_PHY 0x80000000
91 * enum phy_interface_t - Interface Mode definitions
93 * @PHY_INTERFACE_MODE_NA: Not Applicable - don't touch
94 * @PHY_INTERFACE_MODE_INTERNAL: No interface, MAC and PHY combined
95 * @PHY_INTERFACE_MODE_MII: Media-independent interface
96 * @PHY_INTERFACE_MODE_GMII: Gigabit media-independent interface
97 * @PHY_INTERFACE_MODE_SGMII: Serial gigabit media-independent interface
98 * @PHY_INTERFACE_MODE_TBI: Ten Bit Interface
99 * @PHY_INTERFACE_MODE_REVMII: Reverse Media Independent Interface
100 * @PHY_INTERFACE_MODE_RMII: Reduced Media Independent Interface
101 * @PHY_INTERFACE_MODE_REVRMII: Reduced Media Independent Interface in PHY role
102 * @PHY_INTERFACE_MODE_RGMII: Reduced gigabit media-independent interface
103 * @PHY_INTERFACE_MODE_RGMII_ID: RGMII with Internal RX+TX delay
104 * @PHY_INTERFACE_MODE_RGMII_RXID: RGMII with Internal RX delay
105 * @PHY_INTERFACE_MODE_RGMII_TXID: RGMII with Internal RX delay
106 * @PHY_INTERFACE_MODE_RTBI: Reduced TBI
107 * @PHY_INTERFACE_MODE_SMII: Serial MII
108 * @PHY_INTERFACE_MODE_XGMII: 10 gigabit media-independent interface
109 * @PHY_INTERFACE_MODE_XLGMII:40 gigabit media-independent interface
110 * @PHY_INTERFACE_MODE_MOCA: Multimedia over Coax
111 * @PHY_INTERFACE_MODE_QSGMII: Quad SGMII
112 * @PHY_INTERFACE_MODE_TRGMII: Turbo RGMII
113 * @PHY_INTERFACE_MODE_100BASEX: 100 BaseX
114 * @PHY_INTERFACE_MODE_1000BASEX: 1000 BaseX
115 * @PHY_INTERFACE_MODE_2500BASEX: 2500 BaseX
116 * @PHY_INTERFACE_MODE_5GBASER: 5G BaseR
117 * @PHY_INTERFACE_MODE_RXAUI: Reduced XAUI
118 * @PHY_INTERFACE_MODE_XAUI: 10 Gigabit Attachment Unit Interface
119 * @PHY_INTERFACE_MODE_10GBASER: 10G BaseR
120 * @PHY_INTERFACE_MODE_25GBASER: 25G BaseR
121 * @PHY_INTERFACE_MODE_USXGMII: Universal Serial 10GE MII
122 * @PHY_INTERFACE_MODE_10GKR: 10GBASE-KR - with Clause 73 AN
123 * @PHY_INTERFACE_MODE_QUSGMII: Quad Universal SGMII
124 * @PHY_INTERFACE_MODE_1000BASEKX: 1000Base-KX - with Clause 73 AN
125 * @PHY_INTERFACE_MODE_MAX: Book keeping
127 * Describes the interface between the MAC and PHY.
130 PHY_INTERFACE_MODE_NA,
131 PHY_INTERFACE_MODE_INTERNAL,
132 PHY_INTERFACE_MODE_MII,
133 PHY_INTERFACE_MODE_GMII,
134 PHY_INTERFACE_MODE_SGMII,
135 PHY_INTERFACE_MODE_TBI,
136 PHY_INTERFACE_MODE_REVMII,
137 PHY_INTERFACE_MODE_RMII,
138 PHY_INTERFACE_MODE_REVRMII,
139 PHY_INTERFACE_MODE_RGMII,
140 PHY_INTERFACE_MODE_RGMII_ID,
141 PHY_INTERFACE_MODE_RGMII_RXID,
142 PHY_INTERFACE_MODE_RGMII_TXID,
143 PHY_INTERFACE_MODE_RTBI,
144 PHY_INTERFACE_MODE_SMII,
145 PHY_INTERFACE_MODE_XGMII,
146 PHY_INTERFACE_MODE_XLGMII,
147 PHY_INTERFACE_MODE_MOCA,
148 PHY_INTERFACE_MODE_QSGMII,
149 PHY_INTERFACE_MODE_TRGMII,
150 PHY_INTERFACE_MODE_100BASEX,
151 PHY_INTERFACE_MODE_1000BASEX,
152 PHY_INTERFACE_MODE_2500BASEX,
153 PHY_INTERFACE_MODE_5GBASER,
154 PHY_INTERFACE_MODE_RXAUI,
155 PHY_INTERFACE_MODE_XAUI,
156 /* 10GBASE-R, XFI, SFI - single lane 10G Serdes */
157 PHY_INTERFACE_MODE_10GBASER,
158 PHY_INTERFACE_MODE_25GBASER,
159 PHY_INTERFACE_MODE_USXGMII,
160 /* 10GBASE-KR - with Clause 73 AN */
161 PHY_INTERFACE_MODE_10GKR,
162 PHY_INTERFACE_MODE_QUSGMII,
163 PHY_INTERFACE_MODE_1000BASEKX,
164 PHY_INTERFACE_MODE_MAX,
167 /* PHY interface mode bitmap handling */
168 #define DECLARE_PHY_INTERFACE_MASK(name) \
169 DECLARE_BITMAP(name, PHY_INTERFACE_MODE_MAX)
171 static inline void phy_interface_zero(unsigned long *intf)
173 bitmap_zero(intf, PHY_INTERFACE_MODE_MAX);
176 static inline bool phy_interface_empty(const unsigned long *intf)
178 return bitmap_empty(intf, PHY_INTERFACE_MODE_MAX);
181 static inline void phy_interface_and(unsigned long *dst, const unsigned long *a,
182 const unsigned long *b)
184 bitmap_and(dst, a, b, PHY_INTERFACE_MODE_MAX);
187 static inline void phy_interface_or(unsigned long *dst, const unsigned long *a,
188 const unsigned long *b)
190 bitmap_or(dst, a, b, PHY_INTERFACE_MODE_MAX);
193 static inline void phy_interface_set_rgmii(unsigned long *intf)
195 __set_bit(PHY_INTERFACE_MODE_RGMII, intf);
196 __set_bit(PHY_INTERFACE_MODE_RGMII_ID, intf);
197 __set_bit(PHY_INTERFACE_MODE_RGMII_RXID, intf);
198 __set_bit(PHY_INTERFACE_MODE_RGMII_TXID, intf);
202 * phy_supported_speeds - return all speeds currently supported by a PHY device
204 unsigned int phy_supported_speeds(struct phy_device *phy,
205 unsigned int *speeds,
209 * phy_modes - map phy_interface_t enum to device tree binding of phy-mode
210 * @interface: enum phy_interface_t value
212 * Description: maps enum &phy_interface_t defined in this file
213 * into the device tree binding of 'phy-mode', so that Ethernet
214 * device driver can get PHY interface from device tree.
216 static inline const char *phy_modes(phy_interface_t interface)
219 case PHY_INTERFACE_MODE_NA:
221 case PHY_INTERFACE_MODE_INTERNAL:
223 case PHY_INTERFACE_MODE_MII:
225 case PHY_INTERFACE_MODE_GMII:
227 case PHY_INTERFACE_MODE_SGMII:
229 case PHY_INTERFACE_MODE_TBI:
231 case PHY_INTERFACE_MODE_REVMII:
233 case PHY_INTERFACE_MODE_RMII:
235 case PHY_INTERFACE_MODE_REVRMII:
237 case PHY_INTERFACE_MODE_RGMII:
239 case PHY_INTERFACE_MODE_RGMII_ID:
241 case PHY_INTERFACE_MODE_RGMII_RXID:
243 case PHY_INTERFACE_MODE_RGMII_TXID:
245 case PHY_INTERFACE_MODE_RTBI:
247 case PHY_INTERFACE_MODE_SMII:
249 case PHY_INTERFACE_MODE_XGMII:
251 case PHY_INTERFACE_MODE_XLGMII:
253 case PHY_INTERFACE_MODE_MOCA:
255 case PHY_INTERFACE_MODE_QSGMII:
257 case PHY_INTERFACE_MODE_TRGMII:
259 case PHY_INTERFACE_MODE_1000BASEX:
261 case PHY_INTERFACE_MODE_1000BASEKX:
262 return "1000base-kx";
263 case PHY_INTERFACE_MODE_2500BASEX:
265 case PHY_INTERFACE_MODE_5GBASER:
267 case PHY_INTERFACE_MODE_RXAUI:
269 case PHY_INTERFACE_MODE_XAUI:
271 case PHY_INTERFACE_MODE_10GBASER:
273 case PHY_INTERFACE_MODE_25GBASER:
275 case PHY_INTERFACE_MODE_USXGMII:
277 case PHY_INTERFACE_MODE_10GKR:
279 case PHY_INTERFACE_MODE_100BASEX:
281 case PHY_INTERFACE_MODE_QUSGMII:
288 #define PHY_INIT_TIMEOUT 100000
289 #define PHY_FORCE_TIMEOUT 10
291 #define PHY_MAX_ADDR 32
293 /* Used when trying to connect to a specific phy (mii bus id:phy device id) */
294 #define PHY_ID_FMT "%s:%02x"
296 #define MII_BUS_ID_SIZE 61
301 struct sfp_upstream_ops;
305 * struct mdio_bus_stats - Statistics counters for MDIO busses
306 * @transfers: Total number of transfers, i.e. @writes + @reads
307 * @errors: Number of MDIO transfers that returned an error
308 * @writes: Number of write transfers
309 * @reads: Number of read transfers
310 * @syncp: Synchronisation for incrementing statistics
312 struct mdio_bus_stats {
313 u64_stats_t transfers;
317 /* Must be last, add new statistics above */
318 struct u64_stats_sync syncp;
322 * struct phy_package_shared - Shared information in PHY packages
323 * @addr: Common PHY address used to combine PHYs in one package
324 * @refcnt: Number of PHYs connected to this shared data
325 * @flags: Initialization of PHY package
326 * @priv_size: Size of the shared private data @priv
327 * @priv: Driver private data shared across a PHY package
329 * Represents a shared structure between different phydev's in the same
330 * package, for example a quad PHY. See phy_package_join() and
331 * phy_package_leave().
333 struct phy_package_shared {
339 /* private data pointer */
340 /* note that this pointer is shared between different phydevs and
341 * the user has to take care of appropriate locking. It is allocated
342 * and freed automatically by phy_package_join() and
343 * phy_package_leave().
348 /* used as bit number in atomic bitops */
349 #define PHY_SHARED_F_INIT_DONE 0
350 #define PHY_SHARED_F_PROBE_DONE 1
353 * struct mii_bus - Represents an MDIO bus
355 * @owner: Who owns this device
356 * @name: User friendly name for this MDIO device, or driver name
357 * @id: Unique identifier for this bus, typical from bus hierarchy
358 * @priv: Driver private data
360 * The Bus class for PHYs. Devices which provide access to
361 * PHYs should register using this structure
364 struct module *owner;
366 char id[MII_BUS_ID_SIZE];
368 /** @read: Perform a read transfer on the bus */
369 int (*read)(struct mii_bus *bus, int addr, int regnum);
370 /** @write: Perform a write transfer on the bus */
371 int (*write)(struct mii_bus *bus, int addr, int regnum, u16 val);
372 /** @read_c45: Perform a C45 read transfer on the bus */
373 int (*read_c45)(struct mii_bus *bus, int addr, int devnum, int regnum);
374 /** @write_c45: Perform a C45 write transfer on the bus */
375 int (*write_c45)(struct mii_bus *bus, int addr, int devnum,
376 int regnum, u16 val);
377 /** @reset: Perform a reset of the bus */
378 int (*reset)(struct mii_bus *bus);
380 /** @stats: Statistic counters per device on the bus */
381 struct mdio_bus_stats stats[PHY_MAX_ADDR];
384 * @mdio_lock: A lock to ensure that only one thing can read/write
385 * the MDIO bus at a time
387 struct mutex mdio_lock;
389 /** @parent: Parent device of this bus */
390 struct device *parent;
391 /** @state: State of bus structure */
393 MDIOBUS_ALLOCATED = 1,
395 MDIOBUS_UNREGISTERED,
399 /** @dev: Kernel device representation */
402 /** @mdio_map: list of all MDIO devices on bus */
403 struct mdio_device *mdio_map[PHY_MAX_ADDR];
405 /** @phy_mask: PHY addresses to be ignored when probing */
408 /** @phy_ignore_ta_mask: PHY addresses to ignore the TA/read failure */
409 u32 phy_ignore_ta_mask;
412 * @irq: An array of interrupts, each PHY's interrupt at the index
413 * matching its address
415 int irq[PHY_MAX_ADDR];
417 /** @reset_delay_us: GPIO reset pulse width in microseconds */
419 /** @reset_post_delay_us: GPIO reset deassert delay in microseconds */
420 int reset_post_delay_us;
421 /** @reset_gpiod: Reset GPIO descriptor pointer */
422 struct gpio_desc *reset_gpiod;
424 /** @shared_lock: protect access to the shared element */
425 struct mutex shared_lock;
427 /** @shared: shared state across different PHYs */
428 struct phy_package_shared *shared[PHY_MAX_ADDR];
430 #define to_mii_bus(d) container_of(d, struct mii_bus, dev)
432 struct mii_bus *mdiobus_alloc_size(size_t size);
435 * mdiobus_alloc - Allocate an MDIO bus structure
437 * The internal state of the MDIO bus will be set of MDIOBUS_ALLOCATED ready
438 * for the driver to register the bus.
440 static inline struct mii_bus *mdiobus_alloc(void)
442 return mdiobus_alloc_size(0);
445 int __mdiobus_register(struct mii_bus *bus, struct module *owner);
446 int __devm_mdiobus_register(struct device *dev, struct mii_bus *bus,
447 struct module *owner);
448 #define mdiobus_register(bus) __mdiobus_register(bus, THIS_MODULE)
449 #define devm_mdiobus_register(dev, bus) \
450 __devm_mdiobus_register(dev, bus, THIS_MODULE)
452 void mdiobus_unregister(struct mii_bus *bus);
453 void mdiobus_free(struct mii_bus *bus);
454 struct mii_bus *devm_mdiobus_alloc_size(struct device *dev, int sizeof_priv);
455 static inline struct mii_bus *devm_mdiobus_alloc(struct device *dev)
457 return devm_mdiobus_alloc_size(dev, 0);
460 struct mii_bus *mdio_find_bus(const char *mdio_name);
461 struct phy_device *mdiobus_scan_c22(struct mii_bus *bus, int addr);
463 #define PHY_INTERRUPT_DISABLED false
464 #define PHY_INTERRUPT_ENABLED true
467 * enum phy_state - PHY state machine states:
469 * @PHY_DOWN: PHY device and driver are not ready for anything. probe
470 * should be called if and only if the PHY is in this state,
471 * given that the PHY device exists.
472 * - PHY driver probe function will set the state to @PHY_READY
474 * @PHY_READY: PHY is ready to send and receive packets, but the
475 * controller is not. By default, PHYs which do not implement
476 * probe will be set to this state by phy_probe().
477 * - start will set the state to UP
479 * @PHY_UP: The PHY and attached device are ready to do work.
480 * Interrupts should be started here.
481 * - timer moves to @PHY_NOLINK or @PHY_RUNNING
483 * @PHY_NOLINK: PHY is up, but not currently plugged in.
484 * - irq or timer will set @PHY_RUNNING if link comes back
485 * - phy_stop moves to @PHY_HALTED
487 * @PHY_RUNNING: PHY is currently up, running, and possibly sending
488 * and/or receiving packets
489 * - irq or timer will set @PHY_NOLINK if link goes down
490 * - phy_stop moves to @PHY_HALTED
492 * @PHY_CABLETEST: PHY is performing a cable test. Packet reception/sending
493 * is not expected to work, carrier will be indicated as down. PHY will be
494 * poll once per second, or on interrupt for it current state.
495 * Once complete, move to UP to restart the PHY.
496 * - phy_stop aborts the running test and moves to @PHY_HALTED
498 * @PHY_HALTED: PHY is up, but no polling or interrupts are done. Or
499 * PHY is in an error state.
500 * - phy_start moves to @PHY_UP
512 #define MDIO_MMD_NUM 32
515 * struct phy_c45_device_ids - 802.3-c45 Device Identifiers
516 * @devices_in_package: IEEE 802.3 devices in package register value.
517 * @mmds_present: bit vector of MMDs present.
518 * @device_ids: The device identifer for each present device.
520 struct phy_c45_device_ids {
521 u32 devices_in_package;
523 u32 device_ids[MDIO_MMD_NUM];
526 struct macsec_context;
530 * struct phy_device - An instance of a PHY
532 * @mdio: MDIO bus this PHY is on
533 * @drv: Pointer to the driver for this PHY instance
534 * @devlink: Create a link between phy dev and mac dev, if the external phy
535 * used by current mac interface is managed by another mac interface.
536 * @phy_id: UID for this device found during discovery
537 * @c45_ids: 802.3-c45 Device Identifiers if is_c45.
538 * @is_c45: Set to true if this PHY uses clause 45 addressing.
539 * @is_internal: Set to true if this PHY is internal to a MAC.
540 * @is_pseudo_fixed_link: Set to true if this PHY is an Ethernet switch, etc.
541 * @is_gigabit_capable: Set to true if PHY supports 1000Mbps
542 * @has_fixups: Set to true if this PHY has fixups/quirks.
543 * @suspended: Set to true if this PHY has been suspended successfully.
544 * @suspended_by_mdio_bus: Set to true if this PHY was suspended by MDIO bus.
545 * @sysfs_links: Internal boolean tracking sysfs symbolic links setup/removal.
546 * @loopback_enabled: Set true if this PHY has been loopbacked successfully.
547 * @downshifted_rate: Set true if link speed has been downshifted.
548 * @is_on_sfp_module: Set true if PHY is located on an SFP module.
549 * @mac_managed_pm: Set true if MAC driver takes of suspending/resuming PHY
550 * @state: State of the PHY for management purposes
551 * @dev_flags: Device-specific flags used by the PHY driver.
553 * - Bits [15:0] are free to use by the PHY driver to communicate
554 * driver specific behavior.
555 * - Bits [23:16] are currently reserved for future use.
556 * - Bits [31:24] are reserved for defining generic
557 * PHY driver behavior.
558 * @irq: IRQ number of the PHY's interrupt (-1 if none)
559 * @phy_timer: The timer for handling the state machine
560 * @phylink: Pointer to phylink instance for this PHY
561 * @sfp_bus_attached: Flag indicating whether the SFP bus has been attached
562 * @sfp_bus: SFP bus attached to this PHY's fiber port
563 * @attached_dev: The attached enet driver's device instance ptr
564 * @adjust_link: Callback for the enet controller to respond to changes: in the
566 * @phy_link_change: Callback for phylink for notification of link change
567 * @macsec_ops: MACsec offloading ops.
569 * @speed: Current link speed
570 * @duplex: Current duplex
571 * @port: Current port
572 * @pause: Current pause
573 * @asym_pause: Current asymmetric pause
574 * @supported: Combined MAC/PHY supported linkmodes
575 * @advertising: Currently advertised linkmodes
576 * @adv_old: Saved advertised while power saving for WoL
577 * @supported_eee: supported PHY EEE linkmodes
578 * @lp_advertising: Current link partner advertised linkmodes
579 * @host_interfaces: PHY interface modes supported by host
580 * @eee_broken_modes: Energy efficient ethernet modes which should be prohibited
581 * @autoneg: Flag autoneg being used
582 * @rate_matching: Current rate matching mode
583 * @link: Current link state
584 * @autoneg_complete: Flag auto negotiation of the link has completed
585 * @mdix: Current crossover
586 * @mdix_ctrl: User setting of crossover
587 * @pma_extable: Cached value of PMA/PMD Extended Abilities Register
588 * @interrupts: Flag interrupts have been enabled
589 * @irq_suspended: Flag indicating PHY is suspended and therefore interrupt
590 * handling shall be postponed until PHY has resumed
591 * @irq_rerun: Flag indicating interrupts occurred while PHY was suspended,
592 * requiring a rerun of the interrupt handler after resume
593 * @interface: enum phy_interface_t value
594 * @skb: Netlink message for cable diagnostics
595 * @nest: Netlink nest used for cable diagnostics
596 * @ehdr: nNtlink header for cable diagnostics
597 * @phy_led_triggers: Array of LED triggers
598 * @phy_num_led_triggers: Number of triggers in @phy_led_triggers
599 * @led_link_trigger: LED trigger for link up/down
600 * @last_triggered: last LED trigger for link speed
601 * @master_slave_set: User requested master/slave configuration
602 * @master_slave_get: Current master/slave advertisement
603 * @master_slave_state: Current master/slave configuration
604 * @mii_ts: Pointer to time stamper callbacks
605 * @psec: Pointer to Power Sourcing Equipment control struct
606 * @lock: Mutex for serialization access to PHY
607 * @state_queue: Work queue for state machine
608 * @link_down_events: Number of times link was lost
609 * @shared: Pointer to private data shared by phys in one package
610 * @priv: Pointer to driver private data
612 * interrupts currently only supports enabled or disabled,
613 * but could be changed in the future to support enabling
614 * and disabling specific interrupts
616 * Contains some infrastructure for polling and interrupt
617 * handling, as well as handling shifts in PHY hardware state
620 struct mdio_device mdio;
622 /* Information about the PHY type */
623 /* And management functions */
624 struct phy_driver *drv;
626 struct device_link *devlink;
630 struct phy_c45_device_ids c45_ids;
632 unsigned is_internal:1;
633 unsigned is_pseudo_fixed_link:1;
634 unsigned is_gigabit_capable:1;
635 unsigned has_fixups:1;
636 unsigned suspended:1;
637 unsigned suspended_by_mdio_bus:1;
638 unsigned sysfs_links:1;
639 unsigned loopback_enabled:1;
640 unsigned downshifted_rate:1;
641 unsigned is_on_sfp_module:1;
642 unsigned mac_managed_pm:1;
645 /* The most recently read link state */
647 unsigned autoneg_complete:1;
649 /* Interrupts are enabled */
650 unsigned interrupts:1;
651 unsigned irq_suspended:1;
652 unsigned irq_rerun:1;
656 enum phy_state state;
660 phy_interface_t interface;
663 * forced speed & duplex (no autoneg)
664 * partner speed & duplex & pause (autoneg)
673 u8 master_slave_state;
675 /* Union of PHY and Attached devices' supported link modes */
676 /* See ethtool.h for more info */
677 __ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
678 __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
679 __ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising);
680 /* used with phy_speed_down */
681 __ETHTOOL_DECLARE_LINK_MODE_MASK(adv_old);
682 /* used for eee validation */
683 __ETHTOOL_DECLARE_LINK_MODE_MASK(supported_eee);
685 /* Host supported PHY interface types. Should be ignored if empty. */
686 DECLARE_PHY_INTERFACE_MASK(host_interfaces);
688 /* Energy efficient ethernet modes which should be prohibited */
689 u32 eee_broken_modes;
691 #ifdef CONFIG_LED_TRIGGER_PHY
692 struct phy_led_trigger *phy_led_triggers;
693 unsigned int phy_num_led_triggers;
694 struct phy_led_trigger *last_triggered;
696 struct phy_led_trigger *led_link_trigger;
700 * Interrupt number for this PHY
701 * -1 means no interrupt
705 /* private data pointer */
706 /* For use by PHYs to maintain extra state */
709 /* shared data pointer */
710 /* For use by PHYs inside the same package that need a shared state. */
711 struct phy_package_shared *shared;
713 /* Reporting cable test results */
718 /* Interrupt and Polling infrastructure */
719 struct delayed_work state_queue;
723 /* This may be modified under the rtnl lock */
724 bool sfp_bus_attached;
725 struct sfp_bus *sfp_bus;
726 struct phylink *phylink;
727 struct net_device *attached_dev;
728 struct mii_timestamper *mii_ts;
729 struct pse_control *psec;
736 unsigned int link_down_events;
738 void (*phy_link_change)(struct phy_device *phydev, bool up);
739 void (*adjust_link)(struct net_device *dev);
741 #if IS_ENABLED(CONFIG_MACSEC)
742 /* MACsec management functions */
743 const struct macsec_ops *macsec_ops;
747 /* Generic phy_device::dev_flags */
748 #define PHY_F_NO_IRQ 0x80000000
750 static inline struct phy_device *to_phy_device(const struct device *dev)
752 return container_of(to_mdio_device(dev), struct phy_device, mdio);
756 * struct phy_tdr_config - Configuration of a TDR raw test
758 * @first: Distance for first data collection point
759 * @last: Distance for last data collection point
760 * @step: Step between data collection points
761 * @pair: Bitmap of cable pairs to collect data for
763 * A structure containing possible configuration parameters
764 * for a TDR cable test. The driver does not need to implement
765 * all the parameters, but should report what is actually used.
766 * All distances are in centimeters.
768 struct phy_tdr_config {
774 #define PHY_PAIR_ALL -1
777 * struct phy_plca_cfg - Configuration of the PLCA (Physical Layer Collision
778 * Avoidance) Reconciliation Sublayer.
780 * @version: read-only PLCA register map version. -1 = not available. Ignored
781 * when setting the configuration. Format is the same as reported by the PLCA
782 * IDVER register (31.CA00). -1 = not available.
783 * @enabled: PLCA configured mode (enabled/disabled). -1 = not available / don't
784 * set. 0 = disabled, anything else = enabled.
785 * @node_id: the PLCA local node identifier. -1 = not available / don't set.
786 * Allowed values [0 .. 254]. 255 = node disabled.
787 * @node_cnt: the PLCA node count (maximum number of nodes having a TO). Only
788 * meaningful for the coordinator (node_id = 0). -1 = not available / don't
789 * set. Allowed values [1 .. 255].
790 * @to_tmr: The value of the PLCA to_timer in bit-times, which determines the
791 * PLCA transmit opportunity window opening. See IEEE802.3 Clause 148 for
792 * more details. The to_timer shall be set equal over all nodes.
793 * -1 = not available / don't set. Allowed values [0 .. 255].
794 * @burst_cnt: controls how many additional frames a node is allowed to send in
795 * single transmit opportunity (TO). The default value of 0 means that the
796 * node is allowed exactly one frame per TO. A value of 1 allows two frames
797 * per TO, and so on. -1 = not available / don't set.
798 * Allowed values [0 .. 255].
799 * @burst_tmr: controls how many bit times to wait for the MAC to send a new
800 * frame before interrupting the burst. This value should be set to a value
801 * greater than the MAC inter-packet gap (which is typically 96 bits).
802 * -1 = not available / don't set. Allowed values [0 .. 255].
804 * A structure containing configuration parameters for setting/getting the PLCA
805 * RS configuration. The driver does not need to implement all the parameters,
806 * but should report what is actually used.
808 struct phy_plca_cfg {
819 * struct phy_plca_status - Status of the PLCA (Physical Layer Collision
820 * Avoidance) Reconciliation Sublayer.
822 * @pst: The PLCA status as reported by the PST bit in the PLCA STATUS
823 * register(31.CA03), indicating BEACON activity.
825 * A structure containing status information of the PLCA RS configuration.
826 * The driver does not need to implement all the parameters, but should report
827 * what is actually used.
829 struct phy_plca_status {
834 * struct phy_driver - Driver structure for a particular PHY type
836 * @mdiodrv: Data common to all MDIO devices
837 * @phy_id: The result of reading the UID registers of this PHY
838 * type, and ANDing them with the phy_id_mask. This driver
839 * only works for PHYs with IDs which match this field
840 * @name: The friendly name of this PHY type
841 * @phy_id_mask: Defines the important bits of the phy_id
842 * @features: A mandatory list of features (speed, duplex, etc)
843 * supported by this PHY
844 * @flags: A bitfield defining certain other features this PHY
845 * supports (like interrupts)
846 * @driver_data: Static driver data
848 * All functions are optional. If config_aneg or read_status
849 * are not implemented, the phy core uses the genphy versions.
850 * Note that none of these functions should be called from
851 * interrupt time. The goal is for the bus read/write functions
852 * to be able to block when the bus transaction is happening,
853 * and be freed up by an interrupt (The MPC85xx has this ability,
854 * though it is not currently supported in the driver).
857 struct mdio_driver_common mdiodrv;
861 const unsigned long * const features;
863 const void *driver_data;
866 * @soft_reset: Called to issue a PHY software reset
868 int (*soft_reset)(struct phy_device *phydev);
871 * @config_init: Called to initialize the PHY,
872 * including after a reset
874 int (*config_init)(struct phy_device *phydev);
877 * @probe: Called during discovery. Used to set
878 * up device-specific structures, if any
880 int (*probe)(struct phy_device *phydev);
883 * @get_features: Probe the hardware to determine what
884 * abilities it has. Should only set phydev->supported.
886 int (*get_features)(struct phy_device *phydev);
889 * @get_rate_matching: Get the supported type of rate matching for a
890 * particular phy interface. This is used by phy consumers to determine
891 * whether to advertise lower-speed modes for that interface. It is
892 * assumed that if a rate matching mode is supported on an interface,
893 * then that interface's rate can be adapted to all slower link speeds
894 * supported by the phy. If the interface is not supported, this should
895 * return %RATE_MATCH_NONE.
897 int (*get_rate_matching)(struct phy_device *phydev,
898 phy_interface_t iface);
900 /* PHY Power Management */
901 /** @suspend: Suspend the hardware, saving state if needed */
902 int (*suspend)(struct phy_device *phydev);
903 /** @resume: Resume the hardware, restoring state if needed */
904 int (*resume)(struct phy_device *phydev);
907 * @config_aneg: Configures the advertisement and resets
908 * autonegotiation if phydev->autoneg is on,
909 * forces the speed to the current settings in phydev
910 * if phydev->autoneg is off
912 int (*config_aneg)(struct phy_device *phydev);
914 /** @aneg_done: Determines the auto negotiation result */
915 int (*aneg_done)(struct phy_device *phydev);
917 /** @read_status: Determines the negotiated speed and duplex */
918 int (*read_status)(struct phy_device *phydev);
921 * @config_intr: Enables or disables interrupts.
922 * It should also clear any pending interrupts prior to enabling the
923 * IRQs and after disabling them.
925 int (*config_intr)(struct phy_device *phydev);
927 /** @handle_interrupt: Override default interrupt handling */
928 irqreturn_t (*handle_interrupt)(struct phy_device *phydev);
930 /** @remove: Clears up any memory if needed */
931 void (*remove)(struct phy_device *phydev);
934 * @match_phy_device: Returns true if this is a suitable
935 * driver for the given phydev. If NULL, matching is based on
936 * phy_id and phy_id_mask.
938 int (*match_phy_device)(struct phy_device *phydev);
941 * @set_wol: Some devices (e.g. qnap TS-119P II) require PHY
942 * register changes to enable Wake on LAN, so set_wol is
943 * provided to be called in the ethernet driver's set_wol
946 int (*set_wol)(struct phy_device *dev, struct ethtool_wolinfo *wol);
949 * @get_wol: See set_wol, but for checking whether Wake on LAN
952 void (*get_wol)(struct phy_device *dev, struct ethtool_wolinfo *wol);
955 * @link_change_notify: Called to inform a PHY device driver
956 * when the core is about to change the link state. This
957 * callback is supposed to be used as fixup hook for drivers
958 * that need to take action when the link state
959 * changes. Drivers are by no means allowed to mess with the
960 * PHY device structure in their implementations.
962 void (*link_change_notify)(struct phy_device *dev);
965 * @read_mmd: PHY specific driver override for reading a MMD
966 * register. This function is optional for PHY specific
967 * drivers. When not provided, the default MMD read function
968 * will be used by phy_read_mmd(), which will use either a
969 * direct read for Clause 45 PHYs or an indirect read for
970 * Clause 22 PHYs. devnum is the MMD device number within the
971 * PHY device, regnum is the register within the selected MMD
974 int (*read_mmd)(struct phy_device *dev, int devnum, u16 regnum);
977 * @write_mmd: PHY specific driver override for writing a MMD
978 * register. This function is optional for PHY specific
979 * drivers. When not provided, the default MMD write function
980 * will be used by phy_write_mmd(), which will use either a
981 * direct write for Clause 45 PHYs, or an indirect write for
982 * Clause 22 PHYs. devnum is the MMD device number within the
983 * PHY device, regnum is the register within the selected MMD
984 * device. val is the value to be written.
986 int (*write_mmd)(struct phy_device *dev, int devnum, u16 regnum,
989 /** @read_page: Return the current PHY register page number */
990 int (*read_page)(struct phy_device *dev);
991 /** @write_page: Set the current PHY register page number */
992 int (*write_page)(struct phy_device *dev, int page);
995 * @module_info: Get the size and type of the eeprom contained
996 * within a plug-in module
998 int (*module_info)(struct phy_device *dev,
999 struct ethtool_modinfo *modinfo);
1002 * @module_eeprom: Get the eeprom information from the plug-in
1005 int (*module_eeprom)(struct phy_device *dev,
1006 struct ethtool_eeprom *ee, u8 *data);
1008 /** @cable_test_start: Start a cable test */
1009 int (*cable_test_start)(struct phy_device *dev);
1011 /** @cable_test_tdr_start: Start a raw TDR cable test */
1012 int (*cable_test_tdr_start)(struct phy_device *dev,
1013 const struct phy_tdr_config *config);
1016 * @cable_test_get_status: Once per second, or on interrupt,
1017 * request the status of the test.
1019 int (*cable_test_get_status)(struct phy_device *dev, bool *finished);
1021 /* Get statistics from the PHY using ethtool */
1022 /** @get_sset_count: Number of statistic counters */
1023 int (*get_sset_count)(struct phy_device *dev);
1024 /** @get_strings: Names of the statistic counters */
1025 void (*get_strings)(struct phy_device *dev, u8 *data);
1026 /** @get_stats: Return the statistic counter values */
1027 void (*get_stats)(struct phy_device *dev,
1028 struct ethtool_stats *stats, u64 *data);
1030 /* Get and Set PHY tunables */
1031 /** @get_tunable: Return the value of a tunable */
1032 int (*get_tunable)(struct phy_device *dev,
1033 struct ethtool_tunable *tuna, void *data);
1034 /** @set_tunable: Set the value of a tunable */
1035 int (*set_tunable)(struct phy_device *dev,
1036 struct ethtool_tunable *tuna,
1038 /** @set_loopback: Set the loopback mood of the PHY */
1039 int (*set_loopback)(struct phy_device *dev, bool enable);
1040 /** @get_sqi: Get the signal quality indication */
1041 int (*get_sqi)(struct phy_device *dev);
1042 /** @get_sqi_max: Get the maximum signal quality indication */
1043 int (*get_sqi_max)(struct phy_device *dev);
1045 /* PLCA RS interface */
1046 /** @get_plca_cfg: Return the current PLCA configuration */
1047 int (*get_plca_cfg)(struct phy_device *dev,
1048 struct phy_plca_cfg *plca_cfg);
1049 /** @set_plca_cfg: Set the PLCA configuration */
1050 int (*set_plca_cfg)(struct phy_device *dev,
1051 const struct phy_plca_cfg *plca_cfg);
1052 /** @get_plca_status: Return the current PLCA status info */
1053 int (*get_plca_status)(struct phy_device *dev,
1054 struct phy_plca_status *plca_st);
1056 #define to_phy_driver(d) container_of(to_mdio_common_driver(d), \
1057 struct phy_driver, mdiodrv)
1059 #define PHY_ANY_ID "MATCH ANY PHY"
1060 #define PHY_ANY_UID 0xffffffff
1062 #define PHY_ID_MATCH_EXACT(id) .phy_id = (id), .phy_id_mask = GENMASK(31, 0)
1063 #define PHY_ID_MATCH_MODEL(id) .phy_id = (id), .phy_id_mask = GENMASK(31, 4)
1064 #define PHY_ID_MATCH_VENDOR(id) .phy_id = (id), .phy_id_mask = GENMASK(31, 10)
1066 /* A Structure for boards to register fixups with the PHY Lib */
1068 struct list_head list;
1069 char bus_id[MII_BUS_ID_SIZE + 3];
1072 int (*run)(struct phy_device *phydev);
1075 const char *phy_speed_to_str(int speed);
1076 const char *phy_duplex_to_str(unsigned int duplex);
1077 const char *phy_rate_matching_to_str(int rate_matching);
1079 int phy_interface_num_ports(phy_interface_t interface);
1081 /* A structure for mapping a particular speed and duplex
1082 * combination to a particular SUPPORTED and ADVERTISED value
1084 struct phy_setting {
1090 const struct phy_setting *
1091 phy_lookup_setting(int speed, int duplex, const unsigned long *mask,
1093 size_t phy_speeds(unsigned int *speeds, size_t size,
1094 unsigned long *mask);
1095 void of_set_phy_supported(struct phy_device *phydev);
1096 void of_set_phy_eee_broken(struct phy_device *phydev);
1097 int phy_speed_down_core(struct phy_device *phydev);
1100 * phy_is_started - Convenience function to check whether PHY is started
1101 * @phydev: The phy_device struct
1103 static inline bool phy_is_started(struct phy_device *phydev)
1105 return phydev->state >= PHY_UP;
1108 void phy_resolve_aneg_pause(struct phy_device *phydev);
1109 void phy_resolve_aneg_linkmode(struct phy_device *phydev);
1110 void phy_check_downshift(struct phy_device *phydev);
1113 * phy_read - Convenience function for reading a given PHY register
1114 * @phydev: the phy_device struct
1115 * @regnum: register number to read
1117 * NOTE: MUST NOT be called from interrupt context,
1118 * because the bus read/write functions may wait for an interrupt
1119 * to conclude the operation.
1121 static inline int phy_read(struct phy_device *phydev, u32 regnum)
1123 return mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, regnum);
1126 #define phy_read_poll_timeout(phydev, regnum, val, cond, sleep_us, \
1127 timeout_us, sleep_before_read) \
1129 int __ret = read_poll_timeout(phy_read, val, (cond) || val < 0, \
1130 sleep_us, timeout_us, sleep_before_read, phydev, regnum); \
1134 phydev_err(phydev, "%s failed: %d\n", __func__, __ret); \
1140 * __phy_read - convenience function for reading a given PHY register
1141 * @phydev: the phy_device struct
1142 * @regnum: register number to read
1144 * The caller must have taken the MDIO bus lock.
1146 static inline int __phy_read(struct phy_device *phydev, u32 regnum)
1148 return __mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, regnum);
1152 * phy_write - Convenience function for writing a given PHY register
1153 * @phydev: the phy_device struct
1154 * @regnum: register number to write
1155 * @val: value to write to @regnum
1157 * NOTE: MUST NOT be called from interrupt context,
1158 * because the bus read/write functions may wait for an interrupt
1159 * to conclude the operation.
1161 static inline int phy_write(struct phy_device *phydev, u32 regnum, u16 val)
1163 return mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, regnum, val);
1167 * __phy_write - Convenience function for writing a given PHY register
1168 * @phydev: the phy_device struct
1169 * @regnum: register number to write
1170 * @val: value to write to @regnum
1172 * The caller must have taken the MDIO bus lock.
1174 static inline int __phy_write(struct phy_device *phydev, u32 regnum, u16 val)
1176 return __mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, regnum,
1181 * __phy_modify_changed() - Convenience function for modifying a PHY register
1182 * @phydev: a pointer to a &struct phy_device
1183 * @regnum: register number
1184 * @mask: bit mask of bits to clear
1185 * @set: bit mask of bits to set
1187 * Unlocked helper function which allows a PHY register to be modified as
1188 * new register value = (old register value & ~mask) | set
1190 * Returns negative errno, 0 if there was no change, and 1 in case of change
1192 static inline int __phy_modify_changed(struct phy_device *phydev, u32 regnum,
1195 return __mdiobus_modify_changed(phydev->mdio.bus, phydev->mdio.addr,
1200 * phy_read_mmd - Convenience function for reading a register
1201 * from an MMD on a given PHY.
1203 int phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum);
1206 * phy_read_mmd_poll_timeout - Periodically poll a PHY register until a
1207 * condition is met or a timeout occurs
1209 * @phydev: The phy_device struct
1210 * @devaddr: The MMD to read from
1211 * @regnum: The register on the MMD to read
1212 * @val: Variable to read the register into
1213 * @cond: Break condition (usually involving @val)
1214 * @sleep_us: Maximum time to sleep between reads in us (0
1215 * tight-loops). Should be less than ~20ms since usleep_range
1216 * is used (see Documentation/timers/timers-howto.rst).
1217 * @timeout_us: Timeout in us, 0 means never timeout
1218 * @sleep_before_read: if it is true, sleep @sleep_us before read.
1219 * Returns 0 on success and -ETIMEDOUT upon a timeout. In either
1220 * case, the last read value at @args is stored in @val. Must not
1221 * be called from atomic context if sleep_us or timeout_us are used.
1223 #define phy_read_mmd_poll_timeout(phydev, devaddr, regnum, val, cond, \
1224 sleep_us, timeout_us, sleep_before_read) \
1226 int __ret = read_poll_timeout(phy_read_mmd, val, (cond) || val < 0, \
1227 sleep_us, timeout_us, sleep_before_read, \
1228 phydev, devaddr, regnum); \
1232 phydev_err(phydev, "%s failed: %d\n", __func__, __ret); \
1237 * __phy_read_mmd - Convenience function for reading a register
1238 * from an MMD on a given PHY.
1240 int __phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum);
1243 * phy_write_mmd - Convenience function for writing a register
1244 * on an MMD on a given PHY.
1246 int phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val);
1249 * __phy_write_mmd - Convenience function for writing a register
1250 * on an MMD on a given PHY.
1252 int __phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val);
1254 int __phy_modify_changed(struct phy_device *phydev, u32 regnum, u16 mask,
1256 int phy_modify_changed(struct phy_device *phydev, u32 regnum, u16 mask,
1258 int __phy_modify(struct phy_device *phydev, u32 regnum, u16 mask, u16 set);
1259 int phy_modify(struct phy_device *phydev, u32 regnum, u16 mask, u16 set);
1261 int __phy_modify_mmd_changed(struct phy_device *phydev, int devad, u32 regnum,
1263 int phy_modify_mmd_changed(struct phy_device *phydev, int devad, u32 regnum,
1265 int __phy_modify_mmd(struct phy_device *phydev, int devad, u32 regnum,
1267 int phy_modify_mmd(struct phy_device *phydev, int devad, u32 regnum,
1271 * __phy_set_bits - Convenience function for setting bits in a PHY register
1272 * @phydev: the phy_device struct
1273 * @regnum: register number to write
1276 * The caller must have taken the MDIO bus lock.
1278 static inline int __phy_set_bits(struct phy_device *phydev, u32 regnum, u16 val)
1280 return __phy_modify(phydev, regnum, 0, val);
1284 * __phy_clear_bits - Convenience function for clearing bits in a PHY register
1285 * @phydev: the phy_device struct
1286 * @regnum: register number to write
1287 * @val: bits to clear
1289 * The caller must have taken the MDIO bus lock.
1291 static inline int __phy_clear_bits(struct phy_device *phydev, u32 regnum,
1294 return __phy_modify(phydev, regnum, val, 0);
1298 * phy_set_bits - Convenience function for setting bits in a PHY register
1299 * @phydev: the phy_device struct
1300 * @regnum: register number to write
1303 static inline int phy_set_bits(struct phy_device *phydev, u32 regnum, u16 val)
1305 return phy_modify(phydev, regnum, 0, val);
1309 * phy_clear_bits - Convenience function for clearing bits in a PHY register
1310 * @phydev: the phy_device struct
1311 * @regnum: register number to write
1312 * @val: bits to clear
1314 static inline int phy_clear_bits(struct phy_device *phydev, u32 regnum, u16 val)
1316 return phy_modify(phydev, regnum, val, 0);
1320 * __phy_set_bits_mmd - Convenience function for setting bits in a register
1322 * @phydev: the phy_device struct
1323 * @devad: the MMD containing register to modify
1324 * @regnum: register number to modify
1327 * The caller must have taken the MDIO bus lock.
1329 static inline int __phy_set_bits_mmd(struct phy_device *phydev, int devad,
1330 u32 regnum, u16 val)
1332 return __phy_modify_mmd(phydev, devad, regnum, 0, val);
1336 * __phy_clear_bits_mmd - Convenience function for clearing bits in a register
1338 * @phydev: the phy_device struct
1339 * @devad: the MMD containing register to modify
1340 * @regnum: register number to modify
1341 * @val: bits to clear
1343 * The caller must have taken the MDIO bus lock.
1345 static inline int __phy_clear_bits_mmd(struct phy_device *phydev, int devad,
1346 u32 regnum, u16 val)
1348 return __phy_modify_mmd(phydev, devad, regnum, val, 0);
1352 * phy_set_bits_mmd - Convenience function for setting bits in a register
1354 * @phydev: the phy_device struct
1355 * @devad: the MMD containing register to modify
1356 * @regnum: register number to modify
1359 static inline int phy_set_bits_mmd(struct phy_device *phydev, int devad,
1360 u32 regnum, u16 val)
1362 return phy_modify_mmd(phydev, devad, regnum, 0, val);
1366 * phy_clear_bits_mmd - Convenience function for clearing bits in a register
1368 * @phydev: the phy_device struct
1369 * @devad: the MMD containing register to modify
1370 * @regnum: register number to modify
1371 * @val: bits to clear
1373 static inline int phy_clear_bits_mmd(struct phy_device *phydev, int devad,
1374 u32 regnum, u16 val)
1376 return phy_modify_mmd(phydev, devad, regnum, val, 0);
1380 * phy_interrupt_is_valid - Convenience function for testing a given PHY irq
1381 * @phydev: the phy_device struct
1383 * NOTE: must be kept in sync with addition/removal of PHY_POLL and
1386 static inline bool phy_interrupt_is_valid(struct phy_device *phydev)
1388 return phydev->irq != PHY_POLL && phydev->irq != PHY_MAC_INTERRUPT;
1392 * phy_polling_mode - Convenience function for testing whether polling is
1393 * used to detect PHY status changes
1394 * @phydev: the phy_device struct
1396 static inline bool phy_polling_mode(struct phy_device *phydev)
1398 if (phydev->state == PHY_CABLETEST)
1399 if (phydev->drv->flags & PHY_POLL_CABLE_TEST)
1402 return phydev->irq == PHY_POLL;
1406 * phy_has_hwtstamp - Tests whether a PHY time stamp configuration.
1407 * @phydev: the phy_device struct
1409 static inline bool phy_has_hwtstamp(struct phy_device *phydev)
1411 return phydev && phydev->mii_ts && phydev->mii_ts->hwtstamp;
1415 * phy_has_rxtstamp - Tests whether a PHY supports receive time stamping.
1416 * @phydev: the phy_device struct
1418 static inline bool phy_has_rxtstamp(struct phy_device *phydev)
1420 return phydev && phydev->mii_ts && phydev->mii_ts->rxtstamp;
1424 * phy_has_tsinfo - Tests whether a PHY reports time stamping and/or
1425 * PTP hardware clock capabilities.
1426 * @phydev: the phy_device struct
1428 static inline bool phy_has_tsinfo(struct phy_device *phydev)
1430 return phydev && phydev->mii_ts && phydev->mii_ts->ts_info;
1434 * phy_has_txtstamp - Tests whether a PHY supports transmit time stamping.
1435 * @phydev: the phy_device struct
1437 static inline bool phy_has_txtstamp(struct phy_device *phydev)
1439 return phydev && phydev->mii_ts && phydev->mii_ts->txtstamp;
1442 static inline int phy_hwtstamp(struct phy_device *phydev, struct ifreq *ifr)
1444 return phydev->mii_ts->hwtstamp(phydev->mii_ts, ifr);
1447 static inline bool phy_rxtstamp(struct phy_device *phydev, struct sk_buff *skb,
1450 return phydev->mii_ts->rxtstamp(phydev->mii_ts, skb, type);
1453 static inline int phy_ts_info(struct phy_device *phydev,
1454 struct ethtool_ts_info *tsinfo)
1456 return phydev->mii_ts->ts_info(phydev->mii_ts, tsinfo);
1459 static inline void phy_txtstamp(struct phy_device *phydev, struct sk_buff *skb,
1462 phydev->mii_ts->txtstamp(phydev->mii_ts, skb, type);
1466 * phy_is_internal - Convenience function for testing if a PHY is internal
1467 * @phydev: the phy_device struct
1469 static inline bool phy_is_internal(struct phy_device *phydev)
1471 return phydev->is_internal;
1475 * phy_on_sfp - Convenience function for testing if a PHY is on an SFP module
1476 * @phydev: the phy_device struct
1478 static inline bool phy_on_sfp(struct phy_device *phydev)
1480 return phydev->is_on_sfp_module;
1484 * phy_interface_mode_is_rgmii - Convenience function for testing if a
1485 * PHY interface mode is RGMII (all variants)
1486 * @mode: the &phy_interface_t enum
1488 static inline bool phy_interface_mode_is_rgmii(phy_interface_t mode)
1490 return mode >= PHY_INTERFACE_MODE_RGMII &&
1491 mode <= PHY_INTERFACE_MODE_RGMII_TXID;
1495 * phy_interface_mode_is_8023z() - does the PHY interface mode use 802.3z
1497 * @mode: one of &enum phy_interface_t
1499 * Returns true if the PHY interface mode uses the 16-bit negotiation
1500 * word as defined in 802.3z. (See 802.3-2015 37.2.1 Config_Reg encoding)
1502 static inline bool phy_interface_mode_is_8023z(phy_interface_t mode)
1504 return mode == PHY_INTERFACE_MODE_1000BASEX ||
1505 mode == PHY_INTERFACE_MODE_2500BASEX;
1509 * phy_interface_is_rgmii - Convenience function for testing if a PHY interface
1510 * is RGMII (all variants)
1511 * @phydev: the phy_device struct
1513 static inline bool phy_interface_is_rgmii(struct phy_device *phydev)
1515 return phy_interface_mode_is_rgmii(phydev->interface);
1519 * phy_is_pseudo_fixed_link - Convenience function for testing if this
1520 * PHY is the CPU port facing side of an Ethernet switch, or similar.
1521 * @phydev: the phy_device struct
1523 static inline bool phy_is_pseudo_fixed_link(struct phy_device *phydev)
1525 return phydev->is_pseudo_fixed_link;
1528 int phy_save_page(struct phy_device *phydev);
1529 int phy_select_page(struct phy_device *phydev, int page);
1530 int phy_restore_page(struct phy_device *phydev, int oldpage, int ret);
1531 int phy_read_paged(struct phy_device *phydev, int page, u32 regnum);
1532 int phy_write_paged(struct phy_device *phydev, int page, u32 regnum, u16 val);
1533 int phy_modify_paged_changed(struct phy_device *phydev, int page, u32 regnum,
1535 int phy_modify_paged(struct phy_device *phydev, int page, u32 regnum,
1538 struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id,
1540 struct phy_c45_device_ids *c45_ids);
1541 #if IS_ENABLED(CONFIG_PHYLIB)
1542 int fwnode_get_phy_id(struct fwnode_handle *fwnode, u32 *phy_id);
1543 struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode);
1544 struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode);
1545 struct phy_device *device_phy_find_device(struct device *dev);
1546 struct fwnode_handle *fwnode_get_phy_node(struct fwnode_handle *fwnode);
1547 struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45);
1548 int phy_device_register(struct phy_device *phy);
1549 void phy_device_free(struct phy_device *phydev);
1551 static inline int fwnode_get_phy_id(struct fwnode_handle *fwnode, u32 *phy_id)
1556 struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode)
1562 struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode)
1567 static inline struct phy_device *device_phy_find_device(struct device *dev)
1573 struct fwnode_handle *fwnode_get_phy_node(struct fwnode_handle *fwnode)
1579 struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45)
1584 static inline int phy_device_register(struct phy_device *phy)
1589 static inline void phy_device_free(struct phy_device *phydev) { }
1590 #endif /* CONFIG_PHYLIB */
1591 void phy_device_remove(struct phy_device *phydev);
1592 int phy_get_c45_ids(struct phy_device *phydev);
1593 int phy_init_hw(struct phy_device *phydev);
1594 int phy_suspend(struct phy_device *phydev);
1595 int phy_resume(struct phy_device *phydev);
1596 int __phy_resume(struct phy_device *phydev);
1597 int phy_loopback(struct phy_device *phydev, bool enable);
1598 void phy_sfp_attach(void *upstream, struct sfp_bus *bus);
1599 void phy_sfp_detach(void *upstream, struct sfp_bus *bus);
1600 int phy_sfp_probe(struct phy_device *phydev,
1601 const struct sfp_upstream_ops *ops);
1602 struct phy_device *phy_attach(struct net_device *dev, const char *bus_id,
1603 phy_interface_t interface);
1604 struct phy_device *phy_find_first(struct mii_bus *bus);
1605 int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
1606 u32 flags, phy_interface_t interface);
1607 int phy_connect_direct(struct net_device *dev, struct phy_device *phydev,
1608 void (*handler)(struct net_device *),
1609 phy_interface_t interface);
1610 struct phy_device *phy_connect(struct net_device *dev, const char *bus_id,
1611 void (*handler)(struct net_device *),
1612 phy_interface_t interface);
1613 void phy_disconnect(struct phy_device *phydev);
1614 void phy_detach(struct phy_device *phydev);
1615 void phy_start(struct phy_device *phydev);
1616 void phy_stop(struct phy_device *phydev);
1617 int phy_config_aneg(struct phy_device *phydev);
1618 int phy_start_aneg(struct phy_device *phydev);
1619 int phy_aneg_done(struct phy_device *phydev);
1620 int phy_speed_down(struct phy_device *phydev, bool sync);
1621 int phy_speed_up(struct phy_device *phydev);
1622 bool phy_check_valid(int speed, int duplex, unsigned long *features);
1624 int phy_restart_aneg(struct phy_device *phydev);
1625 int phy_reset_after_clk_enable(struct phy_device *phydev);
1627 #if IS_ENABLED(CONFIG_PHYLIB)
1628 int phy_start_cable_test(struct phy_device *phydev,
1629 struct netlink_ext_ack *extack);
1630 int phy_start_cable_test_tdr(struct phy_device *phydev,
1631 struct netlink_ext_ack *extack,
1632 const struct phy_tdr_config *config);
1635 int phy_start_cable_test(struct phy_device *phydev,
1636 struct netlink_ext_ack *extack)
1638 NL_SET_ERR_MSG(extack, "Kernel not compiled with PHYLIB support");
1642 int phy_start_cable_test_tdr(struct phy_device *phydev,
1643 struct netlink_ext_ack *extack,
1644 const struct phy_tdr_config *config)
1646 NL_SET_ERR_MSG(extack, "Kernel not compiled with PHYLIB support");
1651 int phy_cable_test_result(struct phy_device *phydev, u8 pair, u16 result);
1652 int phy_cable_test_fault_length(struct phy_device *phydev, u8 pair,
1655 static inline void phy_device_reset(struct phy_device *phydev, int value)
1657 mdio_device_reset(&phydev->mdio, value);
1660 #define phydev_err(_phydev, format, args...) \
1661 dev_err(&_phydev->mdio.dev, format, ##args)
1663 #define phydev_err_probe(_phydev, err, format, args...) \
1664 dev_err_probe(&_phydev->mdio.dev, err, format, ##args)
1666 #define phydev_info(_phydev, format, args...) \
1667 dev_info(&_phydev->mdio.dev, format, ##args)
1669 #define phydev_warn(_phydev, format, args...) \
1670 dev_warn(&_phydev->mdio.dev, format, ##args)
1672 #define phydev_dbg(_phydev, format, args...) \
1673 dev_dbg(&_phydev->mdio.dev, format, ##args)
1675 static inline const char *phydev_name(const struct phy_device *phydev)
1677 return dev_name(&phydev->mdio.dev);
1680 static inline void phy_lock_mdio_bus(struct phy_device *phydev)
1682 mutex_lock(&phydev->mdio.bus->mdio_lock);
1685 static inline void phy_unlock_mdio_bus(struct phy_device *phydev)
1687 mutex_unlock(&phydev->mdio.bus->mdio_lock);
1690 void phy_attached_print(struct phy_device *phydev, const char *fmt, ...)
1692 char *phy_attached_info_irq(struct phy_device *phydev)
1694 void phy_attached_info(struct phy_device *phydev);
1697 int genphy_read_abilities(struct phy_device *phydev);
1698 int genphy_setup_forced(struct phy_device *phydev);
1699 int genphy_restart_aneg(struct phy_device *phydev);
1700 int genphy_check_and_restart_aneg(struct phy_device *phydev, bool restart);
1701 int genphy_config_eee_advert(struct phy_device *phydev);
1702 int __genphy_config_aneg(struct phy_device *phydev, bool changed);
1703 int genphy_aneg_done(struct phy_device *phydev);
1704 int genphy_update_link(struct phy_device *phydev);
1705 int genphy_read_lpa(struct phy_device *phydev);
1706 int genphy_read_status_fixed(struct phy_device *phydev);
1707 int genphy_read_status(struct phy_device *phydev);
1708 int genphy_read_master_slave(struct phy_device *phydev);
1709 int genphy_suspend(struct phy_device *phydev);
1710 int genphy_resume(struct phy_device *phydev);
1711 int genphy_loopback(struct phy_device *phydev, bool enable);
1712 int genphy_soft_reset(struct phy_device *phydev);
1713 irqreturn_t genphy_handle_interrupt_no_ack(struct phy_device *phydev);
1715 static inline int genphy_config_aneg(struct phy_device *phydev)
1717 return __genphy_config_aneg(phydev, false);
1720 static inline int genphy_no_config_intr(struct phy_device *phydev)
1724 int genphy_read_mmd_unsupported(struct phy_device *phdev, int devad,
1726 int genphy_write_mmd_unsupported(struct phy_device *phdev, int devnum,
1727 u16 regnum, u16 val);
1730 int genphy_c37_config_aneg(struct phy_device *phydev);
1731 int genphy_c37_read_status(struct phy_device *phydev);
1734 int genphy_c45_restart_aneg(struct phy_device *phydev);
1735 int genphy_c45_check_and_restart_aneg(struct phy_device *phydev, bool restart);
1736 int genphy_c45_aneg_done(struct phy_device *phydev);
1737 int genphy_c45_read_link(struct phy_device *phydev);
1738 int genphy_c45_read_lpa(struct phy_device *phydev);
1739 int genphy_c45_read_pma(struct phy_device *phydev);
1740 int genphy_c45_pma_setup_forced(struct phy_device *phydev);
1741 int genphy_c45_pma_baset1_setup_master_slave(struct phy_device *phydev);
1742 int genphy_c45_an_config_aneg(struct phy_device *phydev);
1743 int genphy_c45_an_disable_aneg(struct phy_device *phydev);
1744 int genphy_c45_read_mdix(struct phy_device *phydev);
1745 int genphy_c45_pma_read_abilities(struct phy_device *phydev);
1746 int genphy_c45_read_eee_abilities(struct phy_device *phydev);
1747 int genphy_c45_pma_baset1_read_master_slave(struct phy_device *phydev);
1748 int genphy_c45_read_status(struct phy_device *phydev);
1749 int genphy_c45_baset1_read_status(struct phy_device *phydev);
1750 int genphy_c45_config_aneg(struct phy_device *phydev);
1751 int genphy_c45_loopback(struct phy_device *phydev, bool enable);
1752 int genphy_c45_pma_resume(struct phy_device *phydev);
1753 int genphy_c45_pma_suspend(struct phy_device *phydev);
1754 int genphy_c45_fast_retrain(struct phy_device *phydev, bool enable);
1755 int genphy_c45_plca_get_cfg(struct phy_device *phydev,
1756 struct phy_plca_cfg *plca_cfg);
1757 int genphy_c45_plca_set_cfg(struct phy_device *phydev,
1758 const struct phy_plca_cfg *plca_cfg);
1759 int genphy_c45_plca_get_status(struct phy_device *phydev,
1760 struct phy_plca_status *plca_st);
1761 int genphy_c45_eee_is_active(struct phy_device *phydev, unsigned long *adv,
1762 unsigned long *lp, bool *is_enabled);
1763 int genphy_c45_ethtool_get_eee(struct phy_device *phydev,
1764 struct ethtool_eee *data);
1765 int genphy_c45_ethtool_set_eee(struct phy_device *phydev,
1766 struct ethtool_eee *data);
1767 int genphy_c45_write_eee_adv(struct phy_device *phydev, unsigned long *adv);
1769 /* Generic C45 PHY driver */
1770 extern struct phy_driver genphy_c45_driver;
1772 /* The gen10g_* functions are the old Clause 45 stub */
1773 int gen10g_config_aneg(struct phy_device *phydev);
1775 static inline int phy_read_status(struct phy_device *phydev)
1780 if (phydev->drv->read_status)
1781 return phydev->drv->read_status(phydev);
1783 return genphy_read_status(phydev);
1786 void phy_driver_unregister(struct phy_driver *drv);
1787 void phy_drivers_unregister(struct phy_driver *drv, int n);
1788 int phy_driver_register(struct phy_driver *new_driver, struct module *owner);
1789 int phy_drivers_register(struct phy_driver *new_driver, int n,
1790 struct module *owner);
1791 void phy_error(struct phy_device *phydev);
1792 void phy_state_machine(struct work_struct *work);
1793 void phy_queue_state_machine(struct phy_device *phydev, unsigned long jiffies);
1794 void phy_trigger_machine(struct phy_device *phydev);
1795 void phy_mac_interrupt(struct phy_device *phydev);
1796 void phy_start_machine(struct phy_device *phydev);
1797 void phy_stop_machine(struct phy_device *phydev);
1798 void phy_ethtool_ksettings_get(struct phy_device *phydev,
1799 struct ethtool_link_ksettings *cmd);
1800 int phy_ethtool_ksettings_set(struct phy_device *phydev,
1801 const struct ethtool_link_ksettings *cmd);
1802 int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd);
1803 int phy_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
1804 int phy_do_ioctl_running(struct net_device *dev, struct ifreq *ifr, int cmd);
1805 int phy_disable_interrupts(struct phy_device *phydev);
1806 void phy_request_interrupt(struct phy_device *phydev);
1807 void phy_free_interrupt(struct phy_device *phydev);
1808 void phy_print_status(struct phy_device *phydev);
1809 int phy_get_rate_matching(struct phy_device *phydev,
1810 phy_interface_t iface);
1811 void phy_set_max_speed(struct phy_device *phydev, u32 max_speed);
1812 void phy_remove_link_mode(struct phy_device *phydev, u32 link_mode);
1813 void phy_advertise_supported(struct phy_device *phydev);
1814 void phy_support_sym_pause(struct phy_device *phydev);
1815 void phy_support_asym_pause(struct phy_device *phydev);
1816 void phy_set_sym_pause(struct phy_device *phydev, bool rx, bool tx,
1818 void phy_set_asym_pause(struct phy_device *phydev, bool rx, bool tx);
1819 bool phy_validate_pause(struct phy_device *phydev,
1820 struct ethtool_pauseparam *pp);
1821 void phy_get_pause(struct phy_device *phydev, bool *tx_pause, bool *rx_pause);
1823 s32 phy_get_internal_delay(struct phy_device *phydev, struct device *dev,
1824 const int *delay_values, int size, bool is_rx);
1826 void phy_resolve_pause(unsigned long *local_adv, unsigned long *partner_adv,
1827 bool *tx_pause, bool *rx_pause);
1829 int phy_register_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask,
1830 int (*run)(struct phy_device *));
1831 int phy_register_fixup_for_id(const char *bus_id,
1832 int (*run)(struct phy_device *));
1833 int phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask,
1834 int (*run)(struct phy_device *));
1836 int phy_unregister_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask);
1837 int phy_unregister_fixup_for_id(const char *bus_id);
1838 int phy_unregister_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask);
1840 int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable);
1841 int phy_get_eee_err(struct phy_device *phydev);
1842 int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data);
1843 int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_eee *data);
1844 int phy_ethtool_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol);
1845 void phy_ethtool_get_wol(struct phy_device *phydev,
1846 struct ethtool_wolinfo *wol);
1847 int phy_ethtool_get_link_ksettings(struct net_device *ndev,
1848 struct ethtool_link_ksettings *cmd);
1849 int phy_ethtool_set_link_ksettings(struct net_device *ndev,
1850 const struct ethtool_link_ksettings *cmd);
1851 int phy_ethtool_nway_reset(struct net_device *ndev);
1852 int phy_package_join(struct phy_device *phydev, int addr, size_t priv_size);
1853 void phy_package_leave(struct phy_device *phydev);
1854 int devm_phy_package_join(struct device *dev, struct phy_device *phydev,
1855 int addr, size_t priv_size);
1857 #if IS_ENABLED(CONFIG_PHYLIB)
1858 int __init mdio_bus_init(void);
1859 void mdio_bus_exit(void);
1862 int phy_ethtool_get_strings(struct phy_device *phydev, u8 *data);
1863 int phy_ethtool_get_sset_count(struct phy_device *phydev);
1864 int phy_ethtool_get_stats(struct phy_device *phydev,
1865 struct ethtool_stats *stats, u64 *data);
1866 int phy_ethtool_get_plca_cfg(struct phy_device *phydev,
1867 struct phy_plca_cfg *plca_cfg);
1868 int phy_ethtool_set_plca_cfg(struct phy_device *phydev,
1869 const struct phy_plca_cfg *plca_cfg,
1870 struct netlink_ext_ack *extack);
1871 int phy_ethtool_get_plca_status(struct phy_device *phydev,
1872 struct phy_plca_status *plca_st);
1874 static inline int phy_package_read(struct phy_device *phydev, u32 regnum)
1876 struct phy_package_shared *shared = phydev->shared;
1881 return mdiobus_read(phydev->mdio.bus, shared->addr, regnum);
1884 static inline int __phy_package_read(struct phy_device *phydev, u32 regnum)
1886 struct phy_package_shared *shared = phydev->shared;
1891 return __mdiobus_read(phydev->mdio.bus, shared->addr, regnum);
1894 static inline int phy_package_write(struct phy_device *phydev,
1895 u32 regnum, u16 val)
1897 struct phy_package_shared *shared = phydev->shared;
1902 return mdiobus_write(phydev->mdio.bus, shared->addr, regnum, val);
1905 static inline int __phy_package_write(struct phy_device *phydev,
1906 u32 regnum, u16 val)
1908 struct phy_package_shared *shared = phydev->shared;
1913 return __mdiobus_write(phydev->mdio.bus, shared->addr, regnum, val);
1916 static inline bool __phy_package_set_once(struct phy_device *phydev,
1919 struct phy_package_shared *shared = phydev->shared;
1924 return !test_and_set_bit(b, &shared->flags);
1927 static inline bool phy_package_init_once(struct phy_device *phydev)
1929 return __phy_package_set_once(phydev, PHY_SHARED_F_INIT_DONE);
1932 static inline bool phy_package_probe_once(struct phy_device *phydev)
1934 return __phy_package_set_once(phydev, PHY_SHARED_F_PROBE_DONE);
1937 extern struct bus_type mdio_bus_type;
1939 struct mdio_board_info {
1941 char modalias[MDIO_NAME_SIZE];
1943 const void *platform_data;
1946 #if IS_ENABLED(CONFIG_MDIO_DEVICE)
1947 int mdiobus_register_board_info(const struct mdio_board_info *info,
1950 static inline int mdiobus_register_board_info(const struct mdio_board_info *i,
1959 * phy_module_driver() - Helper macro for registering PHY drivers
1960 * @__phy_drivers: array of PHY drivers to register
1961 * @__count: Numbers of members in array
1963 * Helper macro for PHY drivers which do not do anything special in module
1964 * init/exit. Each module may only use this macro once, and calling it
1965 * replaces module_init() and module_exit().
1967 #define phy_module_driver(__phy_drivers, __count) \
1968 static int __init phy_module_init(void) \
1970 return phy_drivers_register(__phy_drivers, __count, THIS_MODULE); \
1972 module_init(phy_module_init); \
1973 static void __exit phy_module_exit(void) \
1975 phy_drivers_unregister(__phy_drivers, __count); \
1977 module_exit(phy_module_exit)
1979 #define module_phy_driver(__phy_drivers) \
1980 phy_module_driver(__phy_drivers, ARRAY_SIZE(__phy_drivers))
1982 bool phy_driver_is_genphy(struct phy_device *phydev);
1983 bool phy_driver_is_genphy_10g(struct phy_device *phydev);
1985 #endif /* __PHY_H */