mm: Don't pin ZERO_PAGE in pin_user_pages()
[linux-block.git] / include / linux / mdio.h
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
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 *
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 *
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 */
90 static inline void mdiodev_set_drvdata(struct mdio_device *mdio, void *data)
91 {
92         dev_set_drvdata(&mdio->dev, data);
93 }
94
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
109 static inline bool mdio_phy_id_is_c45(int phy_id)
110 {
111         return (phy_id & MDIO_PHY_ID_C45) && !(phy_id & ~MDIO_PHY_ID_C45_MASK);
112 }
113
114 static inline __u16 mdio_phy_id_prtad(int phy_id)
115 {
116         return (phy_id & MDIO_PHY_ID_PRTAD) >> 5;
117 }
118
119 static inline __u16 mdio_phy_id_devad(int phy_id)
120 {
121         return phy_id & MDIO_PHY_ID_DEVAD;
122 }
123
124 /**
125  * struct mdio_if_info - Ethernet controller MDIO interface
126  * @prtad: PRTAD of the PHY (%MDIO_PRTAD_NONE if not present/unknown)
127  * @mmds: Mask of MMDs expected to be present in the PHY.  This must be
128  *      non-zero unless @prtad = %MDIO_PRTAD_NONE.
129  * @mode_support: MDIO modes supported.  If %MDIO_SUPPORTS_C22 is set then
130  *      MII register access will be passed through with @devad =
131  *      %MDIO_DEVAD_NONE.  If %MDIO_EMULATE_C22 is set then access to
132  *      commonly used clause 22 registers will be translated into
133  *      clause 45 registers.
134  * @dev: Net device structure
135  * @mdio_read: Register read function; returns value or negative error code
136  * @mdio_write: Register write function; returns 0 or negative error code
137  */
138 struct mdio_if_info {
139         int prtad;
140         u32 mmds;
141         unsigned mode_support;
142
143         struct net_device *dev;
144         int (*mdio_read)(struct net_device *dev, int prtad, int devad,
145                          u16 addr);
146         int (*mdio_write)(struct net_device *dev, int prtad, int devad,
147                           u16 addr, u16 val);
148 };
149
150 #define MDIO_PRTAD_NONE                 (-1)
151 #define MDIO_DEVAD_NONE                 (-1)
152 #define MDIO_SUPPORTS_C22               1
153 #define MDIO_SUPPORTS_C45               2
154 #define MDIO_EMULATE_C22                4
155
156 struct ethtool_cmd;
157 struct ethtool_pauseparam;
158 extern int mdio45_probe(struct mdio_if_info *mdio, int prtad);
159 extern int mdio_set_flag(const struct mdio_if_info *mdio,
160                          int prtad, int devad, u16 addr, int mask,
161                          bool sense);
162 extern int mdio45_links_ok(const struct mdio_if_info *mdio, u32 mmds);
163 extern int mdio45_nway_restart(const struct mdio_if_info *mdio);
164 extern void mdio45_ethtool_gset_npage(const struct mdio_if_info *mdio,
165                                       struct ethtool_cmd *ecmd,
166                                       u32 npage_adv, u32 npage_lpa);
167 extern void
168 mdio45_ethtool_ksettings_get_npage(const struct mdio_if_info *mdio,
169                                    struct ethtool_link_ksettings *cmd,
170                                    u32 npage_adv, u32 npage_lpa);
171
172 /**
173  * mdio45_ethtool_gset - get settings for ETHTOOL_GSET
174  * @mdio: MDIO interface
175  * @ecmd: Ethtool request structure
176  *
177  * Since the CSRs for auto-negotiation using next pages are not fully
178  * standardised, this function does not attempt to decode them.  Use
179  * mdio45_ethtool_gset_npage() to specify advertisement bits from next
180  * pages.
181  */
182 static inline void mdio45_ethtool_gset(const struct mdio_if_info *mdio,
183                                        struct ethtool_cmd *ecmd)
184 {
185         mdio45_ethtool_gset_npage(mdio, ecmd, 0, 0);
186 }
187
188 /**
189  * mdio45_ethtool_ksettings_get - get settings for ETHTOOL_GLINKSETTINGS
190  * @mdio: MDIO interface
191  * @cmd: Ethtool request structure
192  *
193  * Since the CSRs for auto-negotiation using next pages are not fully
194  * standardised, this function does not attempt to decode them.  Use
195  * mdio45_ethtool_ksettings_get_npage() to specify advertisement bits
196  * from next pages.
197  */
198 static inline void
199 mdio45_ethtool_ksettings_get(const struct mdio_if_info *mdio,
200                              struct ethtool_link_ksettings *cmd)
201 {
202         mdio45_ethtool_ksettings_get_npage(mdio, cmd, 0, 0);
203 }
204
205 extern int mdio_mii_ioctl(const struct mdio_if_info *mdio,
206                           struct mii_ioctl_data *mii_data, int cmd);
207
208 /**
209  * mmd_eee_cap_to_ethtool_sup_t
210  * @eee_cap: value of the MMD EEE Capability register
211  *
212  * A small helper function that translates MMD EEE Capability (3.20) bits
213  * to ethtool supported settings.
214  */
215 static inline u32 mmd_eee_cap_to_ethtool_sup_t(u16 eee_cap)
216 {
217         u32 supported = 0;
218
219         if (eee_cap & MDIO_EEE_100TX)
220                 supported |= SUPPORTED_100baseT_Full;
221         if (eee_cap & MDIO_EEE_1000T)
222                 supported |= SUPPORTED_1000baseT_Full;
223         if (eee_cap & MDIO_EEE_10GT)
224                 supported |= SUPPORTED_10000baseT_Full;
225         if (eee_cap & MDIO_EEE_1000KX)
226                 supported |= SUPPORTED_1000baseKX_Full;
227         if (eee_cap & MDIO_EEE_10GKX4)
228                 supported |= SUPPORTED_10000baseKX4_Full;
229         if (eee_cap & MDIO_EEE_10GKR)
230                 supported |= SUPPORTED_10000baseKR_Full;
231
232         return supported;
233 }
234
235 /**
236  * mmd_eee_adv_to_ethtool_adv_t
237  * @eee_adv: value of the MMD EEE Advertisement/Link Partner Ability registers
238  *
239  * A small helper function that translates the MMD EEE Advertisment (7.60)
240  * and MMD EEE Link Partner Ability (7.61) bits to ethtool advertisement
241  * settings.
242  */
243 static inline u32 mmd_eee_adv_to_ethtool_adv_t(u16 eee_adv)
244 {
245         u32 adv = 0;
246
247         if (eee_adv & MDIO_EEE_100TX)
248                 adv |= ADVERTISED_100baseT_Full;
249         if (eee_adv & MDIO_EEE_1000T)
250                 adv |= ADVERTISED_1000baseT_Full;
251         if (eee_adv & MDIO_EEE_10GT)
252                 adv |= ADVERTISED_10000baseT_Full;
253         if (eee_adv & MDIO_EEE_1000KX)
254                 adv |= ADVERTISED_1000baseKX_Full;
255         if (eee_adv & MDIO_EEE_10GKX4)
256                 adv |= ADVERTISED_10000baseKX4_Full;
257         if (eee_adv & MDIO_EEE_10GKR)
258                 adv |= ADVERTISED_10000baseKR_Full;
259
260         return adv;
261 }
262
263 /**
264  * ethtool_adv_to_mmd_eee_adv_t
265  * @adv: the ethtool advertisement settings
266  *
267  * A small helper function that translates ethtool advertisement settings
268  * to EEE advertisements for the MMD EEE Advertisement (7.60) and
269  * MMD EEE Link Partner Ability (7.61) registers.
270  */
271 static inline u16 ethtool_adv_to_mmd_eee_adv_t(u32 adv)
272 {
273         u16 reg = 0;
274
275         if (adv & ADVERTISED_100baseT_Full)
276                 reg |= MDIO_EEE_100TX;
277         if (adv & ADVERTISED_1000baseT_Full)
278                 reg |= MDIO_EEE_1000T;
279         if (adv & ADVERTISED_10000baseT_Full)
280                 reg |= MDIO_EEE_10GT;
281         if (adv & ADVERTISED_1000baseKX_Full)
282                 reg |= MDIO_EEE_1000KX;
283         if (adv & ADVERTISED_10000baseKX4_Full)
284                 reg |= MDIO_EEE_10GKX4;
285         if (adv & ADVERTISED_10000baseKR_Full)
286                 reg |= MDIO_EEE_10GKR;
287
288         return reg;
289 }
290
291 /**
292  * linkmode_adv_to_mii_10gbt_adv_t
293  * @advertising: the linkmode advertisement settings
294  *
295  * A small helper function that translates linkmode advertisement
296  * settings to phy autonegotiation advertisements for the C45
297  * 10GBASE-T AN CONTROL (7.32) register.
298  */
299 static inline u32 linkmode_adv_to_mii_10gbt_adv_t(unsigned long *advertising)
300 {
301         u32 result = 0;
302
303         if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
304                               advertising))
305                 result |= MDIO_AN_10GBT_CTRL_ADV2_5G;
306         if (linkmode_test_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
307                               advertising))
308                 result |= MDIO_AN_10GBT_CTRL_ADV5G;
309         if (linkmode_test_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
310                               advertising))
311                 result |= MDIO_AN_10GBT_CTRL_ADV10G;
312
313         return result;
314 }
315
316 /**
317  * mii_10gbt_stat_mod_linkmode_lpa_t
318  * @advertising: target the linkmode advertisement settings
319  * @lpa: value of the C45 10GBASE-T AN STATUS register
320  *
321  * A small helper function that translates C45 10GBASE-T AN STATUS register bits
322  * to linkmode advertisement settings. Other bits in advertising aren't changed.
323  */
324 static inline void mii_10gbt_stat_mod_linkmode_lpa_t(unsigned long *advertising,
325                                                      u32 lpa)
326 {
327         linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
328                          advertising, lpa & MDIO_AN_10GBT_STAT_LP2_5G);
329         linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
330                          advertising, lpa & MDIO_AN_10GBT_STAT_LP5G);
331         linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
332                          advertising, lpa & MDIO_AN_10GBT_STAT_LP10G);
333 }
334
335 /**
336  * mii_t1_adv_l_mod_linkmode_t
337  * @advertising: target the linkmode advertisement settings
338  * @lpa: value of the BASE-T1 Autonegotiation Advertisement [15:0] Register
339  *
340  * A small helper function that translates BASE-T1 Autonegotiation
341  * Advertisement [15:0] Register bits to linkmode advertisement settings.
342  * Other bits in advertising aren't changed.
343  */
344 static inline void mii_t1_adv_l_mod_linkmode_t(unsigned long *advertising, u32 lpa)
345 {
346         linkmode_mod_bit(ETHTOOL_LINK_MODE_Pause_BIT, advertising,
347                          lpa & MDIO_AN_T1_ADV_L_PAUSE_CAP);
348         linkmode_mod_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, advertising,
349                          lpa & MDIO_AN_T1_ADV_L_PAUSE_ASYM);
350 }
351
352 /**
353  * mii_t1_adv_m_mod_linkmode_t
354  * @advertising: target the linkmode advertisement settings
355  * @lpa: value of the BASE-T1 Autonegotiation Advertisement [31:16] Register
356  *
357  * A small helper function that translates BASE-T1 Autonegotiation
358  * Advertisement [31:16] Register bits to linkmode advertisement settings.
359  * Other bits in advertising aren't changed.
360  */
361 static inline void mii_t1_adv_m_mod_linkmode_t(unsigned long *advertising, u32 lpa)
362 {
363         linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT1L_Full_BIT,
364                          advertising, lpa & MDIO_AN_T1_ADV_M_B10L);
365 }
366
367 /**
368  * linkmode_adv_to_mii_t1_adv_l_t
369  * @advertising: the linkmode advertisement settings
370  *
371  * A small helper function that translates linkmode advertisement
372  * settings to phy autonegotiation advertisements for the
373  * BASE-T1 Autonegotiation Advertisement [15:0] Register.
374  */
375 static inline u32 linkmode_adv_to_mii_t1_adv_l_t(unsigned long *advertising)
376 {
377         u32 result = 0;
378
379         if (linkmode_test_bit(ETHTOOL_LINK_MODE_Pause_BIT, advertising))
380                 result |= MDIO_AN_T1_ADV_L_PAUSE_CAP;
381         if (linkmode_test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, advertising))
382                 result |= MDIO_AN_T1_ADV_L_PAUSE_ASYM;
383
384         return result;
385 }
386
387 /**
388  * linkmode_adv_to_mii_t1_adv_m_t
389  * @advertising: the linkmode advertisement settings
390  *
391  * A small helper function that translates linkmode advertisement
392  * settings to phy autonegotiation advertisements for the
393  * BASE-T1 Autonegotiation Advertisement [31:16] Register.
394  */
395 static inline u32 linkmode_adv_to_mii_t1_adv_m_t(unsigned long *advertising)
396 {
397         u32 result = 0;
398
399         if (linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT1L_Full_BIT, advertising))
400                 result |= MDIO_AN_T1_ADV_M_B10L;
401
402         return result;
403 }
404
405 /**
406  * mii_eee_cap1_mod_linkmode_t()
407  * @adv: target the linkmode advertisement settings
408  * @val: register value
409  *
410  * A function that translates value of following registers to the linkmode:
411  * IEEE 802.3-2018 45.2.3.10 "EEE control and capability 1" register (3.20)
412  * IEEE 802.3-2018 45.2.7.13 "EEE advertisement 1" register (7.60)
413  * IEEE 802.3-2018 45.2.7.14 "EEE "link partner ability 1 register (7.61)
414  */
415 static inline void mii_eee_cap1_mod_linkmode_t(unsigned long *adv, u32 val)
416 {
417         linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT,
418                          adv, val & MDIO_EEE_100TX);
419         linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
420                          adv, val & MDIO_EEE_1000T);
421         linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
422                          adv, val & MDIO_EEE_10GT);
423         linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseKX_Full_BIT,
424                          adv, val & MDIO_EEE_1000KX);
425         linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT,
426                          adv, val & MDIO_EEE_10GKX4);
427         linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseKR_Full_BIT,
428                          adv, val & MDIO_EEE_10GKR);
429 }
430
431 /**
432  * linkmode_to_mii_eee_cap1_t()
433  * @adv: the linkmode advertisement settings
434  *
435  * A function that translates linkmode to value for IEEE 802.3-2018 45.2.7.13
436  * "EEE advertisement 1" register (7.60)
437  */
438 static inline u32 linkmode_to_mii_eee_cap1_t(unsigned long *adv)
439 {
440         u32 result = 0;
441
442         if (linkmode_test_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, adv))
443                 result |= MDIO_EEE_100TX;
444         if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, adv))
445                 result |= MDIO_EEE_1000T;
446         if (linkmode_test_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT, adv))
447                 result |= MDIO_EEE_10GT;
448         if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseKX_Full_BIT, adv))
449                 result |= MDIO_EEE_1000KX;
450         if (linkmode_test_bit(ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT, adv))
451                 result |= MDIO_EEE_10GKX4;
452         if (linkmode_test_bit(ETHTOOL_LINK_MODE_10000baseKR_Full_BIT, adv))
453                 result |= MDIO_EEE_10GKR;
454
455         return result;
456 }
457
458 /**
459  * mii_10base_t1_adv_mod_linkmode_t()
460  * @adv: linkmode advertisement settings
461  * @val: register value
462  *
463  * A function that translates IEEE 802.3cg-2019 45.2.7.26 "10BASE-T1 AN status"
464  * register (7.527) value to the linkmode.
465  */
466 static inline void mii_10base_t1_adv_mod_linkmode_t(unsigned long *adv, u16 val)
467 {
468         linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT1L_Full_BIT,
469                          adv, val & MDIO_AN_10BT1_AN_CTRL_ADV_EEE_T1L);
470 }
471
472 /**
473  * linkmode_adv_to_mii_10base_t1_t()
474  * @adv: linkmode advertisement settings
475  *
476  * A function that translates the linkmode to IEEE 802.3cg-2019 45.2.7.25
477  * "10BASE-T1 AN control" register (7.526) value.
478  */
479 static inline u32 linkmode_adv_to_mii_10base_t1_t(unsigned long *adv)
480 {
481         u32 result = 0;
482
483         if (linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT1L_Full_BIT, adv))
484                 result |= MDIO_AN_10BT1_AN_CTRL_ADV_EEE_T1L;
485
486         return result;
487 }
488
489 int __mdiobus_read(struct mii_bus *bus, int addr, u32 regnum);
490 int __mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val);
491 int __mdiobus_modify_changed(struct mii_bus *bus, int addr, u32 regnum,
492                              u16 mask, u16 set);
493
494 int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum);
495 int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum);
496 int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val);
497 int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val);
498 int mdiobus_modify(struct mii_bus *bus, int addr, u32 regnum, u16 mask,
499                    u16 set);
500 int mdiobus_modify_changed(struct mii_bus *bus, int addr, u32 regnum,
501                            u16 mask, u16 set);
502 int __mdiobus_c45_read(struct mii_bus *bus, int addr, int devad, u32 regnum);
503 int mdiobus_c45_read(struct mii_bus *bus, int addr, int devad, u32 regnum);
504 int mdiobus_c45_read_nested(struct mii_bus *bus, int addr, int devad,
505                              u32 regnum);
506 int __mdiobus_c45_write(struct mii_bus *bus, int addr,  int devad, u32 regnum,
507                         u16 val);
508 int mdiobus_c45_write(struct mii_bus *bus, int addr,  int devad, u32 regnum,
509                       u16 val);
510 int mdiobus_c45_write_nested(struct mii_bus *bus, int addr,  int devad,
511                              u32 regnum, u16 val);
512 int mdiobus_c45_modify(struct mii_bus *bus, int addr, int devad, u32 regnum,
513                        u16 mask, u16 set);
514
515 int mdiobus_c45_modify_changed(struct mii_bus *bus, int addr, int devad,
516                                u32 regnum, u16 mask, u16 set);
517
518 static inline int mdiodev_read(struct mdio_device *mdiodev, u32 regnum)
519 {
520         return mdiobus_read(mdiodev->bus, mdiodev->addr, regnum);
521 }
522
523 static inline int mdiodev_write(struct mdio_device *mdiodev, u32 regnum,
524                                 u16 val)
525 {
526         return mdiobus_write(mdiodev->bus, mdiodev->addr, regnum, val);
527 }
528
529 static inline int mdiodev_modify(struct mdio_device *mdiodev, u32 regnum,
530                                  u16 mask, u16 set)
531 {
532         return mdiobus_modify(mdiodev->bus, mdiodev->addr, regnum, mask, set);
533 }
534
535 static inline int mdiodev_modify_changed(struct mdio_device *mdiodev,
536                                          u32 regnum, u16 mask, u16 set)
537 {
538         return mdiobus_modify_changed(mdiodev->bus, mdiodev->addr, regnum,
539                                       mask, set);
540 }
541
542 static inline int mdiodev_c45_modify(struct mdio_device *mdiodev, int devad,
543                                      u32 regnum, u16 mask, u16 set)
544 {
545         return mdiobus_c45_modify(mdiodev->bus, mdiodev->addr, devad, regnum,
546                                   mask, set);
547 }
548
549 static inline int mdiodev_c45_modify_changed(struct mdio_device *mdiodev,
550                                              int devad, u32 regnum, u16 mask,
551                                              u16 set)
552 {
553         return mdiobus_c45_modify_changed(mdiodev->bus, mdiodev->addr, devad,
554                                           regnum, mask, set);
555 }
556
557 static inline int mdiodev_c45_read(struct mdio_device *mdiodev, int devad,
558                                    u16 regnum)
559 {
560         return mdiobus_c45_read(mdiodev->bus, mdiodev->addr, devad, regnum);
561 }
562
563 static inline int mdiodev_c45_write(struct mdio_device *mdiodev, u32 devad,
564                                     u16 regnum, u16 val)
565 {
566         return mdiobus_c45_write(mdiodev->bus, mdiodev->addr, devad, regnum,
567                                  val);
568 }
569
570 int mdiobus_register_device(struct mdio_device *mdiodev);
571 int mdiobus_unregister_device(struct mdio_device *mdiodev);
572 bool mdiobus_is_registered_device(struct mii_bus *bus, int addr);
573 struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr);
574
575 /**
576  * mdio_module_driver() - Helper macro for registering mdio drivers
577  * @_mdio_driver: driver to register
578  *
579  * Helper macro for MDIO drivers which do not do anything special in module
580  * init/exit. Each module may only use this macro once, and calling it
581  * replaces module_init() and module_exit().
582  */
583 #define mdio_module_driver(_mdio_driver)                                \
584 static int __init mdio_module_init(void)                                \
585 {                                                                       \
586         return mdio_driver_register(&_mdio_driver);                     \
587 }                                                                       \
588 module_init(mdio_module_init);                                          \
589 static void __exit mdio_module_exit(void)                               \
590 {                                                                       \
591         mdio_driver_unregister(&_mdio_driver);                          \
592 }                                                                       \
593 module_exit(mdio_module_exit)
594
595 #endif /* __LINUX_MDIO_H__ */