Commit | Line | Data |
---|---|---|
52c94dfa BH |
1 | /* |
2 | * linux/mdio.h: definitions for MDIO (clause 45) transceivers | |
3 | * Copyright 2006-2009 Solarflare Communications Inc. | |
4 | * | |
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. | |
8 | */ | |
52c94dfa BH |
9 | #ifndef __LINUX_MDIO_H__ |
10 | #define __LINUX_MDIO_H__ | |
11 | ||
607ca46e | 12 | #include <uapi/linux/mdio.h> |
52c94dfa | 13 | |
bac83c65 | 14 | struct mii_bus; |
9c717758 | 15 | |
e5a03bfd AL |
16 | struct mdio_device { |
17 | struct device dev; | |
18 | ||
19 | struct mii_bus *bus; | |
20 | /* Bus address of the MDIO device (0-31) */ | |
21 | int addr; | |
7f854420 | 22 | int flags; |
e5a03bfd AL |
23 | }; |
24 | #define to_mdio_device(d) container_of(d, struct mdio_device, dev) | |
25 | ||
7f854420 AL |
26 | #define MDIO_DEVICE_FLAG_PHY 1 |
27 | ||
52c94dfa BH |
28 | static inline bool mdio_phy_id_is_c45(int phy_id) |
29 | { | |
30 | return (phy_id & MDIO_PHY_ID_C45) && !(phy_id & ~MDIO_PHY_ID_C45_MASK); | |
31 | } | |
32 | ||
33 | static inline __u16 mdio_phy_id_prtad(int phy_id) | |
34 | { | |
35 | return (phy_id & MDIO_PHY_ID_PRTAD) >> 5; | |
36 | } | |
37 | ||
38 | static inline __u16 mdio_phy_id_devad(int phy_id) | |
39 | { | |
40 | return phy_id & MDIO_PHY_ID_DEVAD; | |
41 | } | |
42 | ||
1b1c2e95 BH |
43 | /** |
44 | * struct mdio_if_info - Ethernet controller MDIO interface | |
45 | * @prtad: PRTAD of the PHY (%MDIO_PRTAD_NONE if not present/unknown) | |
46 | * @mmds: Mask of MMDs expected to be present in the PHY. This must be | |
47 | * non-zero unless @prtad = %MDIO_PRTAD_NONE. | |
48 | * @mode_support: MDIO modes supported. If %MDIO_SUPPORTS_C22 is set then | |
49 | * MII register access will be passed through with @devad = | |
50 | * %MDIO_DEVAD_NONE. If %MDIO_EMULATE_C22 is set then access to | |
51 | * commonly used clause 22 registers will be translated into | |
52 | * clause 45 registers. | |
53 | * @dev: Net device structure | |
54 | * @mdio_read: Register read function; returns value or negative error code | |
55 | * @mdio_write: Register write function; returns 0 or negative error code | |
56 | */ | |
57 | struct mdio_if_info { | |
58 | int prtad; | |
23428e6b | 59 | u32 mmds; |
1b1c2e95 BH |
60 | unsigned mode_support; |
61 | ||
62 | struct net_device *dev; | |
63 | int (*mdio_read)(struct net_device *dev, int prtad, int devad, | |
64 | u16 addr); | |
65 | int (*mdio_write)(struct net_device *dev, int prtad, int devad, | |
66 | u16 addr, u16 val); | |
67 | }; | |
68 | ||
69 | #define MDIO_PRTAD_NONE (-1) | |
70 | #define MDIO_DEVAD_NONE (-1) | |
9c717758 BH |
71 | #define MDIO_SUPPORTS_C22 1 |
72 | #define MDIO_SUPPORTS_C45 2 | |
1b1c2e95 BH |
73 | #define MDIO_EMULATE_C22 4 |
74 | ||
75 | struct ethtool_cmd; | |
76 | struct ethtool_pauseparam; | |
77 | extern int mdio45_probe(struct mdio_if_info *mdio, int prtad); | |
78 | extern int mdio_set_flag(const struct mdio_if_info *mdio, | |
79 | int prtad, int devad, u16 addr, int mask, | |
80 | bool sense); | |
81 | extern int mdio45_links_ok(const struct mdio_if_info *mdio, u32 mmds); | |
82 | extern int mdio45_nway_restart(const struct mdio_if_info *mdio); | |
83 | extern void mdio45_ethtool_gset_npage(const struct mdio_if_info *mdio, | |
84 | struct ethtool_cmd *ecmd, | |
85 | u32 npage_adv, u32 npage_lpa); | |
86 | ||
87 | /** | |
88 | * mdio45_ethtool_gset - get settings for ETHTOOL_GSET | |
89 | * @mdio: MDIO interface | |
90 | * @ecmd: Ethtool request structure | |
91 | * | |
92 | * Since the CSRs for auto-negotiation using next pages are not fully | |
93 | * standardised, this function does not attempt to decode them. Use | |
94 | * mdio45_ethtool_gset_npage() to specify advertisement bits from next | |
95 | * pages. | |
96 | */ | |
97 | static inline void mdio45_ethtool_gset(const struct mdio_if_info *mdio, | |
98 | struct ethtool_cmd *ecmd) | |
99 | { | |
100 | mdio45_ethtool_gset_npage(mdio, ecmd, 0, 0); | |
101 | } | |
102 | ||
103 | extern int mdio_mii_ioctl(const struct mdio_if_info *mdio, | |
104 | struct mii_ioctl_data *mii_data, int cmd); | |
105 | ||
b32607dd AB |
106 | /** |
107 | * mmd_eee_cap_to_ethtool_sup_t | |
108 | * @eee_cap: value of the MMD EEE Capability register | |
109 | * | |
110 | * A small helper function that translates MMD EEE Capability (3.20) bits | |
111 | * to ethtool supported settings. | |
112 | */ | |
113 | static inline u32 mmd_eee_cap_to_ethtool_sup_t(u16 eee_cap) | |
114 | { | |
115 | u32 supported = 0; | |
116 | ||
117 | if (eee_cap & MDIO_EEE_100TX) | |
118 | supported |= SUPPORTED_100baseT_Full; | |
119 | if (eee_cap & MDIO_EEE_1000T) | |
120 | supported |= SUPPORTED_1000baseT_Full; | |
121 | if (eee_cap & MDIO_EEE_10GT) | |
122 | supported |= SUPPORTED_10000baseT_Full; | |
123 | if (eee_cap & MDIO_EEE_1000KX) | |
124 | supported |= SUPPORTED_1000baseKX_Full; | |
125 | if (eee_cap & MDIO_EEE_10GKX4) | |
126 | supported |= SUPPORTED_10000baseKX4_Full; | |
127 | if (eee_cap & MDIO_EEE_10GKR) | |
128 | supported |= SUPPORTED_10000baseKR_Full; | |
129 | ||
130 | return supported; | |
131 | } | |
132 | ||
133 | /** | |
134 | * mmd_eee_adv_to_ethtool_adv_t | |
135 | * @eee_adv: value of the MMD EEE Advertisement/Link Partner Ability registers | |
136 | * | |
137 | * A small helper function that translates the MMD EEE Advertisment (7.60) | |
138 | * and MMD EEE Link Partner Ability (7.61) bits to ethtool advertisement | |
139 | * settings. | |
140 | */ | |
141 | static inline u32 mmd_eee_adv_to_ethtool_adv_t(u16 eee_adv) | |
142 | { | |
143 | u32 adv = 0; | |
144 | ||
145 | if (eee_adv & MDIO_EEE_100TX) | |
146 | adv |= ADVERTISED_100baseT_Full; | |
147 | if (eee_adv & MDIO_EEE_1000T) | |
148 | adv |= ADVERTISED_1000baseT_Full; | |
149 | if (eee_adv & MDIO_EEE_10GT) | |
150 | adv |= ADVERTISED_10000baseT_Full; | |
151 | if (eee_adv & MDIO_EEE_1000KX) | |
152 | adv |= ADVERTISED_1000baseKX_Full; | |
153 | if (eee_adv & MDIO_EEE_10GKX4) | |
154 | adv |= ADVERTISED_10000baseKX4_Full; | |
155 | if (eee_adv & MDIO_EEE_10GKR) | |
156 | adv |= ADVERTISED_10000baseKR_Full; | |
157 | ||
158 | return adv; | |
159 | } | |
160 | ||
161 | /** | |
162 | * ethtool_adv_to_mmd_eee_adv_t | |
163 | * @adv: the ethtool advertisement settings | |
164 | * | |
165 | * A small helper function that translates ethtool advertisement settings | |
166 | * to EEE advertisements for the MMD EEE Advertisement (7.60) and | |
167 | * MMD EEE Link Partner Ability (7.61) registers. | |
168 | */ | |
169 | static inline u16 ethtool_adv_to_mmd_eee_adv_t(u32 adv) | |
170 | { | |
171 | u16 reg = 0; | |
172 | ||
173 | if (adv & ADVERTISED_100baseT_Full) | |
174 | reg |= MDIO_EEE_100TX; | |
175 | if (adv & ADVERTISED_1000baseT_Full) | |
176 | reg |= MDIO_EEE_1000T; | |
177 | if (adv & ADVERTISED_10000baseT_Full) | |
178 | reg |= MDIO_EEE_10GT; | |
179 | if (adv & ADVERTISED_1000baseKX_Full) | |
180 | reg |= MDIO_EEE_1000KX; | |
181 | if (adv & ADVERTISED_10000baseKX4_Full) | |
182 | reg |= MDIO_EEE_10GKX4; | |
183 | if (adv & ADVERTISED_10000baseKR_Full) | |
184 | reg |= MDIO_EEE_10GKR; | |
185 | ||
186 | return reg; | |
187 | } | |
188 | ||
bac83c65 AL |
189 | int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum); |
190 | int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum); | |
191 | int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val); | |
192 | int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val); | |
193 | ||
7f854420 AL |
194 | int mdiobus_register_device(struct mdio_device *mdiodev); |
195 | int mdiobus_unregister_device(struct mdio_device *mdiodev); | |
196 | bool mdiobus_is_registered_device(struct mii_bus *bus, int addr); | |
197 | struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr); | |
198 | ||
52c94dfa | 199 | #endif /* __LINUX_MDIO_H__ */ |