1
2
3
4
5
6
7
8
9#ifndef __LINUX_MDIO_H__
10#define __LINUX_MDIO_H__
11
12#include <uapi/linux/mdio.h>
13
14struct mii_bus;
15
16static inline bool mdio_phy_id_is_c45(int phy_id)
17{
18 return (phy_id & MDIO_PHY_ID_C45) && !(phy_id & ~MDIO_PHY_ID_C45_MASK);
19}
20
21static inline __u16 mdio_phy_id_prtad(int phy_id)
22{
23 return (phy_id & MDIO_PHY_ID_PRTAD) >> 5;
24}
25
26static inline __u16 mdio_phy_id_devad(int phy_id)
27{
28 return phy_id & MDIO_PHY_ID_DEVAD;
29}
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45struct mdio_if_info {
46 int prtad;
47 u32 mmds;
48 unsigned mode_support;
49
50 struct net_device *dev;
51 int (*mdio_read)(struct net_device *dev, int prtad, int devad,
52 u16 addr);
53 int (*mdio_write)(struct net_device *dev, int prtad, int devad,
54 u16 addr, u16 val);
55};
56
57#define MDIO_PRTAD_NONE (-1)
58#define MDIO_DEVAD_NONE (-1)
59#define MDIO_SUPPORTS_C22 1
60#define MDIO_SUPPORTS_C45 2
61#define MDIO_EMULATE_C22 4
62
63struct ethtool_cmd;
64struct ethtool_pauseparam;
65extern int mdio45_probe(struct mdio_if_info *mdio, int prtad);
66extern int mdio_set_flag(const struct mdio_if_info *mdio,
67 int prtad, int devad, u16 addr, int mask,
68 bool sense);
69extern int mdio45_links_ok(const struct mdio_if_info *mdio, u32 mmds);
70extern int mdio45_nway_restart(const struct mdio_if_info *mdio);
71extern void mdio45_ethtool_gset_npage(const struct mdio_if_info *mdio,
72 struct ethtool_cmd *ecmd,
73 u32 npage_adv, u32 npage_lpa);
74extern void
75mdio45_ethtool_ksettings_get_npage(const struct mdio_if_info *mdio,
76 struct ethtool_link_ksettings *cmd,
77 u32 npage_adv, u32 npage_lpa);
78extern void
79mdio45_ethtool_spauseparam_an(const struct mdio_if_info *mdio,
80 const struct ethtool_pauseparam *ecmd);
81
82
83
84
85
86
87
88
89
90
91
92static inline void mdio45_ethtool_gset(const struct mdio_if_info *mdio,
93 struct ethtool_cmd *ecmd)
94{
95 mdio45_ethtool_gset_npage(mdio, ecmd, 0, 0);
96}
97
98
99
100
101
102
103
104
105
106
107
108static inline void
109mdio45_ethtool_ksettings_get(const struct mdio_if_info *mdio,
110 struct ethtool_link_ksettings *cmd)
111{
112 mdio45_ethtool_ksettings_get_npage(mdio, cmd, 0, 0);
113}
114
115extern int mdio_mii_ioctl(const struct mdio_if_info *mdio,
116 struct mii_ioctl_data *mii_data, int cmd);
117
118
119
120
121
122
123
124
125static inline u32 mmd_eee_cap_to_ethtool_sup_t(u16 eee_cap)
126{
127 u32 supported = 0;
128
129 if (eee_cap & MDIO_EEE_100TX)
130 supported |= SUPPORTED_100baseT_Full;
131 if (eee_cap & MDIO_EEE_1000T)
132 supported |= SUPPORTED_1000baseT_Full;
133 if (eee_cap & MDIO_EEE_10GT)
134 supported |= SUPPORTED_10000baseT_Full;
135 if (eee_cap & MDIO_EEE_1000KX)
136 supported |= SUPPORTED_1000baseKX_Full;
137 if (eee_cap & MDIO_EEE_10GKX4)
138 supported |= SUPPORTED_10000baseKX4_Full;
139 if (eee_cap & MDIO_EEE_10GKR)
140 supported |= SUPPORTED_10000baseKR_Full;
141
142 return supported;
143}
144
145
146
147
148
149
150
151
152
153static inline u32 mmd_eee_adv_to_ethtool_adv_t(u16 eee_adv)
154{
155 u32 adv = 0;
156
157 if (eee_adv & MDIO_EEE_100TX)
158 adv |= ADVERTISED_100baseT_Full;
159 if (eee_adv & MDIO_EEE_1000T)
160 adv |= ADVERTISED_1000baseT_Full;
161 if (eee_adv & MDIO_EEE_10GT)
162 adv |= ADVERTISED_10000baseT_Full;
163 if (eee_adv & MDIO_EEE_1000KX)
164 adv |= ADVERTISED_1000baseKX_Full;
165 if (eee_adv & MDIO_EEE_10GKX4)
166 adv |= ADVERTISED_10000baseKX4_Full;
167 if (eee_adv & MDIO_EEE_10GKR)
168 adv |= ADVERTISED_10000baseKR_Full;
169
170 return adv;
171}
172
173
174
175
176
177
178
179
180
181static inline u16 ethtool_adv_to_mmd_eee_adv_t(u32 adv)
182{
183 u16 reg = 0;
184
185 if (adv & ADVERTISED_100baseT_Full)
186 reg |= MDIO_EEE_100TX;
187 if (adv & ADVERTISED_1000baseT_Full)
188 reg |= MDIO_EEE_1000T;
189 if (adv & ADVERTISED_10000baseT_Full)
190 reg |= MDIO_EEE_10GT;
191 if (adv & ADVERTISED_1000baseKX_Full)
192 reg |= MDIO_EEE_1000KX;
193 if (adv & ADVERTISED_10000baseKX4_Full)
194 reg |= MDIO_EEE_10GKX4;
195 if (adv & ADVERTISED_10000baseKR_Full)
196 reg |= MDIO_EEE_10GKR;
197
198 return reg;
199}
200
201int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum);
202int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum);
203int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val);
204int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val);
205
206#endif
207