2 * linux/mdio.h: definitions for MDIO (clause 45) transceivers
3 * Copyright 2006-2009 Solarflare Communications Inc.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation, incorporated herein by reference.
9 #ifndef __LINUX_MDIO_H__
10 #define __LINUX_MDIO_H__
12 #include <uapi/linux/mdio.h>
18 const struct dev_pm_ops *pm_ops;
20 int (*bus_match)(struct device *dev, struct device_driver *drv);
21 /* Bus address of the MDIO device (0-31) */
25 #define to_mdio_device(d) container_of(d, struct mdio_device, dev)
27 #define MDIO_DEVICE_FLAG_PHY 1
29 static inline bool mdio_phy_id_is_c45(int phy_id)
31 return (phy_id & MDIO_PHY_ID_C45) && !(phy_id & ~MDIO_PHY_ID_C45_MASK);
34 static inline __u16 mdio_phy_id_prtad(int phy_id)
36 return (phy_id & MDIO_PHY_ID_PRTAD) >> 5;
39 static inline __u16 mdio_phy_id_devad(int phy_id)
41 return phy_id & MDIO_PHY_ID_DEVAD;
45 * struct mdio_if_info - Ethernet controller MDIO interface
46 * @prtad: PRTAD of the PHY (%MDIO_PRTAD_NONE if not present/unknown)
47 * @mmds: Mask of MMDs expected to be present in the PHY. This must be
48 * non-zero unless @prtad = %MDIO_PRTAD_NONE.
49 * @mode_support: MDIO modes supported. If %MDIO_SUPPORTS_C22 is set then
50 * MII register access will be passed through with @devad =
51 * %MDIO_DEVAD_NONE. If %MDIO_EMULATE_C22 is set then access to
52 * commonly used clause 22 registers will be translated into
53 * clause 45 registers.
54 * @dev: Net device structure
55 * @mdio_read: Register read function; returns value or negative error code
56 * @mdio_write: Register write function; returns 0 or negative error code
61 unsigned mode_support;
63 struct net_device *dev;
64 int (*mdio_read)(struct net_device *dev, int prtad, int devad,
66 int (*mdio_write)(struct net_device *dev, int prtad, int devad,
70 #define MDIO_PRTAD_NONE (-1)
71 #define MDIO_DEVAD_NONE (-1)
72 #define MDIO_SUPPORTS_C22 1
73 #define MDIO_SUPPORTS_C45 2
74 #define MDIO_EMULATE_C22 4
77 struct ethtool_pauseparam;
78 extern int mdio45_probe(struct mdio_if_info *mdio, int prtad);
79 extern int mdio_set_flag(const struct mdio_if_info *mdio,
80 int prtad, int devad, u16 addr, int mask,
82 extern int mdio45_links_ok(const struct mdio_if_info *mdio, u32 mmds);
83 extern int mdio45_nway_restart(const struct mdio_if_info *mdio);
84 extern void mdio45_ethtool_gset_npage(const struct mdio_if_info *mdio,
85 struct ethtool_cmd *ecmd,
86 u32 npage_adv, u32 npage_lpa);
89 * mdio45_ethtool_gset - get settings for ETHTOOL_GSET
90 * @mdio: MDIO interface
91 * @ecmd: Ethtool request structure
93 * Since the CSRs for auto-negotiation using next pages are not fully
94 * standardised, this function does not attempt to decode them. Use
95 * mdio45_ethtool_gset_npage() to specify advertisement bits from next
98 static inline void mdio45_ethtool_gset(const struct mdio_if_info *mdio,
99 struct ethtool_cmd *ecmd)
101 mdio45_ethtool_gset_npage(mdio, ecmd, 0, 0);
104 extern int mdio_mii_ioctl(const struct mdio_if_info *mdio,
105 struct mii_ioctl_data *mii_data, int cmd);
108 * mmd_eee_cap_to_ethtool_sup_t
109 * @eee_cap: value of the MMD EEE Capability register
111 * A small helper function that translates MMD EEE Capability (3.20) bits
112 * to ethtool supported settings.
114 static inline u32 mmd_eee_cap_to_ethtool_sup_t(u16 eee_cap)
118 if (eee_cap & MDIO_EEE_100TX)
119 supported |= SUPPORTED_100baseT_Full;
120 if (eee_cap & MDIO_EEE_1000T)
121 supported |= SUPPORTED_1000baseT_Full;
122 if (eee_cap & MDIO_EEE_10GT)
123 supported |= SUPPORTED_10000baseT_Full;
124 if (eee_cap & MDIO_EEE_1000KX)
125 supported |= SUPPORTED_1000baseKX_Full;
126 if (eee_cap & MDIO_EEE_10GKX4)
127 supported |= SUPPORTED_10000baseKX4_Full;
128 if (eee_cap & MDIO_EEE_10GKR)
129 supported |= SUPPORTED_10000baseKR_Full;
135 * mmd_eee_adv_to_ethtool_adv_t
136 * @eee_adv: value of the MMD EEE Advertisement/Link Partner Ability registers
138 * A small helper function that translates the MMD EEE Advertisment (7.60)
139 * and MMD EEE Link Partner Ability (7.61) bits to ethtool advertisement
142 static inline u32 mmd_eee_adv_to_ethtool_adv_t(u16 eee_adv)
146 if (eee_adv & MDIO_EEE_100TX)
147 adv |= ADVERTISED_100baseT_Full;
148 if (eee_adv & MDIO_EEE_1000T)
149 adv |= ADVERTISED_1000baseT_Full;
150 if (eee_adv & MDIO_EEE_10GT)
151 adv |= ADVERTISED_10000baseT_Full;
152 if (eee_adv & MDIO_EEE_1000KX)
153 adv |= ADVERTISED_1000baseKX_Full;
154 if (eee_adv & MDIO_EEE_10GKX4)
155 adv |= ADVERTISED_10000baseKX4_Full;
156 if (eee_adv & MDIO_EEE_10GKR)
157 adv |= ADVERTISED_10000baseKR_Full;
163 * ethtool_adv_to_mmd_eee_adv_t
164 * @adv: the ethtool advertisement settings
166 * A small helper function that translates ethtool advertisement settings
167 * to EEE advertisements for the MMD EEE Advertisement (7.60) and
168 * MMD EEE Link Partner Ability (7.61) registers.
170 static inline u16 ethtool_adv_to_mmd_eee_adv_t(u32 adv)
174 if (adv & ADVERTISED_100baseT_Full)
175 reg |= MDIO_EEE_100TX;
176 if (adv & ADVERTISED_1000baseT_Full)
177 reg |= MDIO_EEE_1000T;
178 if (adv & ADVERTISED_10000baseT_Full)
179 reg |= MDIO_EEE_10GT;
180 if (adv & ADVERTISED_1000baseKX_Full)
181 reg |= MDIO_EEE_1000KX;
182 if (adv & ADVERTISED_10000baseKX4_Full)
183 reg |= MDIO_EEE_10GKX4;
184 if (adv & ADVERTISED_10000baseKR_Full)
185 reg |= MDIO_EEE_10GKR;
190 int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum);
191 int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum);
192 int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val);
193 int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val);
195 int mdiobus_register_device(struct mdio_device *mdiodev);
196 int mdiobus_unregister_device(struct mdio_device *mdiodev);
197 bool mdiobus_is_registered_device(struct mii_bus *bus, int addr);
198 struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr);
200 #endif /* __LINUX_MDIO_H__ */