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>
17 const struct dev_pm_ops *pm_ops;
20 int (*bus_match)(struct device *dev, struct device_driver *drv);
21 void (*device_free)(struct mdio_device *mdiodev);
22 void (*device_remove)(struct mdio_device *mdiodev);
24 /* Bus address of the MDIO device (0-31) */
28 #define to_mdio_device(d) container_of(d, struct mdio_device, dev)
30 /* struct mdio_driver_common: Common to all MDIO drivers */
31 struct mdio_driver_common {
32 struct device_driver driver;
35 #define MDIO_DEVICE_FLAG_PHY 1
36 #define to_mdio_common_driver(d) \
37 container_of(d, struct mdio_driver_common, driver)
39 /* struct mdio_driver: Generic MDIO driver */
41 struct mdio_driver_common mdiodrv;
44 * Called during discovery. Used to set
45 * up device-specific structures, if any
47 int (*probe)(struct mdio_device *mdiodev);
49 /* Clears up any memory if needed */
50 void (*remove)(struct mdio_device *mdiodev);
52 #define to_mdio_driver(d) \
53 container_of(to_mdio_common_driver(d), struct mdio_driver, mdiodrv)
55 void mdio_device_free(struct mdio_device *mdiodev);
56 struct mdio_device *mdio_device_create(struct mii_bus *bus, int addr);
57 int mdio_device_register(struct mdio_device *mdiodev);
58 void mdio_device_remove(struct mdio_device *mdiodev);
59 int mdio_driver_register(struct mdio_driver *drv);
60 void mdio_driver_unregister(struct mdio_driver *drv);
62 static inline bool mdio_phy_id_is_c45(int phy_id)
64 return (phy_id & MDIO_PHY_ID_C45) && !(phy_id & ~MDIO_PHY_ID_C45_MASK);
67 static inline __u16 mdio_phy_id_prtad(int phy_id)
69 return (phy_id & MDIO_PHY_ID_PRTAD) >> 5;
72 static inline __u16 mdio_phy_id_devad(int phy_id)
74 return phy_id & MDIO_PHY_ID_DEVAD;
78 * struct mdio_if_info - Ethernet controller MDIO interface
79 * @prtad: PRTAD of the PHY (%MDIO_PRTAD_NONE if not present/unknown)
80 * @mmds: Mask of MMDs expected to be present in the PHY. This must be
81 * non-zero unless @prtad = %MDIO_PRTAD_NONE.
82 * @mode_support: MDIO modes supported. If %MDIO_SUPPORTS_C22 is set then
83 * MII register access will be passed through with @devad =
84 * %MDIO_DEVAD_NONE. If %MDIO_EMULATE_C22 is set then access to
85 * commonly used clause 22 registers will be translated into
86 * clause 45 registers.
87 * @dev: Net device structure
88 * @mdio_read: Register read function; returns value or negative error code
89 * @mdio_write: Register write function; returns 0 or negative error code
94 unsigned mode_support;
96 struct net_device *dev;
97 int (*mdio_read)(struct net_device *dev, int prtad, int devad,
99 int (*mdio_write)(struct net_device *dev, int prtad, int devad,
103 #define MDIO_PRTAD_NONE (-1)
104 #define MDIO_DEVAD_NONE (-1)
105 #define MDIO_SUPPORTS_C22 1
106 #define MDIO_SUPPORTS_C45 2
107 #define MDIO_EMULATE_C22 4
110 struct ethtool_pauseparam;
111 extern int mdio45_probe(struct mdio_if_info *mdio, int prtad);
112 extern int mdio_set_flag(const struct mdio_if_info *mdio,
113 int prtad, int devad, u16 addr, int mask,
115 extern int mdio45_links_ok(const struct mdio_if_info *mdio, u32 mmds);
116 extern int mdio45_nway_restart(const struct mdio_if_info *mdio);
117 extern void mdio45_ethtool_gset_npage(const struct mdio_if_info *mdio,
118 struct ethtool_cmd *ecmd,
119 u32 npage_adv, u32 npage_lpa);
122 * mdio45_ethtool_gset - get settings for ETHTOOL_GSET
123 * @mdio: MDIO interface
124 * @ecmd: Ethtool request structure
126 * Since the CSRs for auto-negotiation using next pages are not fully
127 * standardised, this function does not attempt to decode them. Use
128 * mdio45_ethtool_gset_npage() to specify advertisement bits from next
131 static inline void mdio45_ethtool_gset(const struct mdio_if_info *mdio,
132 struct ethtool_cmd *ecmd)
134 mdio45_ethtool_gset_npage(mdio, ecmd, 0, 0);
137 extern int mdio_mii_ioctl(const struct mdio_if_info *mdio,
138 struct mii_ioctl_data *mii_data, int cmd);
141 * mmd_eee_cap_to_ethtool_sup_t
142 * @eee_cap: value of the MMD EEE Capability register
144 * A small helper function that translates MMD EEE Capability (3.20) bits
145 * to ethtool supported settings.
147 static inline u32 mmd_eee_cap_to_ethtool_sup_t(u16 eee_cap)
151 if (eee_cap & MDIO_EEE_100TX)
152 supported |= SUPPORTED_100baseT_Full;
153 if (eee_cap & MDIO_EEE_1000T)
154 supported |= SUPPORTED_1000baseT_Full;
155 if (eee_cap & MDIO_EEE_10GT)
156 supported |= SUPPORTED_10000baseT_Full;
157 if (eee_cap & MDIO_EEE_1000KX)
158 supported |= SUPPORTED_1000baseKX_Full;
159 if (eee_cap & MDIO_EEE_10GKX4)
160 supported |= SUPPORTED_10000baseKX4_Full;
161 if (eee_cap & MDIO_EEE_10GKR)
162 supported |= SUPPORTED_10000baseKR_Full;
168 * mmd_eee_adv_to_ethtool_adv_t
169 * @eee_adv: value of the MMD EEE Advertisement/Link Partner Ability registers
171 * A small helper function that translates the MMD EEE Advertisment (7.60)
172 * and MMD EEE Link Partner Ability (7.61) bits to ethtool advertisement
175 static inline u32 mmd_eee_adv_to_ethtool_adv_t(u16 eee_adv)
179 if (eee_adv & MDIO_EEE_100TX)
180 adv |= ADVERTISED_100baseT_Full;
181 if (eee_adv & MDIO_EEE_1000T)
182 adv |= ADVERTISED_1000baseT_Full;
183 if (eee_adv & MDIO_EEE_10GT)
184 adv |= ADVERTISED_10000baseT_Full;
185 if (eee_adv & MDIO_EEE_1000KX)
186 adv |= ADVERTISED_1000baseKX_Full;
187 if (eee_adv & MDIO_EEE_10GKX4)
188 adv |= ADVERTISED_10000baseKX4_Full;
189 if (eee_adv & MDIO_EEE_10GKR)
190 adv |= ADVERTISED_10000baseKR_Full;
196 * ethtool_adv_to_mmd_eee_adv_t
197 * @adv: the ethtool advertisement settings
199 * A small helper function that translates ethtool advertisement settings
200 * to EEE advertisements for the MMD EEE Advertisement (7.60) and
201 * MMD EEE Link Partner Ability (7.61) registers.
203 static inline u16 ethtool_adv_to_mmd_eee_adv_t(u32 adv)
207 if (adv & ADVERTISED_100baseT_Full)
208 reg |= MDIO_EEE_100TX;
209 if (adv & ADVERTISED_1000baseT_Full)
210 reg |= MDIO_EEE_1000T;
211 if (adv & ADVERTISED_10000baseT_Full)
212 reg |= MDIO_EEE_10GT;
213 if (adv & ADVERTISED_1000baseKX_Full)
214 reg |= MDIO_EEE_1000KX;
215 if (adv & ADVERTISED_10000baseKX4_Full)
216 reg |= MDIO_EEE_10GKX4;
217 if (adv & ADVERTISED_10000baseKR_Full)
218 reg |= MDIO_EEE_10GKR;
223 #endif /* __LINUX_MDIO_H__ */