crypto: atmel-sha - remove unnecessary static in atmel_sha_remove()
[linux-stable.git] / include / linux / mii.h
blobe870bfa6abfebee71051aecf237f8de03c1b2532
1 /*
2 * linux/mii.h: definitions for MII-compatible transceivers
3 * Originally drivers/net/sunhme.h.
5 * Copyright (C) 1996, 1999, 2001 David S. Miller (davem@redhat.com)
6 */
7 #ifndef __LINUX_MII_H__
8 #define __LINUX_MII_H__
11 #include <linux/if.h>
12 #include <uapi/linux/mii.h>
14 struct ethtool_cmd;
16 struct mii_if_info {
17 int phy_id;
18 int advertising;
19 int phy_id_mask;
20 int reg_num_mask;
22 unsigned int full_duplex : 1; /* is full duplex? */
23 unsigned int force_media : 1; /* is autoneg. disabled? */
24 unsigned int supports_gmii : 1; /* are GMII registers supported? */
26 struct net_device *dev;
27 int (*mdio_read) (struct net_device *dev, int phy_id, int location);
28 void (*mdio_write) (struct net_device *dev, int phy_id, int location, int val);
31 extern int mii_link_ok (struct mii_if_info *mii);
32 extern int mii_nway_restart (struct mii_if_info *mii);
33 extern int mii_ethtool_gset(struct mii_if_info *mii, struct ethtool_cmd *ecmd);
34 extern void mii_ethtool_get_link_ksettings(
35 struct mii_if_info *mii, struct ethtool_link_ksettings *cmd);
36 extern int mii_ethtool_sset(struct mii_if_info *mii, struct ethtool_cmd *ecmd);
37 extern int mii_ethtool_set_link_ksettings(
38 struct mii_if_info *mii, const struct ethtool_link_ksettings *cmd);
39 extern int mii_check_gmii_support(struct mii_if_info *mii);
40 extern void mii_check_link (struct mii_if_info *mii);
41 extern unsigned int mii_check_media (struct mii_if_info *mii,
42 unsigned int ok_to_print,
43 unsigned int init_media);
44 extern int generic_mii_ioctl(struct mii_if_info *mii_if,
45 struct mii_ioctl_data *mii_data, int cmd,
46 unsigned int *duplex_changed);
49 static inline struct mii_ioctl_data *if_mii(struct ifreq *rq)
51 return (struct mii_ioctl_data *) &rq->ifr_ifru;
54 /**
55 * mii_nway_result
56 * @negotiated: value of MII ANAR and'd with ANLPAR
58 * Given a set of MII abilities, check each bit and returns the
59 * currently supported media, in the priority order defined by
60 * IEEE 802.3u. We use LPA_xxx constants but note this is not the
61 * value of LPA solely, as described above.
63 * The one exception to IEEE 802.3u is that 100baseT4 is placed
64 * between 100T-full and 100T-half. If your phy does not support
65 * 100T4 this is fine. If your phy places 100T4 elsewhere in the
66 * priority order, you will need to roll your own function.
68 static inline unsigned int mii_nway_result (unsigned int negotiated)
70 unsigned int ret;
72 if (negotiated & LPA_100FULL)
73 ret = LPA_100FULL;
74 else if (negotiated & LPA_100BASE4)
75 ret = LPA_100BASE4;
76 else if (negotiated & LPA_100HALF)
77 ret = LPA_100HALF;
78 else if (negotiated & LPA_10FULL)
79 ret = LPA_10FULL;
80 else
81 ret = LPA_10HALF;
83 return ret;
86 /**
87 * mii_duplex
88 * @duplex_lock: Non-zero if duplex is locked at full
89 * @negotiated: value of MII ANAR and'd with ANLPAR
91 * A small helper function for a common case. Returns one
92 * if the media is operating or locked at full duplex, and
93 * returns zero otherwise.
95 static inline unsigned int mii_duplex (unsigned int duplex_lock,
96 unsigned int negotiated)
98 if (duplex_lock)
99 return 1;
100 if (mii_nway_result(negotiated) & LPA_DUPLEX)
101 return 1;
102 return 0;
106 * ethtool_adv_to_mii_adv_t
107 * @ethadv: the ethtool advertisement settings
109 * A small helper function that translates ethtool advertisement
110 * settings to phy autonegotiation advertisements for the
111 * MII_ADVERTISE register.
113 static inline u32 ethtool_adv_to_mii_adv_t(u32 ethadv)
115 u32 result = 0;
117 if (ethadv & ADVERTISED_10baseT_Half)
118 result |= ADVERTISE_10HALF;
119 if (ethadv & ADVERTISED_10baseT_Full)
120 result |= ADVERTISE_10FULL;
121 if (ethadv & ADVERTISED_100baseT_Half)
122 result |= ADVERTISE_100HALF;
123 if (ethadv & ADVERTISED_100baseT_Full)
124 result |= ADVERTISE_100FULL;
125 if (ethadv & ADVERTISED_Pause)
126 result |= ADVERTISE_PAUSE_CAP;
127 if (ethadv & ADVERTISED_Asym_Pause)
128 result |= ADVERTISE_PAUSE_ASYM;
130 return result;
134 * mii_adv_to_ethtool_adv_t
135 * @adv: value of the MII_ADVERTISE register
137 * A small helper function that translates MII_ADVERTISE bits
138 * to ethtool advertisement settings.
140 static inline u32 mii_adv_to_ethtool_adv_t(u32 adv)
142 u32 result = 0;
144 if (adv & ADVERTISE_10HALF)
145 result |= ADVERTISED_10baseT_Half;
146 if (adv & ADVERTISE_10FULL)
147 result |= ADVERTISED_10baseT_Full;
148 if (adv & ADVERTISE_100HALF)
149 result |= ADVERTISED_100baseT_Half;
150 if (adv & ADVERTISE_100FULL)
151 result |= ADVERTISED_100baseT_Full;
152 if (adv & ADVERTISE_PAUSE_CAP)
153 result |= ADVERTISED_Pause;
154 if (adv & ADVERTISE_PAUSE_ASYM)
155 result |= ADVERTISED_Asym_Pause;
157 return result;
161 * ethtool_adv_to_mii_ctrl1000_t
162 * @ethadv: the ethtool advertisement settings
164 * A small helper function that translates ethtool advertisement
165 * settings to phy autonegotiation advertisements for the
166 * MII_CTRL1000 register when in 1000T mode.
168 static inline u32 ethtool_adv_to_mii_ctrl1000_t(u32 ethadv)
170 u32 result = 0;
172 if (ethadv & ADVERTISED_1000baseT_Half)
173 result |= ADVERTISE_1000HALF;
174 if (ethadv & ADVERTISED_1000baseT_Full)
175 result |= ADVERTISE_1000FULL;
177 return result;
181 * mii_ctrl1000_to_ethtool_adv_t
182 * @adv: value of the MII_CTRL1000 register
184 * A small helper function that translates MII_CTRL1000
185 * bits, when in 1000Base-T mode, to ethtool
186 * advertisement settings.
188 static inline u32 mii_ctrl1000_to_ethtool_adv_t(u32 adv)
190 u32 result = 0;
192 if (adv & ADVERTISE_1000HALF)
193 result |= ADVERTISED_1000baseT_Half;
194 if (adv & ADVERTISE_1000FULL)
195 result |= ADVERTISED_1000baseT_Full;
197 return result;
201 * mii_lpa_to_ethtool_lpa_t
202 * @adv: value of the MII_LPA register
204 * A small helper function that translates MII_LPA
205 * bits, when in 1000Base-T mode, to ethtool
206 * LP advertisement settings.
208 static inline u32 mii_lpa_to_ethtool_lpa_t(u32 lpa)
210 u32 result = 0;
212 if (lpa & LPA_LPACK)
213 result |= ADVERTISED_Autoneg;
215 return result | mii_adv_to_ethtool_adv_t(lpa);
219 * mii_stat1000_to_ethtool_lpa_t
220 * @adv: value of the MII_STAT1000 register
222 * A small helper function that translates MII_STAT1000
223 * bits, when in 1000Base-T mode, to ethtool
224 * advertisement settings.
226 static inline u32 mii_stat1000_to_ethtool_lpa_t(u32 lpa)
228 u32 result = 0;
230 if (lpa & LPA_1000HALF)
231 result |= ADVERTISED_1000baseT_Half;
232 if (lpa & LPA_1000FULL)
233 result |= ADVERTISED_1000baseT_Full;
235 return result;
239 * ethtool_adv_to_mii_adv_x
240 * @ethadv: the ethtool advertisement settings
242 * A small helper function that translates ethtool advertisement
243 * settings to phy autonegotiation advertisements for the
244 * MII_CTRL1000 register when in 1000Base-X mode.
246 static inline u32 ethtool_adv_to_mii_adv_x(u32 ethadv)
248 u32 result = 0;
250 if (ethadv & ADVERTISED_1000baseT_Half)
251 result |= ADVERTISE_1000XHALF;
252 if (ethadv & ADVERTISED_1000baseT_Full)
253 result |= ADVERTISE_1000XFULL;
254 if (ethadv & ADVERTISED_Pause)
255 result |= ADVERTISE_1000XPAUSE;
256 if (ethadv & ADVERTISED_Asym_Pause)
257 result |= ADVERTISE_1000XPSE_ASYM;
259 return result;
263 * mii_adv_to_ethtool_adv_x
264 * @adv: value of the MII_CTRL1000 register
266 * A small helper function that translates MII_CTRL1000
267 * bits, when in 1000Base-X mode, to ethtool
268 * advertisement settings.
270 static inline u32 mii_adv_to_ethtool_adv_x(u32 adv)
272 u32 result = 0;
274 if (adv & ADVERTISE_1000XHALF)
275 result |= ADVERTISED_1000baseT_Half;
276 if (adv & ADVERTISE_1000XFULL)
277 result |= ADVERTISED_1000baseT_Full;
278 if (adv & ADVERTISE_1000XPAUSE)
279 result |= ADVERTISED_Pause;
280 if (adv & ADVERTISE_1000XPSE_ASYM)
281 result |= ADVERTISED_Asym_Pause;
283 return result;
287 * mii_lpa_to_ethtool_lpa_x
288 * @adv: value of the MII_LPA register
290 * A small helper function that translates MII_LPA
291 * bits, when in 1000Base-X mode, to ethtool
292 * LP advertisement settings.
294 static inline u32 mii_lpa_to_ethtool_lpa_x(u32 lpa)
296 u32 result = 0;
298 if (lpa & LPA_LPACK)
299 result |= ADVERTISED_Autoneg;
301 return result | mii_adv_to_ethtool_adv_x(lpa);
305 * mii_advertise_flowctrl - get flow control advertisement flags
306 * @cap: Flow control capabilities (FLOW_CTRL_RX, FLOW_CTRL_TX or both)
308 static inline u16 mii_advertise_flowctrl(int cap)
310 u16 adv = 0;
312 if (cap & FLOW_CTRL_RX)
313 adv = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
314 if (cap & FLOW_CTRL_TX)
315 adv ^= ADVERTISE_PAUSE_ASYM;
317 return adv;
321 * mii_resolve_flowctrl_fdx
322 * @lcladv: value of MII ADVERTISE register
323 * @rmtadv: value of MII LPA register
325 * Resolve full duplex flow control as per IEEE 802.3-2005 table 28B-3
327 static inline u8 mii_resolve_flowctrl_fdx(u16 lcladv, u16 rmtadv)
329 u8 cap = 0;
331 if (lcladv & rmtadv & ADVERTISE_PAUSE_CAP) {
332 cap = FLOW_CTRL_TX | FLOW_CTRL_RX;
333 } else if (lcladv & rmtadv & ADVERTISE_PAUSE_ASYM) {
334 if (lcladv & ADVERTISE_PAUSE_CAP)
335 cap = FLOW_CTRL_RX;
336 else if (rmtadv & ADVERTISE_PAUSE_CAP)
337 cap = FLOW_CTRL_TX;
340 return cap;
343 #endif /* __LINUX_MII_H__ */