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>
20 /* Bus address of the MDIO device (0-31) */
23 #define to_mdio_device(d) container_of(d, struct mdio_device, dev)
25 static inline bool mdio_phy_id_is_c45(int phy_id)
27 return (phy_id & MDIO_PHY_ID_C45) && !(phy_id & ~MDIO_PHY_ID_C45_MASK);
30 static inline __u16 mdio_phy_id_prtad(int phy_id)
32 return (phy_id & MDIO_PHY_ID_PRTAD) >> 5;
35 static inline __u16 mdio_phy_id_devad(int phy_id)
37 return phy_id & MDIO_PHY_ID_DEVAD;
41 * struct mdio_if_info - Ethernet controller MDIO interface
42 * @prtad: PRTAD of the PHY (%MDIO_PRTAD_NONE if not present/unknown)
43 * @mmds: Mask of MMDs expected to be present in the PHY. This must be
44 * non-zero unless @prtad = %MDIO_PRTAD_NONE.
45 * @mode_support: MDIO modes supported. If %MDIO_SUPPORTS_C22 is set then
46 * MII register access will be passed through with @devad =
47 * %MDIO_DEVAD_NONE. If %MDIO_EMULATE_C22 is set then access to
48 * commonly used clause 22 registers will be translated into
49 * clause 45 registers.
50 * @dev: Net device structure
51 * @mdio_read: Register read function; returns value or negative error code
52 * @mdio_write: Register write function; returns 0 or negative error code
57 unsigned mode_support;
59 struct net_device *dev;
60 int (*mdio_read)(struct net_device *dev, int prtad, int devad,
62 int (*mdio_write)(struct net_device *dev, int prtad, int devad,
66 #define MDIO_PRTAD_NONE (-1)
67 #define MDIO_DEVAD_NONE (-1)
68 #define MDIO_SUPPORTS_C22 1
69 #define MDIO_SUPPORTS_C45 2
70 #define MDIO_EMULATE_C22 4
73 struct ethtool_pauseparam;
74 extern int mdio45_probe(struct mdio_if_info *mdio, int prtad);
75 extern int mdio_set_flag(const struct mdio_if_info *mdio,
76 int prtad, int devad, u16 addr, int mask,
78 extern int mdio45_links_ok(const struct mdio_if_info *mdio, u32 mmds);
79 extern int mdio45_nway_restart(const struct mdio_if_info *mdio);
80 extern void mdio45_ethtool_gset_npage(const struct mdio_if_info *mdio,
81 struct ethtool_cmd *ecmd,
82 u32 npage_adv, u32 npage_lpa);
85 * mdio45_ethtool_gset - get settings for ETHTOOL_GSET
86 * @mdio: MDIO interface
87 * @ecmd: Ethtool request structure
89 * Since the CSRs for auto-negotiation using next pages are not fully
90 * standardised, this function does not attempt to decode them. Use
91 * mdio45_ethtool_gset_npage() to specify advertisement bits from next
94 static inline void mdio45_ethtool_gset(const struct mdio_if_info *mdio,
95 struct ethtool_cmd *ecmd)
97 mdio45_ethtool_gset_npage(mdio, ecmd, 0, 0);
100 extern int mdio_mii_ioctl(const struct mdio_if_info *mdio,
101 struct mii_ioctl_data *mii_data, int cmd);
104 * mmd_eee_cap_to_ethtool_sup_t
105 * @eee_cap: value of the MMD EEE Capability register
107 * A small helper function that translates MMD EEE Capability (3.20) bits
108 * to ethtool supported settings.
110 static inline u32 mmd_eee_cap_to_ethtool_sup_t(u16 eee_cap)
114 if (eee_cap & MDIO_EEE_100TX)
115 supported |= SUPPORTED_100baseT_Full;
116 if (eee_cap & MDIO_EEE_1000T)
117 supported |= SUPPORTED_1000baseT_Full;
118 if (eee_cap & MDIO_EEE_10GT)
119 supported |= SUPPORTED_10000baseT_Full;
120 if (eee_cap & MDIO_EEE_1000KX)
121 supported |= SUPPORTED_1000baseKX_Full;
122 if (eee_cap & MDIO_EEE_10GKX4)
123 supported |= SUPPORTED_10000baseKX4_Full;
124 if (eee_cap & MDIO_EEE_10GKR)
125 supported |= SUPPORTED_10000baseKR_Full;
131 * mmd_eee_adv_to_ethtool_adv_t
132 * @eee_adv: value of the MMD EEE Advertisement/Link Partner Ability registers
134 * A small helper function that translates the MMD EEE Advertisment (7.60)
135 * and MMD EEE Link Partner Ability (7.61) bits to ethtool advertisement
138 static inline u32 mmd_eee_adv_to_ethtool_adv_t(u16 eee_adv)
142 if (eee_adv & MDIO_EEE_100TX)
143 adv |= ADVERTISED_100baseT_Full;
144 if (eee_adv & MDIO_EEE_1000T)
145 adv |= ADVERTISED_1000baseT_Full;
146 if (eee_adv & MDIO_EEE_10GT)
147 adv |= ADVERTISED_10000baseT_Full;
148 if (eee_adv & MDIO_EEE_1000KX)
149 adv |= ADVERTISED_1000baseKX_Full;
150 if (eee_adv & MDIO_EEE_10GKX4)
151 adv |= ADVERTISED_10000baseKX4_Full;
152 if (eee_adv & MDIO_EEE_10GKR)
153 adv |= ADVERTISED_10000baseKR_Full;
159 * ethtool_adv_to_mmd_eee_adv_t
160 * @adv: the ethtool advertisement settings
162 * A small helper function that translates ethtool advertisement settings
163 * to EEE advertisements for the MMD EEE Advertisement (7.60) and
164 * MMD EEE Link Partner Ability (7.61) registers.
166 static inline u16 ethtool_adv_to_mmd_eee_adv_t(u32 adv)
170 if (adv & ADVERTISED_100baseT_Full)
171 reg |= MDIO_EEE_100TX;
172 if (adv & ADVERTISED_1000baseT_Full)
173 reg |= MDIO_EEE_1000T;
174 if (adv & ADVERTISED_10000baseT_Full)
175 reg |= MDIO_EEE_10GT;
176 if (adv & ADVERTISED_1000baseKX_Full)
177 reg |= MDIO_EEE_1000KX;
178 if (adv & ADVERTISED_10000baseKX4_Full)
179 reg |= MDIO_EEE_10GKX4;
180 if (adv & ADVERTISED_10000baseKR_Full)
181 reg |= MDIO_EEE_10GKR;
186 int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum);
187 int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum);
188 int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val);
189 int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val);
191 #endif /* __LINUX_MDIO_H__ */