xref: /openbmc/linux/include/linux/mdio.h (revision e6a45700)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * linux/mdio.h: definitions for MDIO (clause 45) transceivers
4  * Copyright 2006-2009 Solarflare Communications Inc.
5  */
6 #ifndef __LINUX_MDIO_H__
7 #define __LINUX_MDIO_H__
8 
9 #include <uapi/linux/mdio.h>
10 #include <linux/bitfield.h>
11 #include <linux/mod_devicetable.h>
12 
13 struct gpio_desc;
14 struct mii_bus;
15 struct reset_control;
16 
17 /* Multiple levels of nesting are possible. However typically this is
18  * limited to nested DSA like layer, a MUX layer, and the normal
19  * user. Instead of trying to handle the general case, just define
20  * these cases.
21  */
22 enum mdio_mutex_lock_class {
23 	MDIO_MUTEX_NORMAL,
24 	MDIO_MUTEX_MUX,
25 	MDIO_MUTEX_NESTED,
26 };
27 
28 struct mdio_device {
29 	struct device dev;
30 
31 	struct mii_bus *bus;
32 	char modalias[MDIO_NAME_SIZE];
33 
34 	int (*bus_match)(struct device *dev, struct device_driver *drv);
35 	void (*device_free)(struct mdio_device *mdiodev);
36 	void (*device_remove)(struct mdio_device *mdiodev);
37 
38 	/* Bus address of the MDIO device (0-31) */
39 	int addr;
40 	int flags;
41 	struct gpio_desc *reset_gpio;
42 	struct reset_control *reset_ctrl;
43 	unsigned int reset_assert_delay;
44 	unsigned int reset_deassert_delay;
45 };
46 
to_mdio_device(const struct device * dev)47 static inline struct mdio_device *to_mdio_device(const struct device *dev)
48 {
49 	return container_of(dev, struct mdio_device, dev);
50 }
51 
52 /* struct mdio_driver_common: Common to all MDIO drivers */
53 struct mdio_driver_common {
54 	struct device_driver driver;
55 	int flags;
56 };
57 #define MDIO_DEVICE_FLAG_PHY		1
58 
59 static inline struct mdio_driver_common *
to_mdio_common_driver(const struct device_driver * driver)60 to_mdio_common_driver(const struct device_driver *driver)
61 {
62 	return container_of(driver, struct mdio_driver_common, driver);
63 }
64 
65 /* struct mdio_driver: Generic MDIO driver */
66 struct mdio_driver {
67 	struct mdio_driver_common mdiodrv;
68 
69 	/*
70 	 * Called during discovery.  Used to set
71 	 * up device-specific structures, if any
72 	 */
73 	int (*probe)(struct mdio_device *mdiodev);
74 
75 	/* Clears up any memory if needed */
76 	void (*remove)(struct mdio_device *mdiodev);
77 
78 	/* Quiesces the device on system shutdown, turns off interrupts etc */
79 	void (*shutdown)(struct mdio_device *mdiodev);
80 };
81 
82 static inline struct mdio_driver *
to_mdio_driver(const struct device_driver * driver)83 to_mdio_driver(const struct device_driver *driver)
84 {
85 	return container_of(to_mdio_common_driver(driver), struct mdio_driver,
86 			    mdiodrv);
87 }
88 
89 /* device driver data */
mdiodev_set_drvdata(struct mdio_device * mdio,void * data)90 static inline void mdiodev_set_drvdata(struct mdio_device *mdio, void *data)
91 {
92 	dev_set_drvdata(&mdio->dev, data);
93 }
94 
mdiodev_get_drvdata(struct mdio_device * mdio)95 static inline void *mdiodev_get_drvdata(struct mdio_device *mdio)
96 {
97 	return dev_get_drvdata(&mdio->dev);
98 }
99 
100 void mdio_device_free(struct mdio_device *mdiodev);
101 struct mdio_device *mdio_device_create(struct mii_bus *bus, int addr);
102 int mdio_device_register(struct mdio_device *mdiodev);
103 void mdio_device_remove(struct mdio_device *mdiodev);
104 void mdio_device_reset(struct mdio_device *mdiodev, int value);
105 int mdio_driver_register(struct mdio_driver *drv);
106 void mdio_driver_unregister(struct mdio_driver *drv);
107 int mdio_device_bus_match(struct device *dev, struct device_driver *drv);
108 
mdio_device_get(struct mdio_device * mdiodev)109 static inline void mdio_device_get(struct mdio_device *mdiodev)
110 {
111 	get_device(&mdiodev->dev);
112 }
113 
mdio_device_put(struct mdio_device * mdiodev)114 static inline void mdio_device_put(struct mdio_device *mdiodev)
115 {
116 	mdio_device_free(mdiodev);
117 }
118 
mdio_phy_id_is_c45(int phy_id)119 static inline bool mdio_phy_id_is_c45(int phy_id)
120 {
121 	return (phy_id & MDIO_PHY_ID_C45) && !(phy_id & ~MDIO_PHY_ID_C45_MASK);
122 }
123 
mdio_phy_id_prtad(int phy_id)124 static inline __u16 mdio_phy_id_prtad(int phy_id)
125 {
126 	return (phy_id & MDIO_PHY_ID_PRTAD) >> 5;
127 }
128 
mdio_phy_id_devad(int phy_id)129 static inline __u16 mdio_phy_id_devad(int phy_id)
130 {
131 	return phy_id & MDIO_PHY_ID_DEVAD;
132 }
133 
134 /**
135  * struct mdio_if_info - Ethernet controller MDIO interface
136  * @prtad: PRTAD of the PHY (%MDIO_PRTAD_NONE if not present/unknown)
137  * @mmds: Mask of MMDs expected to be present in the PHY.  This must be
138  *	non-zero unless @prtad = %MDIO_PRTAD_NONE.
139  * @mode_support: MDIO modes supported.  If %MDIO_SUPPORTS_C22 is set then
140  *	MII register access will be passed through with @devad =
141  *	%MDIO_DEVAD_NONE.  If %MDIO_EMULATE_C22 is set then access to
142  *	commonly used clause 22 registers will be translated into
143  *	clause 45 registers.
144  * @dev: Net device structure
145  * @mdio_read: Register read function; returns value or negative error code
146  * @mdio_write: Register write function; returns 0 or negative error code
147  */
148 struct mdio_if_info {
149 	int prtad;
150 	u32 mmds;
151 	unsigned mode_support;
152 
153 	struct net_device *dev;
154 	int (*mdio_read)(struct net_device *dev, int prtad, int devad,
155 			 u16 addr);
156 	int (*mdio_write)(struct net_device *dev, int prtad, int devad,
157 			  u16 addr, u16 val);
158 };
159 
160 #define MDIO_PRTAD_NONE			(-1)
161 #define MDIO_DEVAD_NONE			(-1)
162 #define MDIO_SUPPORTS_C22		1
163 #define MDIO_SUPPORTS_C45		2
164 #define MDIO_EMULATE_C22		4
165 
166 struct ethtool_cmd;
167 struct ethtool_pauseparam;
168 extern int mdio45_probe(struct mdio_if_info *mdio, int prtad);
169 extern int mdio_set_flag(const struct mdio_if_info *mdio,
170 			 int prtad, int devad, u16 addr, int mask,
171 			 bool sense);
172 extern int mdio45_links_ok(const struct mdio_if_info *mdio, u32 mmds);
173 extern int mdio45_nway_restart(const struct mdio_if_info *mdio);
174 extern void mdio45_ethtool_gset_npage(const struct mdio_if_info *mdio,
175 				      struct ethtool_cmd *ecmd,
176 				      u32 npage_adv, u32 npage_lpa);
177 extern void
178 mdio45_ethtool_ksettings_get_npage(const struct mdio_if_info *mdio,
179 				   struct ethtool_link_ksettings *cmd,
180 				   u32 npage_adv, u32 npage_lpa);
181 
182 /**
183  * mdio45_ethtool_gset - get settings for ETHTOOL_GSET
184  * @mdio: MDIO interface
185  * @ecmd: Ethtool request structure
186  *
187  * Since the CSRs for auto-negotiation using next pages are not fully
188  * standardised, this function does not attempt to decode them.  Use
189  * mdio45_ethtool_gset_npage() to specify advertisement bits from next
190  * pages.
191  */
mdio45_ethtool_gset(const struct mdio_if_info * mdio,struct ethtool_cmd * ecmd)192 static inline void mdio45_ethtool_gset(const struct mdio_if_info *mdio,
193 				       struct ethtool_cmd *ecmd)
194 {
195 	mdio45_ethtool_gset_npage(mdio, ecmd, 0, 0);
196 }
197 
198 /**
199  * mdio45_ethtool_ksettings_get - get settings for ETHTOOL_GLINKSETTINGS
200  * @mdio: MDIO interface
201  * @cmd: Ethtool request structure
202  *
203  * Since the CSRs for auto-negotiation using next pages are not fully
204  * standardised, this function does not attempt to decode them.  Use
205  * mdio45_ethtool_ksettings_get_npage() to specify advertisement bits
206  * from next pages.
207  */
208 static inline void
mdio45_ethtool_ksettings_get(const struct mdio_if_info * mdio,struct ethtool_link_ksettings * cmd)209 mdio45_ethtool_ksettings_get(const struct mdio_if_info *mdio,
210 			     struct ethtool_link_ksettings *cmd)
211 {
212 	mdio45_ethtool_ksettings_get_npage(mdio, cmd, 0, 0);
213 }
214 
215 extern int mdio_mii_ioctl(const struct mdio_if_info *mdio,
216 			  struct mii_ioctl_data *mii_data, int cmd);
217 
218 /**
219  * mmd_eee_cap_to_ethtool_sup_t
220  * @eee_cap: value of the MMD EEE Capability register
221  *
222  * A small helper function that translates MMD EEE Capability (3.20) bits
223  * to ethtool supported settings.
224  */
mmd_eee_cap_to_ethtool_sup_t(u16 eee_cap)225 static inline u32 mmd_eee_cap_to_ethtool_sup_t(u16 eee_cap)
226 {
227 	u32 supported = 0;
228 
229 	if (eee_cap & MDIO_EEE_100TX)
230 		supported |= SUPPORTED_100baseT_Full;
231 	if (eee_cap & MDIO_EEE_1000T)
232 		supported |= SUPPORTED_1000baseT_Full;
233 	if (eee_cap & MDIO_EEE_10GT)
234 		supported |= SUPPORTED_10000baseT_Full;
235 	if (eee_cap & MDIO_EEE_1000KX)
236 		supported |= SUPPORTED_1000baseKX_Full;
237 	if (eee_cap & MDIO_EEE_10GKX4)
238 		supported |= SUPPORTED_10000baseKX4_Full;
239 	if (eee_cap & MDIO_EEE_10GKR)
240 		supported |= SUPPORTED_10000baseKR_Full;
241 
242 	return supported;
243 }
244 
245 /**
246  * mmd_eee_adv_to_ethtool_adv_t
247  * @eee_adv: value of the MMD EEE Advertisement/Link Partner Ability registers
248  *
249  * A small helper function that translates the MMD EEE Advertisment (7.60)
250  * and MMD EEE Link Partner Ability (7.61) bits to ethtool advertisement
251  * settings.
252  */
mmd_eee_adv_to_ethtool_adv_t(u16 eee_adv)253 static inline u32 mmd_eee_adv_to_ethtool_adv_t(u16 eee_adv)
254 {
255 	u32 adv = 0;
256 
257 	if (eee_adv & MDIO_EEE_100TX)
258 		adv |= ADVERTISED_100baseT_Full;
259 	if (eee_adv & MDIO_EEE_1000T)
260 		adv |= ADVERTISED_1000baseT_Full;
261 	if (eee_adv & MDIO_EEE_10GT)
262 		adv |= ADVERTISED_10000baseT_Full;
263 	if (eee_adv & MDIO_EEE_1000KX)
264 		adv |= ADVERTISED_1000baseKX_Full;
265 	if (eee_adv & MDIO_EEE_10GKX4)
266 		adv |= ADVERTISED_10000baseKX4_Full;
267 	if (eee_adv & MDIO_EEE_10GKR)
268 		adv |= ADVERTISED_10000baseKR_Full;
269 
270 	return adv;
271 }
272 
273 /**
274  * ethtool_adv_to_mmd_eee_adv_t
275  * @adv: the ethtool advertisement settings
276  *
277  * A small helper function that translates ethtool advertisement settings
278  * to EEE advertisements for the MMD EEE Advertisement (7.60) and
279  * MMD EEE Link Partner Ability (7.61) registers.
280  */
ethtool_adv_to_mmd_eee_adv_t(u32 adv)281 static inline u16 ethtool_adv_to_mmd_eee_adv_t(u32 adv)
282 {
283 	u16 reg = 0;
284 
285 	if (adv & ADVERTISED_100baseT_Full)
286 		reg |= MDIO_EEE_100TX;
287 	if (adv & ADVERTISED_1000baseT_Full)
288 		reg |= MDIO_EEE_1000T;
289 	if (adv & ADVERTISED_10000baseT_Full)
290 		reg |= MDIO_EEE_10GT;
291 	if (adv & ADVERTISED_1000baseKX_Full)
292 		reg |= MDIO_EEE_1000KX;
293 	if (adv & ADVERTISED_10000baseKX4_Full)
294 		reg |= MDIO_EEE_10GKX4;
295 	if (adv & ADVERTISED_10000baseKR_Full)
296 		reg |= MDIO_EEE_10GKR;
297 
298 	return reg;
299 }
300 
301 /**
302  * linkmode_adv_to_mii_10gbt_adv_t
303  * @advertising: the linkmode advertisement settings
304  *
305  * A small helper function that translates linkmode advertisement
306  * settings to phy autonegotiation advertisements for the C45
307  * 10GBASE-T AN CONTROL (7.32) register.
308  */
linkmode_adv_to_mii_10gbt_adv_t(unsigned long * advertising)309 static inline u32 linkmode_adv_to_mii_10gbt_adv_t(unsigned long *advertising)
310 {
311 	u32 result = 0;
312 
313 	if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
314 			      advertising))
315 		result |= MDIO_AN_10GBT_CTRL_ADV2_5G;
316 	if (linkmode_test_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
317 			      advertising))
318 		result |= MDIO_AN_10GBT_CTRL_ADV5G;
319 	if (linkmode_test_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
320 			      advertising))
321 		result |= MDIO_AN_10GBT_CTRL_ADV10G;
322 
323 	return result;
324 }
325 
326 /**
327  * mii_10gbt_stat_mod_linkmode_lpa_t
328  * @advertising: target the linkmode advertisement settings
329  * @lpa: value of the C45 10GBASE-T AN STATUS register
330  *
331  * A small helper function that translates C45 10GBASE-T AN STATUS register bits
332  * to linkmode advertisement settings. Other bits in advertising aren't changed.
333  */
mii_10gbt_stat_mod_linkmode_lpa_t(unsigned long * advertising,u32 lpa)334 static inline void mii_10gbt_stat_mod_linkmode_lpa_t(unsigned long *advertising,
335 						     u32 lpa)
336 {
337 	linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
338 			 advertising, lpa & MDIO_AN_10GBT_STAT_LP2_5G);
339 	linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
340 			 advertising, lpa & MDIO_AN_10GBT_STAT_LP5G);
341 	linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
342 			 advertising, lpa & MDIO_AN_10GBT_STAT_LP10G);
343 }
344 
345 /**
346  * mii_t1_adv_l_mod_linkmode_t
347  * @advertising: target the linkmode advertisement settings
348  * @lpa: value of the BASE-T1 Autonegotiation Advertisement [15:0] Register
349  *
350  * A small helper function that translates BASE-T1 Autonegotiation
351  * Advertisement [15:0] Register bits to linkmode advertisement settings.
352  * Other bits in advertising aren't changed.
353  */
mii_t1_adv_l_mod_linkmode_t(unsigned long * advertising,u32 lpa)354 static inline void mii_t1_adv_l_mod_linkmode_t(unsigned long *advertising, u32 lpa)
355 {
356 	linkmode_mod_bit(ETHTOOL_LINK_MODE_Pause_BIT, advertising,
357 			 lpa & MDIO_AN_T1_ADV_L_PAUSE_CAP);
358 	linkmode_mod_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, advertising,
359 			 lpa & MDIO_AN_T1_ADV_L_PAUSE_ASYM);
360 }
361 
362 /**
363  * mii_t1_adv_m_mod_linkmode_t
364  * @advertising: target the linkmode advertisement settings
365  * @lpa: value of the BASE-T1 Autonegotiation Advertisement [31:16] Register
366  *
367  * A small helper function that translates BASE-T1 Autonegotiation
368  * Advertisement [31:16] Register bits to linkmode advertisement settings.
369  * Other bits in advertising aren't changed.
370  */
mii_t1_adv_m_mod_linkmode_t(unsigned long * advertising,u32 lpa)371 static inline void mii_t1_adv_m_mod_linkmode_t(unsigned long *advertising, u32 lpa)
372 {
373 	linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT1L_Full_BIT,
374 			 advertising, lpa & MDIO_AN_T1_ADV_M_B10L);
375 }
376 
377 /**
378  * linkmode_adv_to_mii_t1_adv_l_t
379  * @advertising: the linkmode advertisement settings
380  *
381  * A small helper function that translates linkmode advertisement
382  * settings to phy autonegotiation advertisements for the
383  * BASE-T1 Autonegotiation Advertisement [15:0] Register.
384  */
linkmode_adv_to_mii_t1_adv_l_t(unsigned long * advertising)385 static inline u32 linkmode_adv_to_mii_t1_adv_l_t(unsigned long *advertising)
386 {
387 	u32 result = 0;
388 
389 	if (linkmode_test_bit(ETHTOOL_LINK_MODE_Pause_BIT, advertising))
390 		result |= MDIO_AN_T1_ADV_L_PAUSE_CAP;
391 	if (linkmode_test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, advertising))
392 		result |= MDIO_AN_T1_ADV_L_PAUSE_ASYM;
393 
394 	return result;
395 }
396 
397 /**
398  * linkmode_adv_to_mii_t1_adv_m_t
399  * @advertising: the linkmode advertisement settings
400  *
401  * A small helper function that translates linkmode advertisement
402  * settings to phy autonegotiation advertisements for the
403  * BASE-T1 Autonegotiation Advertisement [31:16] Register.
404  */
linkmode_adv_to_mii_t1_adv_m_t(unsigned long * advertising)405 static inline u32 linkmode_adv_to_mii_t1_adv_m_t(unsigned long *advertising)
406 {
407 	u32 result = 0;
408 
409 	if (linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT1L_Full_BIT, advertising))
410 		result |= MDIO_AN_T1_ADV_M_B10L;
411 
412 	return result;
413 }
414 
415 /**
416  * mii_eee_cap1_mod_linkmode_t()
417  * @adv: target the linkmode advertisement settings
418  * @val: register value
419  *
420  * A function that translates value of following registers to the linkmode:
421  * IEEE 802.3-2018 45.2.3.10 "EEE control and capability 1" register (3.20)
422  * IEEE 802.3-2018 45.2.7.13 "EEE advertisement 1" register (7.60)
423  * IEEE 802.3-2018 45.2.7.14 "EEE "link partner ability 1 register (7.61)
424  */
mii_eee_cap1_mod_linkmode_t(unsigned long * adv,u32 val)425 static inline void mii_eee_cap1_mod_linkmode_t(unsigned long *adv, u32 val)
426 {
427 	linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT,
428 			 adv, val & MDIO_EEE_100TX);
429 	linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
430 			 adv, val & MDIO_EEE_1000T);
431 	linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
432 			 adv, val & MDIO_EEE_10GT);
433 	linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseKX_Full_BIT,
434 			 adv, val & MDIO_EEE_1000KX);
435 	linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT,
436 			 adv, val & MDIO_EEE_10GKX4);
437 	linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseKR_Full_BIT,
438 			 adv, val & MDIO_EEE_10GKR);
439 }
440 
441 /**
442  * linkmode_to_mii_eee_cap1_t()
443  * @adv: the linkmode advertisement settings
444  *
445  * A function that translates linkmode to value for IEEE 802.3-2018 45.2.7.13
446  * "EEE advertisement 1" register (7.60)
447  */
linkmode_to_mii_eee_cap1_t(unsigned long * adv)448 static inline u32 linkmode_to_mii_eee_cap1_t(unsigned long *adv)
449 {
450 	u32 result = 0;
451 
452 	if (linkmode_test_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, adv))
453 		result |= MDIO_EEE_100TX;
454 	if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, adv))
455 		result |= MDIO_EEE_1000T;
456 	if (linkmode_test_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT, adv))
457 		result |= MDIO_EEE_10GT;
458 	if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseKX_Full_BIT, adv))
459 		result |= MDIO_EEE_1000KX;
460 	if (linkmode_test_bit(ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT, adv))
461 		result |= MDIO_EEE_10GKX4;
462 	if (linkmode_test_bit(ETHTOOL_LINK_MODE_10000baseKR_Full_BIT, adv))
463 		result |= MDIO_EEE_10GKR;
464 
465 	return result;
466 }
467 
468 /**
469  * mii_10base_t1_adv_mod_linkmode_t()
470  * @adv: linkmode advertisement settings
471  * @val: register value
472  *
473  * A function that translates IEEE 802.3cg-2019 45.2.7.26 "10BASE-T1 AN status"
474  * register (7.527) value to the linkmode.
475  */
mii_10base_t1_adv_mod_linkmode_t(unsigned long * adv,u16 val)476 static inline void mii_10base_t1_adv_mod_linkmode_t(unsigned long *adv, u16 val)
477 {
478 	linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT1L_Full_BIT,
479 			 adv, val & MDIO_AN_10BT1_AN_CTRL_ADV_EEE_T1L);
480 }
481 
482 /**
483  * linkmode_adv_to_mii_10base_t1_t()
484  * @adv: linkmode advertisement settings
485  *
486  * A function that translates the linkmode to IEEE 802.3cg-2019 45.2.7.25
487  * "10BASE-T1 AN control" register (7.526) value.
488  */
linkmode_adv_to_mii_10base_t1_t(unsigned long * adv)489 static inline u32 linkmode_adv_to_mii_10base_t1_t(unsigned long *adv)
490 {
491 	u32 result = 0;
492 
493 	if (linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT1L_Full_BIT, adv))
494 		result |= MDIO_AN_10BT1_AN_CTRL_ADV_EEE_T1L;
495 
496 	return result;
497 }
498 
499 /**
500  * mii_c73_mod_linkmode - convert a Clause 73 advertisement to linkmodes
501  * @adv: linkmode advertisement setting
502  * @lpa: array of three u16s containing the advertisement
503  *
504  * Convert an IEEE 802.3 Clause 73 advertisement to ethtool link modes.
505  */
mii_c73_mod_linkmode(unsigned long * adv,u16 * lpa)506 static inline void mii_c73_mod_linkmode(unsigned long *adv, u16 *lpa)
507 {
508 	linkmode_mod_bit(ETHTOOL_LINK_MODE_Pause_BIT,
509 			 adv, lpa[0] & MDIO_AN_C73_0_PAUSE);
510 	linkmode_mod_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
511 			 adv, lpa[0] & MDIO_AN_C73_0_ASM_DIR);
512 	linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseKX_Full_BIT,
513 			 adv, lpa[1] & MDIO_AN_C73_1_1000BASE_KX);
514 	linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT,
515 			 adv, lpa[1] & MDIO_AN_C73_1_10GBASE_KX4);
516 	linkmode_mod_bit(ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT,
517 			 adv, lpa[1] & MDIO_AN_C73_1_40GBASE_KR4);
518 	linkmode_mod_bit(ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT,
519 			 adv, lpa[1] & MDIO_AN_C73_1_40GBASE_CR4);
520 	/* 100GBASE_CR10 and 100GBASE_KP4 not implemented */
521 	linkmode_mod_bit(ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT,
522 			 adv, lpa[1] & MDIO_AN_C73_1_100GBASE_KR4);
523 	linkmode_mod_bit(ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT,
524 			 adv, lpa[1] & MDIO_AN_C73_1_100GBASE_CR4);
525 	/* 25GBASE_R_S not implemented */
526 	/* The 25GBASE_R bit can be used for 25Gbase KR or CR modes */
527 	linkmode_mod_bit(ETHTOOL_LINK_MODE_25000baseKR_Full_BIT,
528 			 adv, lpa[1] & MDIO_AN_C73_1_25GBASE_R);
529 	linkmode_mod_bit(ETHTOOL_LINK_MODE_25000baseCR_Full_BIT,
530 			 adv, lpa[1] & MDIO_AN_C73_1_25GBASE_R);
531 	linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseKR_Full_BIT,
532 			 adv, lpa[1] & MDIO_AN_C73_1_10GBASE_KR);
533 	linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseX_Full_BIT,
534 			 adv, lpa[2] & MDIO_AN_C73_2_2500BASE_KX);
535 	/* 5GBASE_KR not implemented */
536 }
537 
538 int __mdiobus_read(struct mii_bus *bus, int addr, u32 regnum);
539 int __mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val);
540 int __mdiobus_modify(struct mii_bus *bus, int addr, u32 regnum, u16 mask,
541 		     u16 set);
542 int __mdiobus_modify_changed(struct mii_bus *bus, int addr, u32 regnum,
543 			     u16 mask, u16 set);
544 
545 int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum);
546 int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum);
547 int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val);
548 int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val);
549 int mdiobus_modify(struct mii_bus *bus, int addr, u32 regnum, u16 mask,
550 		   u16 set);
551 int mdiobus_modify_changed(struct mii_bus *bus, int addr, u32 regnum,
552 			   u16 mask, u16 set);
553 int __mdiobus_c45_read(struct mii_bus *bus, int addr, int devad, u32 regnum);
554 int mdiobus_c45_read(struct mii_bus *bus, int addr, int devad, u32 regnum);
555 int mdiobus_c45_read_nested(struct mii_bus *bus, int addr, int devad,
556 			     u32 regnum);
557 int __mdiobus_c45_write(struct mii_bus *bus, int addr,  int devad, u32 regnum,
558 			u16 val);
559 int mdiobus_c45_write(struct mii_bus *bus, int addr,  int devad, u32 regnum,
560 		      u16 val);
561 int mdiobus_c45_write_nested(struct mii_bus *bus, int addr,  int devad,
562 			     u32 regnum, u16 val);
563 int mdiobus_c45_modify(struct mii_bus *bus, int addr, int devad, u32 regnum,
564 		       u16 mask, u16 set);
565 
566 int mdiobus_c45_modify_changed(struct mii_bus *bus, int addr, int devad,
567 			       u32 regnum, u16 mask, u16 set);
568 
__mdiodev_read(struct mdio_device * mdiodev,u32 regnum)569 static inline int __mdiodev_read(struct mdio_device *mdiodev, u32 regnum)
570 {
571 	return __mdiobus_read(mdiodev->bus, mdiodev->addr, regnum);
572 }
573 
__mdiodev_write(struct mdio_device * mdiodev,u32 regnum,u16 val)574 static inline int __mdiodev_write(struct mdio_device *mdiodev, u32 regnum,
575 				  u16 val)
576 {
577 	return __mdiobus_write(mdiodev->bus, mdiodev->addr, regnum, val);
578 }
579 
__mdiodev_modify(struct mdio_device * mdiodev,u32 regnum,u16 mask,u16 set)580 static inline int __mdiodev_modify(struct mdio_device *mdiodev, u32 regnum,
581 				   u16 mask, u16 set)
582 {
583 	return __mdiobus_modify(mdiodev->bus, mdiodev->addr, regnum, mask, set);
584 }
585 
__mdiodev_modify_changed(struct mdio_device * mdiodev,u32 regnum,u16 mask,u16 set)586 static inline int __mdiodev_modify_changed(struct mdio_device *mdiodev,
587 					   u32 regnum, u16 mask, u16 set)
588 {
589 	return __mdiobus_modify_changed(mdiodev->bus, mdiodev->addr, regnum,
590 					mask, set);
591 }
592 
mdiodev_read(struct mdio_device * mdiodev,u32 regnum)593 static inline int mdiodev_read(struct mdio_device *mdiodev, u32 regnum)
594 {
595 	return mdiobus_read(mdiodev->bus, mdiodev->addr, regnum);
596 }
597 
mdiodev_write(struct mdio_device * mdiodev,u32 regnum,u16 val)598 static inline int mdiodev_write(struct mdio_device *mdiodev, u32 regnum,
599 				u16 val)
600 {
601 	return mdiobus_write(mdiodev->bus, mdiodev->addr, regnum, val);
602 }
603 
mdiodev_modify(struct mdio_device * mdiodev,u32 regnum,u16 mask,u16 set)604 static inline int mdiodev_modify(struct mdio_device *mdiodev, u32 regnum,
605 				 u16 mask, u16 set)
606 {
607 	return mdiobus_modify(mdiodev->bus, mdiodev->addr, regnum, mask, set);
608 }
609 
mdiodev_modify_changed(struct mdio_device * mdiodev,u32 regnum,u16 mask,u16 set)610 static inline int mdiodev_modify_changed(struct mdio_device *mdiodev,
611 					 u32 regnum, u16 mask, u16 set)
612 {
613 	return mdiobus_modify_changed(mdiodev->bus, mdiodev->addr, regnum,
614 				      mask, set);
615 }
616 
mdiodev_c45_modify(struct mdio_device * mdiodev,int devad,u32 regnum,u16 mask,u16 set)617 static inline int mdiodev_c45_modify(struct mdio_device *mdiodev, int devad,
618 				     u32 regnum, u16 mask, u16 set)
619 {
620 	return mdiobus_c45_modify(mdiodev->bus, mdiodev->addr, devad, regnum,
621 				  mask, set);
622 }
623 
mdiodev_c45_modify_changed(struct mdio_device * mdiodev,int devad,u32 regnum,u16 mask,u16 set)624 static inline int mdiodev_c45_modify_changed(struct mdio_device *mdiodev,
625 					     int devad, u32 regnum, u16 mask,
626 					     u16 set)
627 {
628 	return mdiobus_c45_modify_changed(mdiodev->bus, mdiodev->addr, devad,
629 					  regnum, mask, set);
630 }
631 
mdiodev_c45_read(struct mdio_device * mdiodev,int devad,u16 regnum)632 static inline int mdiodev_c45_read(struct mdio_device *mdiodev, int devad,
633 				   u16 regnum)
634 {
635 	return mdiobus_c45_read(mdiodev->bus, mdiodev->addr, devad, regnum);
636 }
637 
mdiodev_c45_write(struct mdio_device * mdiodev,u32 devad,u16 regnum,u16 val)638 static inline int mdiodev_c45_write(struct mdio_device *mdiodev, u32 devad,
639 				    u16 regnum, u16 val)
640 {
641 	return mdiobus_c45_write(mdiodev->bus, mdiodev->addr, devad, regnum,
642 				 val);
643 }
644 
645 int mdiobus_register_device(struct mdio_device *mdiodev);
646 int mdiobus_unregister_device(struct mdio_device *mdiodev);
647 bool mdiobus_is_registered_device(struct mii_bus *bus, int addr);
648 struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr);
649 
650 /**
651  * mdio_module_driver() - Helper macro for registering mdio drivers
652  * @_mdio_driver: driver to register
653  *
654  * Helper macro for MDIO drivers which do not do anything special in module
655  * init/exit. Each module may only use this macro once, and calling it
656  * replaces module_init() and module_exit().
657  */
658 #define mdio_module_driver(_mdio_driver)				\
659 static int __init mdio_module_init(void)				\
660 {									\
661 	return mdio_driver_register(&_mdio_driver);			\
662 }									\
663 module_init(mdio_module_init);						\
664 static void __exit mdio_module_exit(void)				\
665 {									\
666 	mdio_driver_unregister(&_mdio_driver);				\
667 }									\
668 module_exit(mdio_module_exit)
669 
670 #endif /* __LINUX_MDIO_H__ */
671