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