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