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
14
15static 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
20static inline __u16 mdio_phy_id_prtad(int phy_id)
21{
22 return (phy_id & MDIO_PHY_ID_PRTAD) >> 5;
23}
24
25static inline __u16 mdio_phy_id_devad(int phy_id)
26{
27 return phy_id & MDIO_PHY_ID_DEVAD;
28}
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44struct 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
62struct ethtool_cmd;
63struct ethtool_pauseparam;
64extern int mdio45_probe(struct mdio_if_info *mdio, int prtad);
65extern int mdio_set_flag(const struct mdio_if_info *mdio,
66 int prtad, int devad, u16 addr, int mask,
67 bool sense);
68extern int mdio45_links_ok(const struct mdio_if_info *mdio, u32 mmds);
69extern int mdio45_nway_restart(const struct mdio_if_info *mdio);
70extern void mdio45_ethtool_gset_npage(const struct mdio_if_info *mdio,
71 struct ethtool_cmd *ecmd,
72 u32 npage_adv, u32 npage_lpa);
73
74
75
76
77
78
79
80
81
82
83
84static inline void mdio45_ethtool_gset(const struct mdio_if_info *mdio,
85 struct ethtool_cmd *ecmd)
86{
87 mdio45_ethtool_gset_npage(mdio, ecmd, 0, 0);
88}
89
90extern int mdio_mii_ioctl(const struct mdio_if_info *mdio,
91 struct mii_ioctl_data *mii_data, int cmd);
92
93
94
95
96
97
98
99
100static inline u32 mmd_eee_cap_to_ethtool_sup_t(u16 eee_cap)
101{
102 u32 supported = 0;
103
104 if (eee_cap & MDIO_EEE_100TX)
105 supported |= SUPPORTED_100baseT_Full;
106 if (eee_cap & MDIO_EEE_1000T)
107 supported |= SUPPORTED_1000baseT_Full;
108 if (eee_cap & MDIO_EEE_10GT)
109 supported |= SUPPORTED_10000baseT_Full;
110 if (eee_cap & MDIO_EEE_1000KX)
111 supported |= SUPPORTED_1000baseKX_Full;
112 if (eee_cap & MDIO_EEE_10GKX4)
113 supported |= SUPPORTED_10000baseKX4_Full;
114 if (eee_cap & MDIO_EEE_10GKR)
115 supported |= SUPPORTED_10000baseKR_Full;
116
117 return supported;
118}
119
120
121
122
123
124
125
126
127
128static inline u32 mmd_eee_adv_to_ethtool_adv_t(u16 eee_adv)
129{
130 u32 adv = 0;
131
132 if (eee_adv & MDIO_EEE_100TX)
133 adv |= ADVERTISED_100baseT_Full;
134 if (eee_adv & MDIO_EEE_1000T)
135 adv |= ADVERTISED_1000baseT_Full;
136 if (eee_adv & MDIO_EEE_10GT)
137 adv |= ADVERTISED_10000baseT_Full;
138 if (eee_adv & MDIO_EEE_1000KX)
139 adv |= ADVERTISED_1000baseKX_Full;
140 if (eee_adv & MDIO_EEE_10GKX4)
141 adv |= ADVERTISED_10000baseKX4_Full;
142 if (eee_adv & MDIO_EEE_10GKR)
143 adv |= ADVERTISED_10000baseKR_Full;
144
145 return adv;
146}
147
148
149
150
151
152
153
154
155
156static inline u16 ethtool_adv_to_mmd_eee_adv_t(u32 adv)
157{
158 u16 reg = 0;
159
160 if (adv & ADVERTISED_100baseT_Full)
161 reg |= MDIO_EEE_100TX;
162 if (adv & ADVERTISED_1000baseT_Full)
163 reg |= MDIO_EEE_1000T;
164 if (adv & ADVERTISED_10000baseT_Full)
165 reg |= MDIO_EEE_10GT;
166 if (adv & ADVERTISED_1000baseKX_Full)
167 reg |= MDIO_EEE_1000KX;
168 if (adv & ADVERTISED_10000baseKX4_Full)
169 reg |= MDIO_EEE_10GKX4;
170 if (adv & ADVERTISED_10000baseKR_Full)
171 reg |= MDIO_EEE_10GKR;
172
173 return reg;
174}
175
176#endif
177