xref: /linux/include/linux/phy.h (revision 8be4d31cb8aaeea27bde4b7ddb26e28a89062ebf)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Framework and drivers for configuring and reading different PHYs
4  * Based on code in sungem_phy.c and (long-removed) gianfar_phy.c
5  *
6  * Author: Andy Fleming
7  *
8  * Copyright (c) 2004 Freescale Semiconductor, Inc.
9  */
10 
11 #ifndef __PHY_H
12 #define __PHY_H
13 
14 #include <linux/compiler.h>
15 #include <linux/spinlock.h>
16 #include <linux/ethtool.h>
17 #include <linux/leds.h>
18 #include <linux/linkmode.h>
19 #include <linux/netlink.h>
20 #include <linux/mdio.h>
21 #include <linux/mii.h>
22 #include <linux/mii_timestamper.h>
23 #include <linux/module.h>
24 #include <linux/timer.h>
25 #include <linux/workqueue.h>
26 #include <linux/mod_devicetable.h>
27 #include <linux/u64_stats_sync.h>
28 #include <linux/irqreturn.h>
29 #include <linux/iopoll.h>
30 #include <linux/refcount.h>
31 
32 #include <linux/atomic.h>
33 #include <net/eee.h>
34 
35 extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_basic_features) __ro_after_init;
36 extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_basic_t1_features) __ro_after_init;
37 extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_basic_t1s_p2mp_features) __ro_after_init;
38 extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_gbit_features) __ro_after_init;
39 extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_gbit_fibre_features) __ro_after_init;
40 extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_10gbit_features) __ro_after_init;
41 extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_eee_cap1_features) __ro_after_init;
42 extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_eee_cap2_features) __ro_after_init;
43 
44 #define PHY_BASIC_FEATURES ((unsigned long *)&phy_basic_features)
45 #define PHY_BASIC_T1_FEATURES ((unsigned long *)&phy_basic_t1_features)
46 #define PHY_BASIC_T1S_P2MP_FEATURES ((unsigned long *)&phy_basic_t1s_p2mp_features)
47 #define PHY_GBIT_FEATURES ((unsigned long *)&phy_gbit_features)
48 #define PHY_GBIT_FIBRE_FEATURES ((unsigned long *)&phy_gbit_fibre_features)
49 #define PHY_10GBIT_FEATURES ((unsigned long *)&phy_10gbit_features)
50 #define PHY_EEE_CAP1_FEATURES ((unsigned long *)&phy_eee_cap1_features)
51 #define PHY_EEE_CAP2_FEATURES ((unsigned long *)&phy_eee_cap2_features)
52 
53 extern const int phy_basic_ports_array[3];
54 
55 /*
56  * Set phydev->irq to PHY_POLL if interrupts are not supported,
57  * or not desired for this PHY.  Set to PHY_MAC_INTERRUPT if
58  * the attached MAC driver handles the interrupt
59  */
60 #define PHY_POLL		-1
61 #define PHY_MAC_INTERRUPT	-2
62 
63 #define PHY_IS_INTERNAL		0x00000001
64 #define PHY_RST_AFTER_CLK_EN	0x00000002
65 #define PHY_POLL_CABLE_TEST	0x00000004
66 #define PHY_ALWAYS_CALL_SUSPEND	0x00000008
67 #define MDIO_DEVICE_IS_PHY	0x80000000
68 
69 /**
70  * enum phy_interface_t - Interface Mode definitions
71  *
72  * @PHY_INTERFACE_MODE_NA: Not Applicable - don't touch
73  * @PHY_INTERFACE_MODE_INTERNAL: No interface, MAC and PHY combined
74  * @PHY_INTERFACE_MODE_MII: Media-independent interface
75  * @PHY_INTERFACE_MODE_GMII: Gigabit media-independent interface
76  * @PHY_INTERFACE_MODE_SGMII: Serial gigabit media-independent interface
77  * @PHY_INTERFACE_MODE_TBI: Ten Bit Interface
78  * @PHY_INTERFACE_MODE_REVMII: Reverse Media Independent Interface
79  * @PHY_INTERFACE_MODE_RMII: Reduced Media Independent Interface
80  * @PHY_INTERFACE_MODE_REVRMII: Reduced Media Independent Interface in PHY role
81  * @PHY_INTERFACE_MODE_RGMII: Reduced gigabit media-independent interface
82  * @PHY_INTERFACE_MODE_RGMII_ID: RGMII with Internal RX+TX delay
83  * @PHY_INTERFACE_MODE_RGMII_RXID: RGMII with Internal RX delay
84  * @PHY_INTERFACE_MODE_RGMII_TXID: RGMII with Internal TX delay
85  * @PHY_INTERFACE_MODE_RTBI: Reduced TBI
86  * @PHY_INTERFACE_MODE_SMII: Serial MII
87  * @PHY_INTERFACE_MODE_XGMII: 10 gigabit media-independent interface
88  * @PHY_INTERFACE_MODE_XLGMII:40 gigabit media-independent interface
89  * @PHY_INTERFACE_MODE_MOCA: Multimedia over Coax
90  * @PHY_INTERFACE_MODE_PSGMII: Penta SGMII
91  * @PHY_INTERFACE_MODE_QSGMII: Quad SGMII
92  * @PHY_INTERFACE_MODE_TRGMII: Turbo RGMII
93  * @PHY_INTERFACE_MODE_100BASEX: 100 BaseX
94  * @PHY_INTERFACE_MODE_1000BASEX: 1000 BaseX
95  * @PHY_INTERFACE_MODE_2500BASEX: 2500 BaseX
96  * @PHY_INTERFACE_MODE_5GBASER: 5G BaseR
97  * @PHY_INTERFACE_MODE_RXAUI: Reduced XAUI
98  * @PHY_INTERFACE_MODE_XAUI: 10 Gigabit Attachment Unit Interface
99  * @PHY_INTERFACE_MODE_10GBASER: 10G BaseR
100  * @PHY_INTERFACE_MODE_25GBASER: 25G BaseR
101  * @PHY_INTERFACE_MODE_USXGMII:  Universal Serial 10GE MII
102  * @PHY_INTERFACE_MODE_10GKR: 10GBASE-KR - with Clause 73 AN
103  * @PHY_INTERFACE_MODE_QUSGMII: Quad Universal SGMII
104  * @PHY_INTERFACE_MODE_1000BASEKX: 1000Base-KX - with Clause 73 AN
105  * @PHY_INTERFACE_MODE_10G_QXGMII: 10G-QXGMII - 4 ports over 10G USXGMII
106  * @PHY_INTERFACE_MODE_50GBASER: 50GBase-R - with Clause 134 FEC
107  * @PHY_INTERFACE_MODE_LAUI: 50 Gigabit Attachment Unit Interface
108  * @PHY_INTERFACE_MODE_100GBASEP: 100GBase-P - with Clause 134 FEC
109  * @PHY_INTERFACE_MODE_MIILITE: MII-Lite - MII without RXER TXER CRS COL
110  * @PHY_INTERFACE_MODE_MAX: Book keeping
111  *
112  * Describes the interface between the MAC and PHY.
113  */
114 typedef enum {
115 	PHY_INTERFACE_MODE_NA,
116 	PHY_INTERFACE_MODE_INTERNAL,
117 	PHY_INTERFACE_MODE_MII,
118 	PHY_INTERFACE_MODE_GMII,
119 	PHY_INTERFACE_MODE_SGMII,
120 	PHY_INTERFACE_MODE_TBI,
121 	PHY_INTERFACE_MODE_REVMII,
122 	PHY_INTERFACE_MODE_RMII,
123 	PHY_INTERFACE_MODE_REVRMII,
124 	PHY_INTERFACE_MODE_RGMII,
125 	PHY_INTERFACE_MODE_RGMII_ID,
126 	PHY_INTERFACE_MODE_RGMII_RXID,
127 	PHY_INTERFACE_MODE_RGMII_TXID,
128 	PHY_INTERFACE_MODE_RTBI,
129 	PHY_INTERFACE_MODE_SMII,
130 	PHY_INTERFACE_MODE_XGMII,
131 	PHY_INTERFACE_MODE_XLGMII,
132 	PHY_INTERFACE_MODE_MOCA,
133 	PHY_INTERFACE_MODE_PSGMII,
134 	PHY_INTERFACE_MODE_QSGMII,
135 	PHY_INTERFACE_MODE_TRGMII,
136 	PHY_INTERFACE_MODE_100BASEX,
137 	PHY_INTERFACE_MODE_1000BASEX,
138 	PHY_INTERFACE_MODE_2500BASEX,
139 	PHY_INTERFACE_MODE_5GBASER,
140 	PHY_INTERFACE_MODE_RXAUI,
141 	PHY_INTERFACE_MODE_XAUI,
142 	/* 10GBASE-R, XFI, SFI - single lane 10G Serdes */
143 	PHY_INTERFACE_MODE_10GBASER,
144 	PHY_INTERFACE_MODE_25GBASER,
145 	PHY_INTERFACE_MODE_USXGMII,
146 	/* 10GBASE-KR - with Clause 73 AN */
147 	PHY_INTERFACE_MODE_10GKR,
148 	PHY_INTERFACE_MODE_QUSGMII,
149 	PHY_INTERFACE_MODE_1000BASEKX,
150 	PHY_INTERFACE_MODE_10G_QXGMII,
151 	PHY_INTERFACE_MODE_50GBASER,
152 	PHY_INTERFACE_MODE_LAUI,
153 	PHY_INTERFACE_MODE_100GBASEP,
154 	PHY_INTERFACE_MODE_MIILITE,
155 	PHY_INTERFACE_MODE_MAX,
156 } phy_interface_t;
157 
158 /* PHY interface mode bitmap handling */
159 #define DECLARE_PHY_INTERFACE_MASK(name) \
160 	DECLARE_BITMAP(name, PHY_INTERFACE_MODE_MAX)
161 
phy_interface_zero(unsigned long * intf)162 static inline void phy_interface_zero(unsigned long *intf)
163 {
164 	bitmap_zero(intf, PHY_INTERFACE_MODE_MAX);
165 }
166 
phy_interface_empty(const unsigned long * intf)167 static inline bool phy_interface_empty(const unsigned long *intf)
168 {
169 	return bitmap_empty(intf, PHY_INTERFACE_MODE_MAX);
170 }
171 
phy_interface_and(unsigned long * dst,const unsigned long * a,const unsigned long * b)172 static inline void phy_interface_and(unsigned long *dst, const unsigned long *a,
173 				     const unsigned long *b)
174 {
175 	bitmap_and(dst, a, b, PHY_INTERFACE_MODE_MAX);
176 }
177 
phy_interface_or(unsigned long * dst,const unsigned long * a,const unsigned long * b)178 static inline void phy_interface_or(unsigned long *dst, const unsigned long *a,
179 				    const unsigned long *b)
180 {
181 	bitmap_or(dst, a, b, PHY_INTERFACE_MODE_MAX);
182 }
183 
phy_interface_set_rgmii(unsigned long * intf)184 static inline void phy_interface_set_rgmii(unsigned long *intf)
185 {
186 	__set_bit(PHY_INTERFACE_MODE_RGMII, intf);
187 	__set_bit(PHY_INTERFACE_MODE_RGMII_ID, intf);
188 	__set_bit(PHY_INTERFACE_MODE_RGMII_RXID, intf);
189 	__set_bit(PHY_INTERFACE_MODE_RGMII_TXID, intf);
190 }
191 
192 /**
193  * phy_modes - map phy_interface_t enum to device tree binding of phy-mode
194  * @interface: enum phy_interface_t value
195  *
196  * Description: maps enum &phy_interface_t defined in this file
197  * into the device tree binding of 'phy-mode', so that Ethernet
198  * device driver can get PHY interface from device tree.
199  */
phy_modes(phy_interface_t interface)200 static inline const char *phy_modes(phy_interface_t interface)
201 {
202 	switch (interface) {
203 	case PHY_INTERFACE_MODE_NA:
204 		return "";
205 	case PHY_INTERFACE_MODE_INTERNAL:
206 		return "internal";
207 	case PHY_INTERFACE_MODE_MII:
208 		return "mii";
209 	case PHY_INTERFACE_MODE_GMII:
210 		return "gmii";
211 	case PHY_INTERFACE_MODE_SGMII:
212 		return "sgmii";
213 	case PHY_INTERFACE_MODE_TBI:
214 		return "tbi";
215 	case PHY_INTERFACE_MODE_REVMII:
216 		return "rev-mii";
217 	case PHY_INTERFACE_MODE_RMII:
218 		return "rmii";
219 	case PHY_INTERFACE_MODE_REVRMII:
220 		return "rev-rmii";
221 	case PHY_INTERFACE_MODE_RGMII:
222 		return "rgmii";
223 	case PHY_INTERFACE_MODE_RGMII_ID:
224 		return "rgmii-id";
225 	case PHY_INTERFACE_MODE_RGMII_RXID:
226 		return "rgmii-rxid";
227 	case PHY_INTERFACE_MODE_RGMII_TXID:
228 		return "rgmii-txid";
229 	case PHY_INTERFACE_MODE_RTBI:
230 		return "rtbi";
231 	case PHY_INTERFACE_MODE_SMII:
232 		return "smii";
233 	case PHY_INTERFACE_MODE_XGMII:
234 		return "xgmii";
235 	case PHY_INTERFACE_MODE_XLGMII:
236 		return "xlgmii";
237 	case PHY_INTERFACE_MODE_MOCA:
238 		return "moca";
239 	case PHY_INTERFACE_MODE_PSGMII:
240 		return "psgmii";
241 	case PHY_INTERFACE_MODE_QSGMII:
242 		return "qsgmii";
243 	case PHY_INTERFACE_MODE_TRGMII:
244 		return "trgmii";
245 	case PHY_INTERFACE_MODE_1000BASEX:
246 		return "1000base-x";
247 	case PHY_INTERFACE_MODE_1000BASEKX:
248 		return "1000base-kx";
249 	case PHY_INTERFACE_MODE_2500BASEX:
250 		return "2500base-x";
251 	case PHY_INTERFACE_MODE_5GBASER:
252 		return "5gbase-r";
253 	case PHY_INTERFACE_MODE_RXAUI:
254 		return "rxaui";
255 	case PHY_INTERFACE_MODE_XAUI:
256 		return "xaui";
257 	case PHY_INTERFACE_MODE_10GBASER:
258 		return "10gbase-r";
259 	case PHY_INTERFACE_MODE_25GBASER:
260 		return "25gbase-r";
261 	case PHY_INTERFACE_MODE_USXGMII:
262 		return "usxgmii";
263 	case PHY_INTERFACE_MODE_10GKR:
264 		return "10gbase-kr";
265 	case PHY_INTERFACE_MODE_100BASEX:
266 		return "100base-x";
267 	case PHY_INTERFACE_MODE_QUSGMII:
268 		return "qusgmii";
269 	case PHY_INTERFACE_MODE_10G_QXGMII:
270 		return "10g-qxgmii";
271 	case PHY_INTERFACE_MODE_50GBASER:
272 		return "50gbase-r";
273 	case PHY_INTERFACE_MODE_LAUI:
274 		return "laui";
275 	case PHY_INTERFACE_MODE_100GBASEP:
276 		return "100gbase-p";
277 	case PHY_INTERFACE_MODE_MIILITE:
278 		return "mii-lite";
279 	default:
280 		return "unknown";
281 	}
282 }
283 
284 /**
285  * rgmii_clock - map link speed to the clock rate
286  * @speed: link speed value
287  *
288  * Description: maps RGMII supported link speeds into the clock rates.
289  * This can also be used for MII, GMII, and RMII interface modes as the
290  * clock rates are indentical, but the caller must be aware that errors
291  * for unsupported clock rates will not be signalled.
292  *
293  * Returns: clock rate or negative errno
294  */
rgmii_clock(int speed)295 static inline long rgmii_clock(int speed)
296 {
297 	switch (speed) {
298 	case SPEED_10:
299 		return 2500000;
300 	case SPEED_100:
301 		return 25000000;
302 	case SPEED_1000:
303 		return 125000000;
304 	default:
305 		return -EINVAL;
306 	}
307 }
308 
309 #define PHY_MAX_ADDR	32
310 
311 /* Used when trying to connect to a specific phy (mii bus id:phy device id) */
312 #define PHY_ID_FMT "%s:%02x"
313 #define PHY_ID_SIZE	(MII_BUS_ID_SIZE + 3)
314 
315 #define MII_BUS_ID_SIZE	61
316 
317 struct device;
318 struct kernel_hwtstamp_config;
319 struct phylink;
320 struct sfp_bus;
321 struct sfp_upstream_ops;
322 struct sk_buff;
323 
324 /**
325  * struct mdio_bus_stats - Statistics counters for MDIO busses
326  * @transfers: Total number of transfers, i.e. @writes + @reads
327  * @errors: Number of MDIO transfers that returned an error
328  * @writes: Number of write transfers
329  * @reads: Number of read transfers
330  * @syncp: Synchronisation for incrementing statistics
331  */
332 struct mdio_bus_stats {
333 	u64_stats_t transfers;
334 	u64_stats_t errors;
335 	u64_stats_t writes;
336 	u64_stats_t reads;
337 	/* Must be last, add new statistics above */
338 	struct u64_stats_sync syncp;
339 };
340 
341 /**
342  * struct mii_bus - Represents an MDIO bus
343  *
344  * @owner: Who owns this device
345  * @name: User friendly name for this MDIO device, or driver name
346  * @id: Unique identifier for this bus, typical from bus hierarchy
347  * @priv: Driver private data
348  *
349  * The Bus class for PHYs.  Devices which provide access to
350  * PHYs should register using this structure
351  */
352 struct mii_bus {
353 	struct module *owner;
354 	const char *name;
355 	char id[MII_BUS_ID_SIZE];
356 	void *priv;
357 	/** @read: Perform a read transfer on the bus */
358 	int (*read)(struct mii_bus *bus, int addr, int regnum);
359 	/** @write: Perform a write transfer on the bus */
360 	int (*write)(struct mii_bus *bus, int addr, int regnum, u16 val);
361 	/** @read_c45: Perform a C45 read transfer on the bus */
362 	int (*read_c45)(struct mii_bus *bus, int addr, int devnum, int regnum);
363 	/** @write_c45: Perform a C45 write transfer on the bus */
364 	int (*write_c45)(struct mii_bus *bus, int addr, int devnum,
365 			 int regnum, u16 val);
366 	/** @reset: Perform a reset of the bus */
367 	int (*reset)(struct mii_bus *bus);
368 
369 	/** @stats: Statistic counters per device on the bus */
370 	struct mdio_bus_stats stats[PHY_MAX_ADDR];
371 
372 	/**
373 	 * @mdio_lock: A lock to ensure that only one thing can read/write
374 	 * the MDIO bus at a time
375 	 */
376 	struct mutex mdio_lock;
377 
378 	/** @parent: Parent device of this bus */
379 	struct device *parent;
380 	/** @state: State of bus structure */
381 	enum {
382 		MDIOBUS_ALLOCATED = 1,
383 		MDIOBUS_REGISTERED,
384 		MDIOBUS_UNREGISTERED,
385 		MDIOBUS_RELEASED,
386 	} state;
387 
388 	/** @dev: Kernel device representation */
389 	struct device dev;
390 
391 	/** @mdio_map: list of all MDIO devices on bus */
392 	struct mdio_device *mdio_map[PHY_MAX_ADDR];
393 
394 	/** @phy_mask: PHY addresses to be ignored when probing */
395 	u32 phy_mask;
396 
397 	/** @phy_ignore_ta_mask: PHY addresses to ignore the TA/read failure */
398 	u32 phy_ignore_ta_mask;
399 
400 	/**
401 	 * @irq: An array of interrupts, each PHY's interrupt at the index
402 	 * matching its address
403 	 */
404 	int irq[PHY_MAX_ADDR];
405 
406 	/** @reset_delay_us: GPIO reset pulse width in microseconds */
407 	int reset_delay_us;
408 	/** @reset_post_delay_us: GPIO reset deassert delay in microseconds */
409 	int reset_post_delay_us;
410 	/** @reset_gpiod: Reset GPIO descriptor pointer */
411 	struct gpio_desc *reset_gpiod;
412 
413 	/** @shared_lock: protect access to the shared element */
414 	struct mutex shared_lock;
415 
416 #if IS_ENABLED(CONFIG_PHY_PACKAGE)
417 	/** @shared: shared state across different PHYs */
418 	struct phy_package_shared *shared[PHY_MAX_ADDR];
419 #endif
420 };
421 #define to_mii_bus(d) container_of(d, struct mii_bus, dev)
422 
423 struct mii_bus *mdiobus_alloc_size(size_t size);
424 
425 /**
426  * mdiobus_alloc - Allocate an MDIO bus structure
427  *
428  * The internal state of the MDIO bus will be set of MDIOBUS_ALLOCATED ready
429  * for the driver to register the bus.
430  */
mdiobus_alloc(void)431 static inline struct mii_bus *mdiobus_alloc(void)
432 {
433 	return mdiobus_alloc_size(0);
434 }
435 
436 int __mdiobus_register(struct mii_bus *bus, struct module *owner);
437 int __devm_mdiobus_register(struct device *dev, struct mii_bus *bus,
438 			    struct module *owner);
439 #define mdiobus_register(bus) __mdiobus_register(bus, THIS_MODULE)
440 #define devm_mdiobus_register(dev, bus) \
441 		__devm_mdiobus_register(dev, bus, THIS_MODULE)
442 
443 void mdiobus_unregister(struct mii_bus *bus);
444 void mdiobus_free(struct mii_bus *bus);
445 struct mii_bus *devm_mdiobus_alloc_size(struct device *dev, int sizeof_priv);
devm_mdiobus_alloc(struct device * dev)446 static inline struct mii_bus *devm_mdiobus_alloc(struct device *dev)
447 {
448 	return devm_mdiobus_alloc_size(dev, 0);
449 }
450 
451 struct mii_bus *mdio_find_bus(const char *mdio_name);
452 struct phy_device *mdiobus_scan_c22(struct mii_bus *bus, int addr);
453 
454 #define PHY_INTERRUPT_DISABLED	false
455 #define PHY_INTERRUPT_ENABLED	true
456 
457 /**
458  * enum phy_state - PHY state machine states:
459  *
460  * @PHY_DOWN: PHY device and driver are not ready for anything.  probe
461  * should be called if and only if the PHY is in this state,
462  * given that the PHY device exists.
463  * - PHY driver probe function will set the state to @PHY_READY
464  *
465  * @PHY_READY: PHY is ready to send and receive packets, but the
466  * controller is not.  By default, PHYs which do not implement
467  * probe will be set to this state by phy_probe().
468  * - start will set the state to UP
469  *
470  * @PHY_UP: The PHY and attached device are ready to do work.
471  * Interrupts should be started here.
472  * - timer moves to @PHY_NOLINK or @PHY_RUNNING
473  *
474  * @PHY_NOLINK: PHY is up, but not currently plugged in.
475  * - irq or timer will set @PHY_RUNNING if link comes back
476  * - phy_stop moves to @PHY_HALTED
477  *
478  * @PHY_RUNNING: PHY is currently up, running, and possibly sending
479  * and/or receiving packets
480  * - irq or timer will set @PHY_NOLINK if link goes down
481  * - phy_stop moves to @PHY_HALTED
482  *
483  * @PHY_CABLETEST: PHY is performing a cable test. Packet reception/sending
484  * is not expected to work, carrier will be indicated as down. PHY will be
485  * poll once per second, or on interrupt for it current state.
486  * Once complete, move to UP to restart the PHY.
487  * - phy_stop aborts the running test and moves to @PHY_HALTED
488  *
489  * @PHY_HALTED: PHY is up, but no polling or interrupts are done.
490  * - phy_start moves to @PHY_UP
491  *
492  * @PHY_ERROR: PHY is up, but is in an error state.
493  * - phy_stop moves to @PHY_HALTED
494  */
495 enum phy_state {
496 	PHY_DOWN = 0,
497 	PHY_READY,
498 	PHY_HALTED,
499 	PHY_ERROR,
500 	PHY_UP,
501 	PHY_RUNNING,
502 	PHY_NOLINK,
503 	PHY_CABLETEST,
504 };
505 
506 #define MDIO_MMD_NUM 32
507 
508 /**
509  * struct phy_c45_device_ids - 802.3-c45 Device Identifiers
510  * @devices_in_package: IEEE 802.3 devices in package register value.
511  * @mmds_present: bit vector of MMDs present.
512  * @device_ids: The device identifer for each present device.
513  */
514 struct phy_c45_device_ids {
515 	u32 devices_in_package;
516 	u32 mmds_present;
517 	u32 device_ids[MDIO_MMD_NUM];
518 };
519 
520 struct macsec_context;
521 struct macsec_ops;
522 
523 /**
524  * struct phy_device - An instance of a PHY
525  *
526  * @mdio: MDIO bus this PHY is on
527  * @drv: Pointer to the driver for this PHY instance
528  * @devlink: Create a link between phy dev and mac dev, if the external phy
529  *           used by current mac interface is managed by another mac interface.
530  * @phyindex: Unique id across the phy's parent tree of phys to address the PHY
531  *	      from userspace, similar to ifindex. A zero index means the PHY
532  *	      wasn't assigned an id yet.
533  * @phy_id: UID for this device found during discovery
534  * @c45_ids: 802.3-c45 Device Identifiers if is_c45.
535  * @is_c45:  Set to true if this PHY uses clause 45 addressing.
536  * @is_internal: Set to true if this PHY is internal to a MAC.
537  * @is_pseudo_fixed_link: Set to true if this PHY is an Ethernet switch, etc.
538  * @is_gigabit_capable: Set to true if PHY supports 1000Mbps
539  * @has_fixups: Set to true if this PHY has fixups/quirks.
540  * @suspended: Set to true if this PHY has been suspended successfully.
541  * @suspended_by_mdio_bus: Set to true if this PHY was suspended by MDIO bus.
542  * @sysfs_links: Internal boolean tracking sysfs symbolic links setup/removal.
543  * @loopback_enabled: Set true if this PHY has been loopbacked successfully.
544  * @downshifted_rate: Set true if link speed has been downshifted.
545  * @is_on_sfp_module: Set true if PHY is located on an SFP module.
546  * @mac_managed_pm: Set true if MAC driver takes of suspending/resuming PHY
547  * @wol_enabled: Set to true if the PHY or the attached MAC have Wake-on-LAN
548  * 		 enabled.
549  * @is_genphy_driven: PHY is driven by one of the generic PHY drivers
550  * @state: State of the PHY for management purposes
551  * @dev_flags: Device-specific flags used by the PHY driver.
552  *
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  * @phylink: Pointer to phylink instance for this PHY
560  * @sfp_bus_attached: Flag indicating whether the SFP bus has been attached
561  * @sfp_bus: SFP bus attached to this PHY's fiber port
562  * @attached_dev: The attached enet driver's device instance ptr
563  * @adjust_link: Callback for the enet controller to respond to changes: in the
564  *               link state.
565  * @phy_link_change: Callback for phylink for notification of link change
566  * @macsec_ops: MACsec offloading ops.
567  *
568  * @speed: Current link speed
569  * @duplex: Current duplex
570  * @port: Current port
571  * @pause: Current pause
572  * @asym_pause: Current asymmetric pause
573  * @supported: Combined MAC/PHY supported linkmodes
574  * @advertising: Currently advertised linkmodes
575  * @adv_old: Saved advertised while power saving for WoL
576  * @supported_eee: supported PHY EEE linkmodes
577  * @advertising_eee: Currently advertised EEE linkmodes
578  * @enable_tx_lpi: When True, MAC should transmit LPI to PHY
579  * @eee_active: phylib private state, indicating that EEE has been negotiated
580  * @eee_cfg: User configuration of EEE
581  * @lp_advertising: Current link partner advertised linkmodes
582  * @host_interfaces: PHY interface modes supported by host
583  * @eee_disabled_modes: Energy efficient ethernet modes not to be advertised
584  * @autoneg: Flag autoneg being used
585  * @rate_matching: Current rate matching mode
586  * @link: Current link state
587  * @autoneg_complete: Flag auto negotiation of the link has completed
588  * @mdix: Current crossover
589  * @mdix_ctrl: User setting of crossover
590  * @pma_extable: Cached value of PMA/PMD Extended Abilities Register
591  * @interrupts: Flag interrupts have been enabled
592  * @irq_suspended: Flag indicating PHY is suspended and therefore interrupt
593  *                 handling shall be postponed until PHY has resumed
594  * @irq_rerun: Flag indicating interrupts occurred while PHY was suspended,
595  *             requiring a rerun of the interrupt handler after resume
596  * @default_timestamp: Flag indicating whether we are using the phy
597  *		       timestamp as the default one
598  * @interface: enum phy_interface_t value
599  * @possible_interfaces: bitmap if interface modes that the attached PHY
600  *			 will switch between depending on media speed.
601  * @skb: Netlink message for cable diagnostics
602  * @nest: Netlink nest used for cable diagnostics
603  * @ehdr: nNtlink header for cable diagnostics
604  * @phy_led_triggers: Array of LED triggers
605  * @phy_num_led_triggers: Number of triggers in @phy_led_triggers
606  * @led_link_trigger: LED trigger for link up/down
607  * @last_triggered: last LED trigger for link speed
608  * @leds: list of PHY LED structures
609  * @master_slave_set: User requested master/slave configuration
610  * @master_slave_get: Current master/slave advertisement
611  * @master_slave_state: Current master/slave configuration
612  * @mii_ts: Pointer to time stamper callbacks
613  * @psec: Pointer to Power Sourcing Equipment control struct
614  * @lock:  Mutex for serialization access to PHY
615  * @state_queue: Work queue for state machine
616  * @link_down_events: Number of times link was lost
617  * @shared: Pointer to private data shared by phys in one package
618  * @priv: Pointer to driver private data
619  *
620  * interrupts currently only supports enabled or disabled,
621  * but could be changed in the future to support enabling
622  * and disabling specific interrupts
623  *
624  * Contains some infrastructure for polling and interrupt
625  * handling, as well as handling shifts in PHY hardware state
626  */
627 struct phy_device {
628 	struct mdio_device mdio;
629 
630 	/* Information about the PHY type */
631 	/* And management functions */
632 	const struct phy_driver *drv;
633 
634 	struct device_link *devlink;
635 
636 	u32 phyindex;
637 	u32 phy_id;
638 
639 	struct phy_c45_device_ids c45_ids;
640 	unsigned is_c45:1;
641 	unsigned is_internal:1;
642 	unsigned is_pseudo_fixed_link:1;
643 	unsigned is_gigabit_capable:1;
644 	unsigned has_fixups:1;
645 	unsigned suspended:1;
646 	unsigned suspended_by_mdio_bus:1;
647 	unsigned sysfs_links:1;
648 	unsigned loopback_enabled:1;
649 	unsigned downshifted_rate:1;
650 	unsigned is_on_sfp_module:1;
651 	unsigned mac_managed_pm:1;
652 	unsigned wol_enabled:1;
653 	unsigned is_genphy_driven:1;
654 
655 	unsigned autoneg:1;
656 	/* The most recently read link state */
657 	unsigned link:1;
658 	unsigned autoneg_complete:1;
659 
660 	/* Interrupts are enabled */
661 	unsigned interrupts:1;
662 	unsigned irq_suspended:1;
663 	unsigned irq_rerun:1;
664 
665 	unsigned default_timestamp:1;
666 
667 	int rate_matching;
668 
669 	enum phy_state state;
670 
671 	u32 dev_flags;
672 
673 	phy_interface_t interface;
674 	DECLARE_PHY_INTERFACE_MASK(possible_interfaces);
675 
676 	/*
677 	 * forced speed & duplex (no autoneg)
678 	 * partner speed & duplex & pause (autoneg)
679 	 */
680 	int speed;
681 	int duplex;
682 	int port;
683 	int pause;
684 	int asym_pause;
685 	u8 master_slave_get;
686 	u8 master_slave_set;
687 	u8 master_slave_state;
688 
689 	/* Union of PHY and Attached devices' supported link modes */
690 	/* See ethtool.h for more info */
691 	__ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
692 	__ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
693 	__ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising);
694 	/* used with phy_speed_down */
695 	__ETHTOOL_DECLARE_LINK_MODE_MASK(adv_old);
696 	/* used for eee validation and configuration*/
697 	__ETHTOOL_DECLARE_LINK_MODE_MASK(supported_eee);
698 	__ETHTOOL_DECLARE_LINK_MODE_MASK(advertising_eee);
699 	/* Energy efficient ethernet modes which should be prohibited */
700 	__ETHTOOL_DECLARE_LINK_MODE_MASK(eee_disabled_modes);
701 	bool enable_tx_lpi;
702 	bool eee_active;
703 	struct eee_config eee_cfg;
704 
705 	/* Host supported PHY interface types. Should be ignored if empty. */
706 	DECLARE_PHY_INTERFACE_MASK(host_interfaces);
707 
708 #ifdef CONFIG_LED_TRIGGER_PHY
709 	struct phy_led_trigger *phy_led_triggers;
710 	unsigned int phy_num_led_triggers;
711 	struct phy_led_trigger *last_triggered;
712 
713 	struct phy_led_trigger *led_link_trigger;
714 #endif
715 	struct list_head leds;
716 
717 	/*
718 	 * Interrupt number for this PHY
719 	 * -1 means no interrupt
720 	 */
721 	int irq;
722 
723 	/* private data pointer */
724 	/* For use by PHYs to maintain extra state */
725 	void *priv;
726 
727 #if IS_ENABLED(CONFIG_PHY_PACKAGE)
728 	/* shared data pointer */
729 	/* For use by PHYs inside the same package that need a shared state. */
730 	struct phy_package_shared *shared;
731 #endif
732 
733 	/* Reporting cable test results */
734 	struct sk_buff *skb;
735 	void *ehdr;
736 	struct nlattr *nest;
737 
738 	/* Interrupt and Polling infrastructure */
739 	struct delayed_work state_queue;
740 
741 	struct mutex lock;
742 
743 	/* This may be modified under the rtnl lock */
744 	bool sfp_bus_attached;
745 	struct sfp_bus *sfp_bus;
746 	struct phylink *phylink;
747 	struct net_device *attached_dev;
748 	struct mii_timestamper *mii_ts;
749 	struct pse_control *psec;
750 
751 	u8 mdix;
752 	u8 mdix_ctrl;
753 
754 	int pma_extable;
755 
756 	unsigned int link_down_events;
757 
758 	void (*phy_link_change)(struct phy_device *phydev, bool up);
759 	void (*adjust_link)(struct net_device *dev);
760 
761 #if IS_ENABLED(CONFIG_MACSEC)
762 	/* MACsec management functions */
763 	const struct macsec_ops *macsec_ops;
764 #endif
765 };
766 
767 /* Generic phy_device::dev_flags */
768 #define PHY_F_NO_IRQ		0x80000000
769 #define PHY_F_RXC_ALWAYS_ON	0x40000000
770 
771 #define to_phy_device(__dev)	container_of_const(to_mdio_device(__dev), struct phy_device, mdio)
772 
773 /**
774  * struct phy_tdr_config - Configuration of a TDR raw test
775  *
776  * @first: Distance for first data collection point
777  * @last: Distance for last data collection point
778  * @step: Step between data collection points
779  * @pair: Bitmap of cable pairs to collect data for
780  *
781  * A structure containing possible configuration parameters
782  * for a TDR cable test. The driver does not need to implement
783  * all the parameters, but should report what is actually used.
784  * All distances are in centimeters.
785  */
786 struct phy_tdr_config {
787 	u32 first;
788 	u32 last;
789 	u32 step;
790 	s8 pair;
791 };
792 #define PHY_PAIR_ALL -1
793 
794 /**
795  * enum link_inband_signalling - in-band signalling modes that are supported
796  *
797  * @LINK_INBAND_DISABLE: in-band signalling can be disabled
798  * @LINK_INBAND_ENABLE: in-band signalling can be enabled without bypass
799  * @LINK_INBAND_BYPASS: in-band signalling can be enabled with bypass
800  *
801  * The possible and required bits can only be used if the valid bit is set.
802  * If possible is clear, that means inband signalling can not be used.
803  * Required is only valid when possible is set, and means that inband
804  * signalling must be used.
805  */
806 enum link_inband_signalling {
807 	LINK_INBAND_DISABLE		= BIT(0),
808 	LINK_INBAND_ENABLE		= BIT(1),
809 	LINK_INBAND_BYPASS		= BIT(2),
810 };
811 
812 /**
813  * struct phy_plca_cfg - Configuration of the PLCA (Physical Layer Collision
814  * Avoidance) Reconciliation Sublayer.
815  *
816  * @version: read-only PLCA register map version. -1 = not available. Ignored
817  *   when setting the configuration. Format is the same as reported by the PLCA
818  *   IDVER register (31.CA00). -1 = not available.
819  * @enabled: PLCA configured mode (enabled/disabled). -1 = not available / don't
820  *   set. 0 = disabled, anything else = enabled.
821  * @node_id: the PLCA local node identifier. -1 = not available / don't set.
822  *   Allowed values [0 .. 254]. 255 = node disabled.
823  * @node_cnt: the PLCA node count (maximum number of nodes having a TO). Only
824  *   meaningful for the coordinator (node_id = 0). -1 = not available / don't
825  *   set. Allowed values [1 .. 255].
826  * @to_tmr: The value of the PLCA to_timer in bit-times, which determines the
827  *   PLCA transmit opportunity window opening. See IEEE802.3 Clause 148 for
828  *   more details. The to_timer shall be set equal over all nodes.
829  *   -1 = not available / don't set. Allowed values [0 .. 255].
830  * @burst_cnt: controls how many additional frames a node is allowed to send in
831  *   single transmit opportunity (TO). The default value of 0 means that the
832  *   node is allowed exactly one frame per TO. A value of 1 allows two frames
833  *   per TO, and so on. -1 = not available / don't set.
834  *   Allowed values [0 .. 255].
835  * @burst_tmr: controls how many bit times to wait for the MAC to send a new
836  *   frame before interrupting the burst. This value should be set to a value
837  *   greater than the MAC inter-packet gap (which is typically 96 bits).
838  *   -1 = not available / don't set. Allowed values [0 .. 255].
839  *
840  * A structure containing configuration parameters for setting/getting the PLCA
841  * RS configuration. The driver does not need to implement all the parameters,
842  * but should report what is actually used.
843  */
844 struct phy_plca_cfg {
845 	int version;
846 	int enabled;
847 	int node_id;
848 	int node_cnt;
849 	int to_tmr;
850 	int burst_cnt;
851 	int burst_tmr;
852 };
853 
854 /**
855  * struct phy_plca_status - Status of the PLCA (Physical Layer Collision
856  * Avoidance) Reconciliation Sublayer.
857  *
858  * @pst: The PLCA status as reported by the PST bit in the PLCA STATUS
859  *	register(31.CA03), indicating BEACON activity.
860  *
861  * A structure containing status information of the PLCA RS configuration.
862  * The driver does not need to implement all the parameters, but should report
863  * what is actually used.
864  */
865 struct phy_plca_status {
866 	bool pst;
867 };
868 
869 /* Modes for PHY LED configuration */
870 enum phy_led_modes {
871 	PHY_LED_ACTIVE_HIGH = 0,
872 	PHY_LED_ACTIVE_LOW = 1,
873 	PHY_LED_INACTIVE_HIGH_IMPEDANCE = 2,
874 
875 	/* keep it last */
876 	__PHY_LED_MODES_NUM,
877 };
878 
879 /**
880  * struct phy_led: An LED driven by the PHY
881  *
882  * @list: List of LEDs
883  * @phydev: PHY this LED is attached to
884  * @led_cdev: Standard LED class structure
885  * @index: Number of the LED
886  */
887 struct phy_led {
888 	struct list_head list;
889 	struct phy_device *phydev;
890 	struct led_classdev led_cdev;
891 	u8 index;
892 };
893 
894 #define to_phy_led(d) container_of(d, struct phy_led, led_cdev)
895 
896 /**
897  * struct phy_driver - Driver structure for a particular PHY type
898  *
899  * @mdiodrv: Data common to all MDIO devices
900  * @phy_id: The result of reading the UID registers of this PHY
901  *   type, and ANDing them with the phy_id_mask.  This driver
902  *   only works for PHYs with IDs which match this field
903  * @name: The friendly name of this PHY type
904  * @phy_id_mask: Defines the important bits of the phy_id
905  * @features: A mandatory list of features (speed, duplex, etc)
906  *   supported by this PHY
907  * @flags: A bitfield defining certain other features this PHY
908  *   supports (like interrupts)
909  * @driver_data: Static driver data
910  *
911  * All functions are optional. If config_aneg or read_status
912  * are not implemented, the phy core uses the genphy versions.
913  * Note that none of these functions should be called from
914  * interrupt time. The goal is for the bus read/write functions
915  * to be able to block when the bus transaction is happening,
916  * and be freed up by an interrupt (The MPC85xx has this ability,
917  * though it is not currently supported in the driver).
918  */
919 struct phy_driver {
920 	struct mdio_driver_common mdiodrv;
921 	u32 phy_id;
922 	char *name;
923 	u32 phy_id_mask;
924 	const unsigned long * const features;
925 	u32 flags;
926 	const void *driver_data;
927 
928 	/**
929 	 * @soft_reset: Called to issue a PHY software reset
930 	 */
931 	int (*soft_reset)(struct phy_device *phydev);
932 
933 	/**
934 	 * @config_init: Called to initialize the PHY,
935 	 * including after a reset
936 	 */
937 	int (*config_init)(struct phy_device *phydev);
938 
939 	/**
940 	 * @probe: Called during discovery.  Used to set
941 	 * up device-specific structures, if any
942 	 */
943 	int (*probe)(struct phy_device *phydev);
944 
945 	/**
946 	 * @get_features: Probe the hardware to determine what
947 	 * abilities it has.  Should only set phydev->supported.
948 	 */
949 	int (*get_features)(struct phy_device *phydev);
950 
951 	/**
952 	 * @inband_caps: query whether in-band is supported for the given PHY
953 	 * interface mode. Returns a bitmask of bits defined by enum
954 	 * link_inband_signalling.
955 	 */
956 	unsigned int (*inband_caps)(struct phy_device *phydev,
957 				    phy_interface_t interface);
958 
959 	/**
960 	 * @config_inband: configure in-band mode for the PHY
961 	 */
962 	int (*config_inband)(struct phy_device *phydev, unsigned int modes);
963 
964 	/**
965 	 * @get_rate_matching: Get the supported type of rate matching for a
966 	 * particular phy interface. This is used by phy consumers to determine
967 	 * whether to advertise lower-speed modes for that interface. It is
968 	 * assumed that if a rate matching mode is supported on an interface,
969 	 * then that interface's rate can be adapted to all slower link speeds
970 	 * supported by the phy. If the interface is not supported, this should
971 	 * return %RATE_MATCH_NONE.
972 	 */
973 	int (*get_rate_matching)(struct phy_device *phydev,
974 				   phy_interface_t iface);
975 
976 	/* PHY Power Management */
977 	/** @suspend: Suspend the hardware, saving state if needed */
978 	int (*suspend)(struct phy_device *phydev);
979 	/** @resume: Resume the hardware, restoring state if needed */
980 	int (*resume)(struct phy_device *phydev);
981 
982 	/**
983 	 * @config_aneg: Configures the advertisement and resets
984 	 * autonegotiation if phydev->autoneg is on,
985 	 * forces the speed to the current settings in phydev
986 	 * if phydev->autoneg is off
987 	 */
988 	int (*config_aneg)(struct phy_device *phydev);
989 
990 	/** @aneg_done: Determines the auto negotiation result */
991 	int (*aneg_done)(struct phy_device *phydev);
992 
993 	/** @read_status: Determines the negotiated speed and duplex */
994 	int (*read_status)(struct phy_device *phydev);
995 
996 	/**
997 	 * @config_intr: Enables or disables interrupts.
998 	 * It should also clear any pending interrupts prior to enabling the
999 	 * IRQs and after disabling them.
1000 	 */
1001 	int (*config_intr)(struct phy_device *phydev);
1002 
1003 	/** @handle_interrupt: Override default interrupt handling */
1004 	irqreturn_t (*handle_interrupt)(struct phy_device *phydev);
1005 
1006 	/** @remove: Clears up any memory if needed */
1007 	void (*remove)(struct phy_device *phydev);
1008 
1009 	/**
1010 	 * @match_phy_device: Returns true if this is a suitable
1011 	 * driver for the given phydev.	 If NULL, matching is based on
1012 	 * phy_id and phy_id_mask.
1013 	 */
1014 	int (*match_phy_device)(struct phy_device *phydev,
1015 				const struct phy_driver *phydrv);
1016 
1017 	/**
1018 	 * @set_wol: Some devices (e.g. qnap TS-119P II) require PHY
1019 	 * register changes to enable Wake on LAN, so set_wol is
1020 	 * provided to be called in the ethernet driver's set_wol
1021 	 * function.
1022 	 */
1023 	int (*set_wol)(struct phy_device *dev, struct ethtool_wolinfo *wol);
1024 
1025 	/**
1026 	 * @get_wol: See set_wol, but for checking whether Wake on LAN
1027 	 * is enabled.
1028 	 */
1029 	void (*get_wol)(struct phy_device *dev, struct ethtool_wolinfo *wol);
1030 
1031 	/**
1032 	 * @link_change_notify: Called to inform a PHY device driver
1033 	 * when the core is about to change the link state. This
1034 	 * callback is supposed to be used as fixup hook for drivers
1035 	 * that need to take action when the link state
1036 	 * changes. Drivers are by no means allowed to mess with the
1037 	 * PHY device structure in their implementations.
1038 	 */
1039 	void (*link_change_notify)(struct phy_device *dev);
1040 
1041 	/**
1042 	 * @read_mmd: PHY specific driver override for reading a MMD
1043 	 * register.  This function is optional for PHY specific
1044 	 * drivers.  When not provided, the default MMD read function
1045 	 * will be used by phy_read_mmd(), which will use either a
1046 	 * direct read for Clause 45 PHYs or an indirect read for
1047 	 * Clause 22 PHYs.  devnum is the MMD device number within the
1048 	 * PHY device, regnum is the register within the selected MMD
1049 	 * device.
1050 	 */
1051 	int (*read_mmd)(struct phy_device *dev, int devnum, u16 regnum);
1052 
1053 	/**
1054 	 * @write_mmd: PHY specific driver override for writing a MMD
1055 	 * register.  This function is optional for PHY specific
1056 	 * drivers.  When not provided, the default MMD write function
1057 	 * will be used by phy_write_mmd(), which will use either a
1058 	 * direct write for Clause 45 PHYs, or an indirect write for
1059 	 * Clause 22 PHYs.  devnum is the MMD device number within the
1060 	 * PHY device, regnum is the register within the selected MMD
1061 	 * device.  val is the value to be written.
1062 	 */
1063 	int (*write_mmd)(struct phy_device *dev, int devnum, u16 regnum,
1064 			 u16 val);
1065 
1066 	/** @read_page: Return the current PHY register page number */
1067 	int (*read_page)(struct phy_device *dev);
1068 	/** @write_page: Set the current PHY register page number */
1069 	int (*write_page)(struct phy_device *dev, int page);
1070 
1071 	/**
1072 	 * @module_info: Get the size and type of the eeprom contained
1073 	 * within a plug-in module
1074 	 */
1075 	int (*module_info)(struct phy_device *dev,
1076 			   struct ethtool_modinfo *modinfo);
1077 
1078 	/**
1079 	 * @module_eeprom: Get the eeprom information from the plug-in
1080 	 * module
1081 	 */
1082 	int (*module_eeprom)(struct phy_device *dev,
1083 			     struct ethtool_eeprom *ee, u8 *data);
1084 
1085 	/** @cable_test_start: Start a cable test */
1086 	int (*cable_test_start)(struct phy_device *dev);
1087 
1088 	/**  @cable_test_tdr_start: Start a raw TDR cable test */
1089 	int (*cable_test_tdr_start)(struct phy_device *dev,
1090 				    const struct phy_tdr_config *config);
1091 
1092 	/**
1093 	 * @cable_test_get_status: Once per second, or on interrupt,
1094 	 * request the status of the test.
1095 	 */
1096 	int (*cable_test_get_status)(struct phy_device *dev, bool *finished);
1097 
1098 	/* Get statistics from the PHY using ethtool */
1099 	/**
1100 	 * @get_phy_stats: Retrieve PHY statistics.
1101 	 * @dev: The PHY device for which the statistics are retrieved.
1102 	 * @eth_stats: structure where Ethernet PHY stats will be stored.
1103 	 * @stats: structure where additional PHY-specific stats will be stored.
1104 	 *
1105 	 * Retrieves the supported PHY statistics and populates the provided
1106 	 * structures. The input structures are pre-initialized with
1107 	 * `ETHTOOL_STAT_NOT_SET`, and the driver must only modify members
1108 	 * corresponding to supported statistics. Unmodified members will remain
1109 	 * set to `ETHTOOL_STAT_NOT_SET` and will not be returned to userspace.
1110 	 */
1111 	void (*get_phy_stats)(struct phy_device *dev,
1112 			      struct ethtool_eth_phy_stats *eth_stats,
1113 			      struct ethtool_phy_stats *stats);
1114 
1115 	/**
1116 	 * @get_link_stats: Retrieve link statistics.
1117 	 * @dev: The PHY device for which the statistics are retrieved.
1118 	 * @link_stats: structure where link-specific stats will be stored.
1119 	 *
1120 	 * Retrieves link-related statistics for the given PHY device. The input
1121 	 * structure is pre-initialized with `ETHTOOL_STAT_NOT_SET`, and the
1122 	 * driver must only modify members corresponding to supported
1123 	 * statistics. Unmodified members will remain set to
1124 	 * `ETHTOOL_STAT_NOT_SET` and will not be returned to userspace.
1125 	 */
1126 	void (*get_link_stats)(struct phy_device *dev,
1127 			       struct ethtool_link_ext_stats *link_stats);
1128 
1129 	/**
1130 	 * @update_stats: Trigger periodic statistics updates.
1131 	 * @dev: The PHY device for which statistics updates are triggered.
1132 	 *
1133 	 * Periodically gathers statistics from the PHY device to update locally
1134 	 * maintained 64-bit counters. This is necessary for PHYs that implement
1135 	 * reduced-width counters (e.g., 16-bit or 32-bit) which can overflow
1136 	 * more frequently compared to 64-bit counters. By invoking this
1137 	 * callback, drivers can fetch the current counter values, handle
1138 	 * overflow detection, and accumulate the results into local 64-bit
1139 	 * counters for accurate reporting through the `get_phy_stats` and
1140 	 * `get_link_stats` interfaces.
1141 	 *
1142 	 * Return: 0 on success or a negative error code on failure.
1143 	 */
1144 	int (*update_stats)(struct phy_device *dev);
1145 
1146 	/** @get_sset_count: Number of statistic counters */
1147 	int (*get_sset_count)(struct phy_device *dev);
1148 	/** @get_strings: Names of the statistic counters */
1149 	void (*get_strings)(struct phy_device *dev, u8 *data);
1150 	/** @get_stats: Return the statistic counter values */
1151 	void (*get_stats)(struct phy_device *dev,
1152 			  struct ethtool_stats *stats, u64 *data);
1153 
1154 	/* Get and Set PHY tunables */
1155 	/** @get_tunable: Return the value of a tunable */
1156 	int (*get_tunable)(struct phy_device *dev,
1157 			   struct ethtool_tunable *tuna, void *data);
1158 	/** @set_tunable: Set the value of a tunable */
1159 	int (*set_tunable)(struct phy_device *dev,
1160 			    struct ethtool_tunable *tuna,
1161 			    const void *data);
1162 	/**
1163 	 * @set_loopback: Set the loopback mode of the PHY
1164 	 * enable selects if the loopback mode is enabled or disabled. If the
1165 	 * loopback mode is enabled, then the speed of the loopback mode can be
1166 	 * requested with the speed argument. If the speed argument is zero,
1167 	 * then any speed can be selected. If the speed argument is > 0, then
1168 	 * this speed shall be selected for the loopback mode or EOPNOTSUPP
1169 	 * shall be returned if speed selection is not supported.
1170 	 */
1171 	int (*set_loopback)(struct phy_device *dev, bool enable, int speed);
1172 	/** @get_sqi: Get the signal quality indication */
1173 	int (*get_sqi)(struct phy_device *dev);
1174 	/** @get_sqi_max: Get the maximum signal quality indication */
1175 	int (*get_sqi_max)(struct phy_device *dev);
1176 
1177 	/* PLCA RS interface */
1178 	/** @get_plca_cfg: Return the current PLCA configuration */
1179 	int (*get_plca_cfg)(struct phy_device *dev,
1180 			    struct phy_plca_cfg *plca_cfg);
1181 	/** @set_plca_cfg: Set the PLCA configuration */
1182 	int (*set_plca_cfg)(struct phy_device *dev,
1183 			    const struct phy_plca_cfg *plca_cfg);
1184 	/** @get_plca_status: Return the current PLCA status info */
1185 	int (*get_plca_status)(struct phy_device *dev,
1186 			       struct phy_plca_status *plca_st);
1187 
1188 	/**
1189 	 * @led_brightness_set: Set a PHY LED brightness. Index
1190 	 * indicates which of the PHYs led should be set. Value
1191 	 * follows the standard LED class meaning, e.g. LED_OFF,
1192 	 * LED_HALF, LED_FULL.
1193 	 */
1194 	int (*led_brightness_set)(struct phy_device *dev,
1195 				  u8 index, enum led_brightness value);
1196 
1197 	/**
1198 	 * @led_blink_set: Set a PHY LED blinking.  Index indicates
1199 	 * which of the PHYs led should be configured to blink. Delays
1200 	 * are in milliseconds and if both are zero then a sensible
1201 	 * default should be chosen.  The call should adjust the
1202 	 * timings in that case and if it can't match the values
1203 	 * specified exactly.
1204 	 */
1205 	int (*led_blink_set)(struct phy_device *dev, u8 index,
1206 			     unsigned long *delay_on,
1207 			     unsigned long *delay_off);
1208 	/**
1209 	 * @led_hw_is_supported: Can the HW support the given rules.
1210 	 * @dev: PHY device which has the LED
1211 	 * @index: Which LED of the PHY device
1212 	 * @rules The core is interested in these rules
1213 	 *
1214 	 * Return 0 if yes,  -EOPNOTSUPP if not, or an error code.
1215 	 */
1216 	int (*led_hw_is_supported)(struct phy_device *dev, u8 index,
1217 				   unsigned long rules);
1218 	/**
1219 	 * @led_hw_control_set: Set the HW to control the LED
1220 	 * @dev: PHY device which has the LED
1221 	 * @index: Which LED of the PHY device
1222 	 * @rules The rules used to control the LED
1223 	 *
1224 	 * Returns 0, or a an error code.
1225 	 */
1226 	int (*led_hw_control_set)(struct phy_device *dev, u8 index,
1227 				  unsigned long rules);
1228 	/**
1229 	 * @led_hw_control_get: Get how the HW is controlling the LED
1230 	 * @dev: PHY device which has the LED
1231 	 * @index: Which LED of the PHY device
1232 	 * @rules Pointer to the rules used to control the LED
1233 	 *
1234 	 * Set *@rules to how the HW is currently blinking. Returns 0
1235 	 * on success, or a error code if the current blinking cannot
1236 	 * be represented in rules, or some other error happens.
1237 	 */
1238 	int (*led_hw_control_get)(struct phy_device *dev, u8 index,
1239 				  unsigned long *rules);
1240 
1241 	/**
1242 	 * @led_polarity_set: Set the LED polarity modes
1243 	 * @dev: PHY device which has the LED
1244 	 * @index: Which LED of the PHY device
1245 	 * @modes: bitmap of LED polarity modes
1246 	 *
1247 	 * Configure LED with all the required polarity modes in @modes
1248 	 * to make it correctly turn ON or OFF.
1249 	 *
1250 	 * Returns 0, or an error code.
1251 	 */
1252 	int (*led_polarity_set)(struct phy_device *dev, int index,
1253 				unsigned long modes);
1254 
1255 	/**
1256 	 * @get_next_update_time: Get the time until the next update event
1257 	 * @dev: PHY device
1258 	 *
1259 	 * Callback to determine the time (in jiffies) until the next
1260 	 * update event for the PHY state  machine. Allows PHY drivers to
1261 	 * dynamically adjust polling intervals based on link state or other
1262 	 * conditions.
1263 	 *
1264 	 * Returns the time in jiffies until the next update event.
1265 	 */
1266 	unsigned int (*get_next_update_time)(struct phy_device *dev);
1267 };
1268 #define to_phy_driver(d) container_of_const(to_mdio_common_driver(d),		\
1269 				      struct phy_driver, mdiodrv)
1270 
1271 #define PHY_ID_MATCH_EXACT(id) .phy_id = (id), .phy_id_mask = GENMASK(31, 0)
1272 #define PHY_ID_MATCH_MODEL(id) .phy_id = (id), .phy_id_mask = GENMASK(31, 4)
1273 #define PHY_ID_MATCH_VENDOR(id) .phy_id = (id), .phy_id_mask = GENMASK(31, 10)
1274 
1275 /**
1276  * phy_id_compare - compare @id1 with @id2 taking account of @mask
1277  * @id1: first PHY ID
1278  * @id2: second PHY ID
1279  * @mask: the PHY ID mask, set bits are significant in matching
1280  *
1281  * Return true if the bits from @id1 and @id2 specified by @mask match.
1282  * This uses an equivalent test to (@id & @mask) == (@phy_id & @mask).
1283  */
phy_id_compare(u32 id1,u32 id2,u32 mask)1284 static inline bool phy_id_compare(u32 id1, u32 id2, u32 mask)
1285 {
1286 	return !((id1 ^ id2) & mask);
1287 }
1288 
1289 /**
1290  * phydev_id_compare - compare @id with the PHY's Clause 22 ID
1291  * @phydev: the PHY device
1292  * @id: the PHY ID to be matched
1293  *
1294  * Compare the @phydev clause 22 ID with the provided @id and return true or
1295  * false depending whether it matches, using the bound driver mask. The
1296  * @phydev must be bound to a driver.
1297  */
phydev_id_compare(struct phy_device * phydev,u32 id)1298 static inline bool phydev_id_compare(struct phy_device *phydev, u32 id)
1299 {
1300 	return phy_id_compare(id, phydev->phy_id, phydev->drv->phy_id_mask);
1301 }
1302 
1303 const char *phy_speed_to_str(int speed);
1304 const char *phy_duplex_to_str(unsigned int duplex);
1305 const char *phy_rate_matching_to_str(int rate_matching);
1306 
1307 int phy_interface_num_ports(phy_interface_t interface);
1308 
1309 /**
1310  * phy_is_started - Convenience function to check whether PHY is started
1311  * @phydev: The phy_device struct
1312  */
phy_is_started(struct phy_device * phydev)1313 static inline bool phy_is_started(struct phy_device *phydev)
1314 {
1315 	return phydev->state >= PHY_UP;
1316 }
1317 
1318 /**
1319  * phy_driver_is_genphy - Convenience function to check whether PHY is driven
1320  *                        by one of the generic PHY drivers
1321  * @phydev: The phy_device struct
1322  * Return: true if PHY is driven by one of the genphy drivers
1323  */
phy_driver_is_genphy(struct phy_device * phydev)1324 static inline bool phy_driver_is_genphy(struct phy_device *phydev)
1325 {
1326 	return phydev->is_genphy_driven;
1327 }
1328 
1329 /**
1330  * phy_disable_eee_mode - Don't advertise an EEE mode.
1331  * @phydev: The phy_device struct
1332  * @link_mode: The EEE mode to be disabled
1333  */
phy_disable_eee_mode(struct phy_device * phydev,u32 link_mode)1334 static inline void phy_disable_eee_mode(struct phy_device *phydev, u32 link_mode)
1335 {
1336 	WARN_ON(phy_is_started(phydev));
1337 
1338 	linkmode_set_bit(link_mode, phydev->eee_disabled_modes);
1339 	linkmode_clear_bit(link_mode, phydev->advertising_eee);
1340 }
1341 
1342 void phy_resolve_aneg_pause(struct phy_device *phydev);
1343 void phy_resolve_aneg_linkmode(struct phy_device *phydev);
1344 
1345 /**
1346  * phy_read - Convenience function for reading a given PHY register
1347  * @phydev: the phy_device struct
1348  * @regnum: register number to read
1349  *
1350  * NOTE: MUST NOT be called from interrupt context,
1351  * because the bus read/write functions may wait for an interrupt
1352  * to conclude the operation.
1353  */
phy_read(struct phy_device * phydev,u32 regnum)1354 static inline int phy_read(struct phy_device *phydev, u32 regnum)
1355 {
1356 	return mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, regnum);
1357 }
1358 
1359 #define phy_read_poll_timeout(phydev, regnum, val, cond, sleep_us, \
1360 				timeout_us, sleep_before_read) \
1361 ({ \
1362 	int __ret, __val; \
1363 	__ret = read_poll_timeout(__val = phy_read, val, \
1364 				  __val < 0 || (cond), \
1365 		sleep_us, timeout_us, sleep_before_read, phydev, regnum); \
1366 	if (__val < 0) \
1367 		__ret = __val; \
1368 	if (__ret) \
1369 		phydev_err(phydev, "%s failed: %d\n", __func__, __ret); \
1370 	__ret; \
1371 })
1372 
1373 /**
1374  * __phy_read - convenience function for reading a given PHY register
1375  * @phydev: the phy_device struct
1376  * @regnum: register number to read
1377  *
1378  * The caller must have taken the MDIO bus lock.
1379  */
__phy_read(struct phy_device * phydev,u32 regnum)1380 static inline int __phy_read(struct phy_device *phydev, u32 regnum)
1381 {
1382 	return __mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, regnum);
1383 }
1384 
1385 /**
1386  * phy_write - Convenience function for writing a given PHY register
1387  * @phydev: the phy_device struct
1388  * @regnum: register number to write
1389  * @val: value to write to @regnum
1390  *
1391  * NOTE: MUST NOT be called from interrupt context,
1392  * because the bus read/write functions may wait for an interrupt
1393  * to conclude the operation.
1394  */
phy_write(struct phy_device * phydev,u32 regnum,u16 val)1395 static inline int phy_write(struct phy_device *phydev, u32 regnum, u16 val)
1396 {
1397 	return mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, regnum, val);
1398 }
1399 
1400 /**
1401  * __phy_write - Convenience function for writing a given PHY register
1402  * @phydev: the phy_device struct
1403  * @regnum: register number to write
1404  * @val: value to write to @regnum
1405  *
1406  * The caller must have taken the MDIO bus lock.
1407  */
__phy_write(struct phy_device * phydev,u32 regnum,u16 val)1408 static inline int __phy_write(struct phy_device *phydev, u32 regnum, u16 val)
1409 {
1410 	return __mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, regnum,
1411 			       val);
1412 }
1413 
1414 /**
1415  * __phy_modify_changed() - Convenience function for modifying a PHY register
1416  * @phydev: a pointer to a &struct phy_device
1417  * @regnum: register number
1418  * @mask: bit mask of bits to clear
1419  * @set: bit mask of bits to set
1420  *
1421  * Unlocked helper function which allows a PHY register to be modified as
1422  * new register value = (old register value & ~mask) | set
1423  *
1424  * Returns negative errno, 0 if there was no change, and 1 in case of change
1425  */
__phy_modify_changed(struct phy_device * phydev,u32 regnum,u16 mask,u16 set)1426 static inline int __phy_modify_changed(struct phy_device *phydev, u32 regnum,
1427 				       u16 mask, u16 set)
1428 {
1429 	return __mdiobus_modify_changed(phydev->mdio.bus, phydev->mdio.addr,
1430 					regnum, mask, set);
1431 }
1432 
1433 /*
1434  * phy_read_mmd - Convenience function for reading a register
1435  * from an MMD on a given PHY.
1436  */
1437 int phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum);
1438 
1439 /**
1440  * phy_read_mmd_poll_timeout - Periodically poll a PHY register until a
1441  *                             condition is met or a timeout occurs
1442  *
1443  * @phydev: The phy_device struct
1444  * @devaddr: The MMD to read from
1445  * @regnum: The register on the MMD to read
1446  * @val: Variable to read the register into
1447  * @cond: Break condition (usually involving @val)
1448  * @sleep_us: Maximum time to sleep between reads in us (0 tight-loops). Please
1449  *            read usleep_range() function description for details and
1450  *            limitations.
1451  * @timeout_us: Timeout in us, 0 means never timeout
1452  * @sleep_before_read: if it is true, sleep @sleep_us before read.
1453  *
1454  * Returns: 0 on success and -ETIMEDOUT upon a timeout. In either
1455  * case, the last read value at @args is stored in @val. Must not
1456  * be called from atomic context if sleep_us or timeout_us are used.
1457  */
1458 #define phy_read_mmd_poll_timeout(phydev, devaddr, regnum, val, cond, \
1459 				  sleep_us, timeout_us, sleep_before_read) \
1460 ({ \
1461 	int __ret, __val; \
1462 	__ret = read_poll_timeout(__val = phy_read_mmd, val, \
1463 				  __val < 0 || (cond), \
1464 				  sleep_us, timeout_us, sleep_before_read, \
1465 				  phydev, devaddr, regnum); \
1466 	if (__val < 0) \
1467 		__ret = __val; \
1468 	if (__ret) \
1469 		phydev_err(phydev, "%s failed: %d\n", __func__, __ret); \
1470 	__ret; \
1471 })
1472 
1473 /*
1474  * __phy_read_mmd - Convenience function for reading a register
1475  * from an MMD on a given PHY.
1476  */
1477 int __phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum);
1478 
1479 /*
1480  * phy_write_mmd - Convenience function for writing a register
1481  * on an MMD on a given PHY.
1482  */
1483 int phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val);
1484 
1485 /*
1486  * __phy_write_mmd - Convenience function for writing a register
1487  * on an MMD on a given PHY.
1488  */
1489 int __phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val);
1490 
1491 int __phy_modify_changed(struct phy_device *phydev, u32 regnum, u16 mask,
1492 			 u16 set);
1493 int phy_modify_changed(struct phy_device *phydev, u32 regnum, u16 mask,
1494 		       u16 set);
1495 int __phy_modify(struct phy_device *phydev, u32 regnum, u16 mask, u16 set);
1496 int phy_modify(struct phy_device *phydev, u32 regnum, u16 mask, u16 set);
1497 
1498 int __phy_modify_mmd_changed(struct phy_device *phydev, int devad, u32 regnum,
1499 			     u16 mask, u16 set);
1500 int phy_modify_mmd_changed(struct phy_device *phydev, int devad, u32 regnum,
1501 			   u16 mask, u16 set);
1502 int __phy_modify_mmd(struct phy_device *phydev, int devad, u32 regnum,
1503 		     u16 mask, u16 set);
1504 int phy_modify_mmd(struct phy_device *phydev, int devad, u32 regnum,
1505 		   u16 mask, u16 set);
1506 
1507 /**
1508  * __phy_set_bits - Convenience function for setting bits in a PHY register
1509  * @phydev: the phy_device struct
1510  * @regnum: register number to write
1511  * @val: bits to set
1512  *
1513  * The caller must have taken the MDIO bus lock.
1514  */
__phy_set_bits(struct phy_device * phydev,u32 regnum,u16 val)1515 static inline int __phy_set_bits(struct phy_device *phydev, u32 regnum, u16 val)
1516 {
1517 	return __phy_modify(phydev, regnum, 0, val);
1518 }
1519 
1520 /**
1521  * __phy_clear_bits - Convenience function for clearing bits in a PHY register
1522  * @phydev: the phy_device struct
1523  * @regnum: register number to write
1524  * @val: bits to clear
1525  *
1526  * The caller must have taken the MDIO bus lock.
1527  */
__phy_clear_bits(struct phy_device * phydev,u32 regnum,u16 val)1528 static inline int __phy_clear_bits(struct phy_device *phydev, u32 regnum,
1529 				   u16 val)
1530 {
1531 	return __phy_modify(phydev, regnum, val, 0);
1532 }
1533 
1534 /**
1535  * phy_set_bits - Convenience function for setting bits in a PHY register
1536  * @phydev: the phy_device struct
1537  * @regnum: register number to write
1538  * @val: bits to set
1539  */
phy_set_bits(struct phy_device * phydev,u32 regnum,u16 val)1540 static inline int phy_set_bits(struct phy_device *phydev, u32 regnum, u16 val)
1541 {
1542 	return phy_modify(phydev, regnum, 0, val);
1543 }
1544 
1545 /**
1546  * phy_clear_bits - Convenience function for clearing bits in a PHY register
1547  * @phydev: the phy_device struct
1548  * @regnum: register number to write
1549  * @val: bits to clear
1550  */
phy_clear_bits(struct phy_device * phydev,u32 regnum,u16 val)1551 static inline int phy_clear_bits(struct phy_device *phydev, u32 regnum, u16 val)
1552 {
1553 	return phy_modify(phydev, regnum, val, 0);
1554 }
1555 
1556 /**
1557  * __phy_set_bits_mmd - Convenience function for setting bits in a register
1558  * on MMD
1559  * @phydev: the phy_device struct
1560  * @devad: the MMD containing register to modify
1561  * @regnum: register number to modify
1562  * @val: bits to set
1563  *
1564  * The caller must have taken the MDIO bus lock.
1565  */
__phy_set_bits_mmd(struct phy_device * phydev,int devad,u32 regnum,u16 val)1566 static inline int __phy_set_bits_mmd(struct phy_device *phydev, int devad,
1567 		u32 regnum, u16 val)
1568 {
1569 	return __phy_modify_mmd(phydev, devad, regnum, 0, val);
1570 }
1571 
1572 /**
1573  * __phy_clear_bits_mmd - Convenience function for clearing bits in a register
1574  * on MMD
1575  * @phydev: the phy_device struct
1576  * @devad: the MMD containing register to modify
1577  * @regnum: register number to modify
1578  * @val: bits to clear
1579  *
1580  * The caller must have taken the MDIO bus lock.
1581  */
__phy_clear_bits_mmd(struct phy_device * phydev,int devad,u32 regnum,u16 val)1582 static inline int __phy_clear_bits_mmd(struct phy_device *phydev, int devad,
1583 		u32 regnum, u16 val)
1584 {
1585 	return __phy_modify_mmd(phydev, devad, regnum, val, 0);
1586 }
1587 
1588 /**
1589  * phy_set_bits_mmd - Convenience function for setting bits in a register
1590  * on MMD
1591  * @phydev: the phy_device struct
1592  * @devad: the MMD containing register to modify
1593  * @regnum: register number to modify
1594  * @val: bits to set
1595  */
phy_set_bits_mmd(struct phy_device * phydev,int devad,u32 regnum,u16 val)1596 static inline int phy_set_bits_mmd(struct phy_device *phydev, int devad,
1597 		u32 regnum, u16 val)
1598 {
1599 	return phy_modify_mmd(phydev, devad, regnum, 0, val);
1600 }
1601 
1602 /**
1603  * phy_clear_bits_mmd - Convenience function for clearing bits in a register
1604  * on MMD
1605  * @phydev: the phy_device struct
1606  * @devad: the MMD containing register to modify
1607  * @regnum: register number to modify
1608  * @val: bits to clear
1609  */
phy_clear_bits_mmd(struct phy_device * phydev,int devad,u32 regnum,u16 val)1610 static inline int phy_clear_bits_mmd(struct phy_device *phydev, int devad,
1611 		u32 regnum, u16 val)
1612 {
1613 	return phy_modify_mmd(phydev, devad, regnum, val, 0);
1614 }
1615 
1616 /**
1617  * phy_interrupt_is_valid - Convenience function for testing a given PHY irq
1618  * @phydev: the phy_device struct
1619  *
1620  * NOTE: must be kept in sync with addition/removal of PHY_POLL and
1621  * PHY_MAC_INTERRUPT
1622  */
phy_interrupt_is_valid(struct phy_device * phydev)1623 static inline bool phy_interrupt_is_valid(struct phy_device *phydev)
1624 {
1625 	return phydev->irq != PHY_POLL && phydev->irq != PHY_MAC_INTERRUPT;
1626 }
1627 
1628 /**
1629  * phy_polling_mode - Convenience function for testing whether polling is
1630  * used to detect PHY status changes
1631  * @phydev: the phy_device struct
1632  */
phy_polling_mode(struct phy_device * phydev)1633 static inline bool phy_polling_mode(struct phy_device *phydev)
1634 {
1635 	if (phydev->state == PHY_CABLETEST)
1636 		if (phydev->drv->flags & PHY_POLL_CABLE_TEST)
1637 			return true;
1638 
1639 	if (phydev->drv->update_stats)
1640 		return true;
1641 
1642 	return phydev->irq == PHY_POLL;
1643 }
1644 
1645 /**
1646  * phy_has_hwtstamp - Tests whether a PHY time stamp configuration.
1647  * @phydev: the phy_device struct
1648  */
phy_has_hwtstamp(struct phy_device * phydev)1649 static inline bool phy_has_hwtstamp(struct phy_device *phydev)
1650 {
1651 	return phydev && phydev->mii_ts && phydev->mii_ts->hwtstamp;
1652 }
1653 
1654 /**
1655  * phy_has_rxtstamp - Tests whether a PHY supports receive time stamping.
1656  * @phydev: the phy_device struct
1657  */
phy_has_rxtstamp(struct phy_device * phydev)1658 static inline bool phy_has_rxtstamp(struct phy_device *phydev)
1659 {
1660 	return phydev && phydev->mii_ts && phydev->mii_ts->rxtstamp;
1661 }
1662 
1663 /**
1664  * phy_has_tsinfo - Tests whether a PHY reports time stamping and/or
1665  * PTP hardware clock capabilities.
1666  * @phydev: the phy_device struct
1667  */
phy_has_tsinfo(struct phy_device * phydev)1668 static inline bool phy_has_tsinfo(struct phy_device *phydev)
1669 {
1670 	return phydev && phydev->mii_ts && phydev->mii_ts->ts_info;
1671 }
1672 
1673 /**
1674  * phy_has_txtstamp - Tests whether a PHY supports transmit time stamping.
1675  * @phydev: the phy_device struct
1676  */
phy_has_txtstamp(struct phy_device * phydev)1677 static inline bool phy_has_txtstamp(struct phy_device *phydev)
1678 {
1679 	return phydev && phydev->mii_ts && phydev->mii_ts->txtstamp;
1680 }
1681 
phy_hwtstamp(struct phy_device * phydev,struct kernel_hwtstamp_config * cfg,struct netlink_ext_ack * extack)1682 static inline int phy_hwtstamp(struct phy_device *phydev,
1683 			       struct kernel_hwtstamp_config *cfg,
1684 			       struct netlink_ext_ack *extack)
1685 {
1686 	return phydev->mii_ts->hwtstamp(phydev->mii_ts, cfg, extack);
1687 }
1688 
phy_rxtstamp(struct phy_device * phydev,struct sk_buff * skb,int type)1689 static inline bool phy_rxtstamp(struct phy_device *phydev, struct sk_buff *skb,
1690 				int type)
1691 {
1692 	return phydev->mii_ts->rxtstamp(phydev->mii_ts, skb, type);
1693 }
1694 
phy_ts_info(struct phy_device * phydev,struct kernel_ethtool_ts_info * tsinfo)1695 static inline int phy_ts_info(struct phy_device *phydev,
1696 			      struct kernel_ethtool_ts_info *tsinfo)
1697 {
1698 	return phydev->mii_ts->ts_info(phydev->mii_ts, tsinfo);
1699 }
1700 
phy_txtstamp(struct phy_device * phydev,struct sk_buff * skb,int type)1701 static inline void phy_txtstamp(struct phy_device *phydev, struct sk_buff *skb,
1702 				int type)
1703 {
1704 	phydev->mii_ts->txtstamp(phydev->mii_ts, skb, type);
1705 }
1706 
1707 /**
1708  * phy_is_default_hwtstamp - Is the PHY hwtstamp the default timestamp
1709  * @phydev: Pointer to phy_device
1710  *
1711  * This is used to get default timestamping device taking into account
1712  * the new API choice, which is selecting the timestamping from MAC by
1713  * default if the phydev does not have default_timestamp flag enabled.
1714  *
1715  * Return: True if phy is the default hw timestamp, false otherwise.
1716  */
phy_is_default_hwtstamp(struct phy_device * phydev)1717 static inline bool phy_is_default_hwtstamp(struct phy_device *phydev)
1718 {
1719 	return phy_has_hwtstamp(phydev) && phydev->default_timestamp;
1720 }
1721 
1722 /**
1723  * phy_on_sfp - Convenience function for testing if a PHY is on an SFP module
1724  * @phydev: the phy_device struct
1725  */
phy_on_sfp(struct phy_device * phydev)1726 static inline bool phy_on_sfp(struct phy_device *phydev)
1727 {
1728 	return phydev->is_on_sfp_module;
1729 }
1730 
1731 /**
1732  * phy_interface_mode_is_rgmii - Convenience function for testing if a
1733  * PHY interface mode is RGMII (all variants)
1734  * @mode: the &phy_interface_t enum
1735  */
phy_interface_mode_is_rgmii(phy_interface_t mode)1736 static inline bool phy_interface_mode_is_rgmii(phy_interface_t mode)
1737 {
1738 	return mode >= PHY_INTERFACE_MODE_RGMII &&
1739 		mode <= PHY_INTERFACE_MODE_RGMII_TXID;
1740 };
1741 
1742 /**
1743  * phy_interface_mode_is_8023z() - does the PHY interface mode use 802.3z
1744  *   negotiation
1745  * @mode: one of &enum phy_interface_t
1746  *
1747  * Returns true if the PHY interface mode uses the 16-bit negotiation
1748  * word as defined in 802.3z. (See 802.3-2015 37.2.1 Config_Reg encoding)
1749  */
phy_interface_mode_is_8023z(phy_interface_t mode)1750 static inline bool phy_interface_mode_is_8023z(phy_interface_t mode)
1751 {
1752 	return mode == PHY_INTERFACE_MODE_1000BASEX ||
1753 	       mode == PHY_INTERFACE_MODE_2500BASEX;
1754 }
1755 
1756 /**
1757  * phy_interface_is_rgmii - Convenience function for testing if a PHY interface
1758  * is RGMII (all variants)
1759  * @phydev: the phy_device struct
1760  */
phy_interface_is_rgmii(struct phy_device * phydev)1761 static inline bool phy_interface_is_rgmii(struct phy_device *phydev)
1762 {
1763 	return phy_interface_mode_is_rgmii(phydev->interface);
1764 };
1765 
1766 /**
1767  * phy_is_pseudo_fixed_link - Convenience function for testing if this
1768  * PHY is the CPU port facing side of an Ethernet switch, or similar.
1769  * @phydev: the phy_device struct
1770  */
phy_is_pseudo_fixed_link(struct phy_device * phydev)1771 static inline bool phy_is_pseudo_fixed_link(struct phy_device *phydev)
1772 {
1773 	return phydev->is_pseudo_fixed_link;
1774 }
1775 
1776 int phy_save_page(struct phy_device *phydev);
1777 int phy_select_page(struct phy_device *phydev, int page);
1778 int phy_restore_page(struct phy_device *phydev, int oldpage, int ret);
1779 int phy_read_paged(struct phy_device *phydev, int page, u32 regnum);
1780 int phy_write_paged(struct phy_device *phydev, int page, u32 regnum, u16 val);
1781 int phy_modify_paged_changed(struct phy_device *phydev, int page, u32 regnum,
1782 			     u16 mask, u16 set);
1783 int phy_modify_paged(struct phy_device *phydev, int page, u32 regnum,
1784 		     u16 mask, u16 set);
1785 
1786 struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id,
1787 				     bool is_c45,
1788 				     struct phy_c45_device_ids *c45_ids);
1789 int fwnode_get_phy_id(struct fwnode_handle *fwnode, u32 *phy_id);
1790 struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode);
1791 struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode);
1792 struct fwnode_handle *fwnode_get_phy_node(const struct fwnode_handle *fwnode);
1793 struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45);
1794 int phy_device_register(struct phy_device *phy);
1795 void phy_device_free(struct phy_device *phydev);
1796 void phy_device_remove(struct phy_device *phydev);
1797 int phy_get_c45_ids(struct phy_device *phydev);
1798 int phy_init_hw(struct phy_device *phydev);
1799 int phy_suspend(struct phy_device *phydev);
1800 int phy_resume(struct phy_device *phydev);
1801 int __phy_resume(struct phy_device *phydev);
1802 int phy_loopback(struct phy_device *phydev, bool enable, int speed);
1803 int phy_sfp_connect_phy(void *upstream, struct phy_device *phy);
1804 void phy_sfp_disconnect_phy(void *upstream, struct phy_device *phy);
1805 void phy_sfp_attach(void *upstream, struct sfp_bus *bus);
1806 void phy_sfp_detach(void *upstream, struct sfp_bus *bus);
1807 int phy_sfp_probe(struct phy_device *phydev,
1808 	          const struct sfp_upstream_ops *ops);
1809 struct phy_device *phy_attach(struct net_device *dev, const char *bus_id,
1810 			      phy_interface_t interface);
1811 struct phy_device *phy_find_first(struct mii_bus *bus);
1812 int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
1813 		      u32 flags, phy_interface_t interface);
1814 int phy_connect_direct(struct net_device *dev, struct phy_device *phydev,
1815 		       void (*handler)(struct net_device *),
1816 		       phy_interface_t interface);
1817 struct phy_device *phy_connect(struct net_device *dev, const char *bus_id,
1818 			       void (*handler)(struct net_device *),
1819 			       phy_interface_t interface);
1820 void phy_disconnect(struct phy_device *phydev);
1821 void phy_detach(struct phy_device *phydev);
1822 void phy_start(struct phy_device *phydev);
1823 void phy_stop(struct phy_device *phydev);
1824 int phy_config_aneg(struct phy_device *phydev);
1825 int _phy_start_aneg(struct phy_device *phydev);
1826 int phy_start_aneg(struct phy_device *phydev);
1827 int phy_aneg_done(struct phy_device *phydev);
1828 unsigned int phy_inband_caps(struct phy_device *phydev,
1829 			     phy_interface_t interface);
1830 int phy_config_inband(struct phy_device *phydev, unsigned int modes);
1831 int phy_speed_down(struct phy_device *phydev, bool sync);
1832 int phy_speed_up(struct phy_device *phydev);
1833 bool phy_check_valid(int speed, int duplex, unsigned long *features);
1834 
1835 int phy_restart_aneg(struct phy_device *phydev);
1836 int phy_reset_after_clk_enable(struct phy_device *phydev);
1837 
1838 #if IS_ENABLED(CONFIG_PHYLIB)
1839 int phy_start_cable_test(struct phy_device *phydev,
1840 			 struct netlink_ext_ack *extack);
1841 int phy_start_cable_test_tdr(struct phy_device *phydev,
1842 			     struct netlink_ext_ack *extack,
1843 			     const struct phy_tdr_config *config);
1844 #else
1845 static inline
phy_start_cable_test(struct phy_device * phydev,struct netlink_ext_ack * extack)1846 int phy_start_cable_test(struct phy_device *phydev,
1847 			 struct netlink_ext_ack *extack)
1848 {
1849 	NL_SET_ERR_MSG(extack, "Kernel not compiled with PHYLIB support");
1850 	return -EOPNOTSUPP;
1851 }
1852 static inline
phy_start_cable_test_tdr(struct phy_device * phydev,struct netlink_ext_ack * extack,const struct phy_tdr_config * config)1853 int phy_start_cable_test_tdr(struct phy_device *phydev,
1854 			     struct netlink_ext_ack *extack,
1855 			     const struct phy_tdr_config *config)
1856 {
1857 	NL_SET_ERR_MSG(extack, "Kernel not compiled with PHYLIB support");
1858 	return -EOPNOTSUPP;
1859 }
1860 #endif
1861 
phy_device_reset(struct phy_device * phydev,int value)1862 static inline void phy_device_reset(struct phy_device *phydev, int value)
1863 {
1864 	mdio_device_reset(&phydev->mdio, value);
1865 }
1866 
1867 #define phydev_err(_phydev, format, args...)	\
1868 	dev_err(&_phydev->mdio.dev, format, ##args)
1869 
1870 #define phydev_err_probe(_phydev, err, format, args...)	\
1871 	dev_err_probe(&_phydev->mdio.dev, err, format, ##args)
1872 
1873 #define phydev_info(_phydev, format, args...)	\
1874 	dev_info(&_phydev->mdio.dev, format, ##args)
1875 
1876 #define phydev_warn(_phydev, format, args...)	\
1877 	dev_warn(&_phydev->mdio.dev, format, ##args)
1878 
1879 #define phydev_dbg(_phydev, format, args...)	\
1880 	dev_dbg(&_phydev->mdio.dev, format, ##args)
1881 
phydev_name(const struct phy_device * phydev)1882 static inline const char *phydev_name(const struct phy_device *phydev)
1883 {
1884 	return dev_name(&phydev->mdio.dev);
1885 }
1886 
phy_lock_mdio_bus(struct phy_device * phydev)1887 static inline void phy_lock_mdio_bus(struct phy_device *phydev)
1888 {
1889 	mutex_lock(&phydev->mdio.bus->mdio_lock);
1890 }
1891 
phy_unlock_mdio_bus(struct phy_device * phydev)1892 static inline void phy_unlock_mdio_bus(struct phy_device *phydev)
1893 {
1894 	mutex_unlock(&phydev->mdio.bus->mdio_lock);
1895 }
1896 
1897 void phy_attached_print(struct phy_device *phydev, const char *fmt, ...)
1898 	__printf(2, 3);
1899 char *phy_attached_info_irq(struct phy_device *phydev)
1900 	__malloc;
1901 void phy_attached_info(struct phy_device *phydev);
1902 
1903 int genphy_match_phy_device(struct phy_device *phydev,
1904 			    const struct phy_driver *phydrv);
1905 
1906 /* Clause 22 PHY */
1907 int genphy_read_abilities(struct phy_device *phydev);
1908 int genphy_setup_forced(struct phy_device *phydev);
1909 int genphy_restart_aneg(struct phy_device *phydev);
1910 int genphy_check_and_restart_aneg(struct phy_device *phydev, bool restart);
1911 int __genphy_config_aneg(struct phy_device *phydev, bool changed);
1912 int genphy_aneg_done(struct phy_device *phydev);
1913 int genphy_update_link(struct phy_device *phydev);
1914 int genphy_read_lpa(struct phy_device *phydev);
1915 int genphy_read_status_fixed(struct phy_device *phydev);
1916 int genphy_read_status(struct phy_device *phydev);
1917 int genphy_read_master_slave(struct phy_device *phydev);
1918 int genphy_suspend(struct phy_device *phydev);
1919 int genphy_resume(struct phy_device *phydev);
1920 int genphy_loopback(struct phy_device *phydev, bool enable, int speed);
1921 int genphy_soft_reset(struct phy_device *phydev);
1922 irqreturn_t genphy_handle_interrupt_no_ack(struct phy_device *phydev);
1923 
genphy_config_aneg(struct phy_device * phydev)1924 static inline int genphy_config_aneg(struct phy_device *phydev)
1925 {
1926 	return __genphy_config_aneg(phydev, false);
1927 }
1928 
genphy_no_config_intr(struct phy_device * phydev)1929 static inline int genphy_no_config_intr(struct phy_device *phydev)
1930 {
1931 	return 0;
1932 }
1933 int genphy_read_mmd_unsupported(struct phy_device *phdev, int devad,
1934 				u16 regnum);
1935 int genphy_write_mmd_unsupported(struct phy_device *phdev, int devnum,
1936 				 u16 regnum, u16 val);
1937 
1938 /* Clause 37 */
1939 int genphy_c37_config_aneg(struct phy_device *phydev);
1940 int genphy_c37_read_status(struct phy_device *phydev, bool *changed);
1941 
1942 /* Clause 45 PHY */
1943 int genphy_c45_restart_aneg(struct phy_device *phydev);
1944 int genphy_c45_check_and_restart_aneg(struct phy_device *phydev, bool restart);
1945 int genphy_c45_aneg_done(struct phy_device *phydev);
1946 int genphy_c45_read_link(struct phy_device *phydev);
1947 int genphy_c45_read_lpa(struct phy_device *phydev);
1948 int genphy_c45_read_pma(struct phy_device *phydev);
1949 int genphy_c45_pma_setup_forced(struct phy_device *phydev);
1950 int genphy_c45_pma_baset1_setup_master_slave(struct phy_device *phydev);
1951 int genphy_c45_an_config_aneg(struct phy_device *phydev);
1952 int genphy_c45_an_disable_aneg(struct phy_device *phydev);
1953 int genphy_c45_read_mdix(struct phy_device *phydev);
1954 int genphy_c45_pma_read_abilities(struct phy_device *phydev);
1955 int genphy_c45_pma_read_ext_abilities(struct phy_device *phydev);
1956 int genphy_c45_pma_baset1_read_abilities(struct phy_device *phydev);
1957 int genphy_c45_read_eee_abilities(struct phy_device *phydev);
1958 int genphy_c45_pma_baset1_read_master_slave(struct phy_device *phydev);
1959 int genphy_c45_read_status(struct phy_device *phydev);
1960 int genphy_c45_baset1_read_status(struct phy_device *phydev);
1961 int genphy_c45_config_aneg(struct phy_device *phydev);
1962 int genphy_c45_loopback(struct phy_device *phydev, bool enable, int speed);
1963 int genphy_c45_pma_resume(struct phy_device *phydev);
1964 int genphy_c45_pma_suspend(struct phy_device *phydev);
1965 int genphy_c45_fast_retrain(struct phy_device *phydev, bool enable);
1966 int genphy_c45_plca_get_cfg(struct phy_device *phydev,
1967 			    struct phy_plca_cfg *plca_cfg);
1968 int genphy_c45_plca_set_cfg(struct phy_device *phydev,
1969 			    const struct phy_plca_cfg *plca_cfg);
1970 int genphy_c45_plca_get_status(struct phy_device *phydev,
1971 			       struct phy_plca_status *plca_st);
1972 int genphy_c45_eee_is_active(struct phy_device *phydev, unsigned long *lp);
1973 int genphy_c45_ethtool_get_eee(struct phy_device *phydev,
1974 			       struct ethtool_keee *data);
1975 int genphy_c45_ethtool_set_eee(struct phy_device *phydev,
1976 			       struct ethtool_keee *data);
1977 int genphy_c45_an_config_eee_aneg(struct phy_device *phydev);
1978 
1979 /* The gen10g_* functions are the old Clause 45 stub */
1980 int gen10g_config_aneg(struct phy_device *phydev);
1981 
phy_read_status(struct phy_device * phydev)1982 static inline int phy_read_status(struct phy_device *phydev)
1983 {
1984 	if (!phydev->drv)
1985 		return -EIO;
1986 
1987 	if (phydev->drv->read_status)
1988 		return phydev->drv->read_status(phydev);
1989 	else
1990 		return genphy_read_status(phydev);
1991 }
1992 
1993 void phy_driver_unregister(struct phy_driver *drv);
1994 void phy_drivers_unregister(struct phy_driver *drv, int n);
1995 int phy_driver_register(struct phy_driver *new_driver, struct module *owner);
1996 int phy_drivers_register(struct phy_driver *new_driver, int n,
1997 			 struct module *owner);
1998 void phy_error(struct phy_device *phydev);
1999 void phy_state_machine(struct work_struct *work);
2000 void phy_trigger_machine(struct phy_device *phydev);
2001 void phy_mac_interrupt(struct phy_device *phydev);
2002 void phy_start_machine(struct phy_device *phydev);
2003 void phy_stop_machine(struct phy_device *phydev);
2004 void phy_ethtool_ksettings_get(struct phy_device *phydev,
2005 			       struct ethtool_link_ksettings *cmd);
2006 int phy_ethtool_ksettings_set(struct phy_device *phydev,
2007 			      const struct ethtool_link_ksettings *cmd);
2008 int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd);
2009 int phy_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
2010 int phy_do_ioctl_running(struct net_device *dev, struct ifreq *ifr, int cmd);
2011 int phy_disable_interrupts(struct phy_device *phydev);
2012 void phy_request_interrupt(struct phy_device *phydev);
2013 void phy_free_interrupt(struct phy_device *phydev);
2014 void phy_print_status(struct phy_device *phydev);
2015 int phy_get_rate_matching(struct phy_device *phydev,
2016 			    phy_interface_t iface);
2017 void phy_set_max_speed(struct phy_device *phydev, u32 max_speed);
2018 void phy_remove_link_mode(struct phy_device *phydev, u32 link_mode);
2019 void phy_advertise_supported(struct phy_device *phydev);
2020 void phy_advertise_eee_all(struct phy_device *phydev);
2021 void phy_support_sym_pause(struct phy_device *phydev);
2022 void phy_support_asym_pause(struct phy_device *phydev);
2023 void phy_support_eee(struct phy_device *phydev);
2024 void phy_disable_eee(struct phy_device *phydev);
2025 void phy_set_sym_pause(struct phy_device *phydev, bool rx, bool tx,
2026 		       bool autoneg);
2027 void phy_set_asym_pause(struct phy_device *phydev, bool rx, bool tx);
2028 bool phy_validate_pause(struct phy_device *phydev,
2029 			struct ethtool_pauseparam *pp);
2030 void phy_get_pause(struct phy_device *phydev, bool *tx_pause, bool *rx_pause);
2031 
2032 s32 phy_get_internal_delay(struct phy_device *phydev, const int *delay_values,
2033 			   int size, bool is_rx);
2034 
2035 int phy_get_tx_amplitude_gain(struct phy_device *phydev, struct device *dev,
2036 			      enum ethtool_link_mode_bit_indices linkmode,
2037 			      u32 *val);
2038 
2039 int phy_get_mac_termination(struct phy_device *phydev, struct device *dev,
2040 			    u32 *val);
2041 
2042 void phy_resolve_pause(unsigned long *local_adv, unsigned long *partner_adv,
2043 		       bool *tx_pause, bool *rx_pause);
2044 
2045 int phy_register_fixup_for_id(const char *bus_id,
2046 			      int (*run)(struct phy_device *));
2047 int phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask,
2048 			       int (*run)(struct phy_device *));
2049 
2050 int phy_unregister_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask);
2051 int phy_unregister_fixup_for_id(const char *bus_id);
2052 int phy_unregister_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask);
2053 
2054 int phy_eee_tx_clock_stop_capable(struct phy_device *phydev);
2055 int phy_eee_rx_clock_stop(struct phy_device *phydev, bool clk_stop_enable);
2056 int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable);
2057 int phy_get_eee_err(struct phy_device *phydev);
2058 int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_keee *data);
2059 int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_keee *data);
2060 int phy_ethtool_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol);
2061 void phy_ethtool_get_wol(struct phy_device *phydev,
2062 			 struct ethtool_wolinfo *wol);
2063 int phy_ethtool_get_link_ksettings(struct net_device *ndev,
2064 				   struct ethtool_link_ksettings *cmd);
2065 int phy_ethtool_set_link_ksettings(struct net_device *ndev,
2066 				   const struct ethtool_link_ksettings *cmd);
2067 int phy_ethtool_nway_reset(struct net_device *ndev);
2068 
2069 int phy_ethtool_get_strings(struct phy_device *phydev, u8 *data);
2070 int phy_ethtool_get_sset_count(struct phy_device *phydev);
2071 int phy_ethtool_get_stats(struct phy_device *phydev,
2072 			  struct ethtool_stats *stats, u64 *data);
2073 
2074 void __phy_ethtool_get_phy_stats(struct phy_device *phydev,
2075 			 struct ethtool_eth_phy_stats *phy_stats,
2076 			 struct ethtool_phy_stats *phydev_stats);
2077 void __phy_ethtool_get_link_ext_stats(struct phy_device *phydev,
2078 				      struct ethtool_link_ext_stats *link_stats);
2079 
2080 int phy_ethtool_get_plca_cfg(struct phy_device *phydev,
2081 			     struct phy_plca_cfg *plca_cfg);
2082 int phy_ethtool_set_plca_cfg(struct phy_device *phydev,
2083 			     const struct phy_plca_cfg *plca_cfg,
2084 			     struct netlink_ext_ack *extack);
2085 int phy_ethtool_get_plca_status(struct phy_device *phydev,
2086 				struct phy_plca_status *plca_st);
2087 
2088 int __phy_hwtstamp_get(struct phy_device *phydev,
2089 		       struct kernel_hwtstamp_config *config);
2090 int __phy_hwtstamp_set(struct phy_device *phydev,
2091 		       struct kernel_hwtstamp_config *config,
2092 		       struct netlink_ext_ack *extack);
2093 
2094 extern const struct bus_type mdio_bus_type;
2095 extern const struct class mdio_bus_class;
2096 
2097 struct mdio_board_info {
2098 	const char	*bus_id;
2099 	char		modalias[MDIO_NAME_SIZE];
2100 	int		mdio_addr;
2101 	const void	*platform_data;
2102 };
2103 
2104 int mdiobus_register_board_info(const struct mdio_board_info *info,
2105 				unsigned int n);
2106 
2107 /**
2108  * phy_module_driver() - Helper macro for registering PHY drivers
2109  * @__phy_drivers: array of PHY drivers to register
2110  * @__count: Numbers of members in array
2111  *
2112  * Helper macro for PHY drivers which do not do anything special in module
2113  * init/exit. Each module may only use this macro once, and calling it
2114  * replaces module_init() and module_exit().
2115  */
2116 #define phy_module_driver(__phy_drivers, __count)			\
2117 static int __init phy_module_init(void)					\
2118 {									\
2119 	return phy_drivers_register(__phy_drivers, __count, THIS_MODULE); \
2120 }									\
2121 module_init(phy_module_init);						\
2122 static void __exit phy_module_exit(void)				\
2123 {									\
2124 	phy_drivers_unregister(__phy_drivers, __count);			\
2125 }									\
2126 module_exit(phy_module_exit)
2127 
2128 #define module_phy_driver(__phy_drivers)				\
2129 	phy_module_driver(__phy_drivers, ARRAY_SIZE(__phy_drivers))
2130 
2131 #endif /* __PHY_H */
2132