1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33#include "en.h"
34#include "ipoib.h"
35
36static void mlx5i_get_drvinfo(struct net_device *dev,
37 struct ethtool_drvinfo *drvinfo)
38{
39 struct mlx5e_priv *priv = mlx5i_epriv(dev);
40
41 mlx5e_ethtool_get_drvinfo(priv, drvinfo);
42 strlcpy(drvinfo->driver, DRIVER_NAME "[ib_ipoib]",
43 sizeof(drvinfo->driver));
44}
45
46static void mlx5i_get_strings(struct net_device *dev, u32 stringset, u8 *data)
47{
48 struct mlx5e_priv *priv = mlx5i_epriv(dev);
49
50 mlx5e_ethtool_get_strings(priv, stringset, data);
51}
52
53static int mlx5i_get_sset_count(struct net_device *dev, int sset)
54{
55 struct mlx5e_priv *priv = mlx5i_epriv(dev);
56
57 return mlx5e_ethtool_get_sset_count(priv, sset);
58}
59
60static void mlx5i_get_ethtool_stats(struct net_device *dev,
61 struct ethtool_stats *stats,
62 u64 *data)
63{
64 struct mlx5e_priv *priv = mlx5i_epriv(dev);
65
66 mlx5e_ethtool_get_ethtool_stats(priv, stats, data);
67}
68
69static int mlx5i_set_ringparam(struct net_device *dev,
70 struct ethtool_ringparam *param)
71{
72 struct mlx5e_priv *priv = mlx5i_epriv(dev);
73
74 return mlx5e_ethtool_set_ringparam(priv, param);
75}
76
77static void mlx5i_get_ringparam(struct net_device *dev,
78 struct ethtool_ringparam *param)
79{
80 struct mlx5e_priv *priv = mlx5i_epriv(dev);
81
82 mlx5e_ethtool_get_ringparam(priv, param);
83}
84
85static int mlx5i_set_channels(struct net_device *dev,
86 struct ethtool_channels *ch)
87{
88 struct mlx5e_priv *priv = mlx5i_epriv(dev);
89
90 return mlx5e_ethtool_set_channels(priv, ch);
91}
92
93static void mlx5i_get_channels(struct net_device *dev,
94 struct ethtool_channels *ch)
95{
96 struct mlx5e_priv *priv = mlx5i_epriv(dev);
97
98 mlx5e_ethtool_get_channels(priv, ch);
99}
100
101static int mlx5i_set_coalesce(struct net_device *netdev,
102 struct ethtool_coalesce *coal)
103{
104 struct mlx5e_priv *priv = mlx5i_epriv(netdev);
105
106 return mlx5e_ethtool_set_coalesce(priv, coal);
107}
108
109static int mlx5i_get_coalesce(struct net_device *netdev,
110 struct ethtool_coalesce *coal)
111{
112 struct mlx5e_priv *priv = mlx5i_epriv(netdev);
113
114 return mlx5e_ethtool_get_coalesce(priv, coal);
115}
116
117static int mlx5i_get_ts_info(struct net_device *netdev,
118 struct ethtool_ts_info *info)
119{
120 struct mlx5e_priv *priv = mlx5i_epriv(netdev);
121
122 return mlx5e_ethtool_get_ts_info(priv, info);
123}
124
125static int mlx5i_flash_device(struct net_device *netdev,
126 struct ethtool_flash *flash)
127{
128 struct mlx5e_priv *priv = mlx5i_epriv(netdev);
129
130 return mlx5e_ethtool_flash_device(priv, flash);
131}
132
133enum mlx5_ptys_width {
134 MLX5_PTYS_WIDTH_1X = 1 << 0,
135 MLX5_PTYS_WIDTH_2X = 1 << 1,
136 MLX5_PTYS_WIDTH_4X = 1 << 2,
137 MLX5_PTYS_WIDTH_8X = 1 << 3,
138 MLX5_PTYS_WIDTH_12X = 1 << 4,
139};
140
141static inline int mlx5_ptys_width_enum_to_int(enum mlx5_ptys_width width)
142{
143 switch (width) {
144 case MLX5_PTYS_WIDTH_1X: return 1;
145 case MLX5_PTYS_WIDTH_2X: return 2;
146 case MLX5_PTYS_WIDTH_4X: return 4;
147 case MLX5_PTYS_WIDTH_8X: return 8;
148 case MLX5_PTYS_WIDTH_12X: return 12;
149 default: return -1;
150 }
151}
152
153enum mlx5_ptys_rate {
154 MLX5_PTYS_RATE_SDR = 1 << 0,
155 MLX5_PTYS_RATE_DDR = 1 << 1,
156 MLX5_PTYS_RATE_QDR = 1 << 2,
157 MLX5_PTYS_RATE_FDR10 = 1 << 3,
158 MLX5_PTYS_RATE_FDR = 1 << 4,
159 MLX5_PTYS_RATE_EDR = 1 << 5,
160 MLX5_PTYS_RATE_HDR = 1 << 6,
161};
162
163static inline int mlx5_ptys_rate_enum_to_int(enum mlx5_ptys_rate rate)
164{
165 switch (rate) {
166 case MLX5_PTYS_RATE_SDR: return 2500;
167 case MLX5_PTYS_RATE_DDR: return 5000;
168 case MLX5_PTYS_RATE_QDR:
169 case MLX5_PTYS_RATE_FDR10: return 10000;
170 case MLX5_PTYS_RATE_FDR: return 14000;
171 case MLX5_PTYS_RATE_EDR: return 25000;
172 case MLX5_PTYS_RATE_HDR: return 50000;
173 default: return -1;
174 }
175}
176
177static int mlx5i_get_port_settings(struct net_device *netdev,
178 u16 *ib_link_width_oper, u16 *ib_proto_oper)
179{
180 struct mlx5e_priv *priv = mlx5i_epriv(netdev);
181 struct mlx5_core_dev *mdev = priv->mdev;
182 u32 out[MLX5_ST_SZ_DW(ptys_reg)] = {0};
183 int ret;
184
185 ret = mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_IB, 1);
186 if (ret)
187 return ret;
188
189 *ib_link_width_oper = MLX5_GET(ptys_reg, out, ib_link_width_oper);
190 *ib_proto_oper = MLX5_GET(ptys_reg, out, ib_proto_oper);
191
192 return 0;
193}
194
195static int mlx5i_get_speed_settings(u16 ib_link_width_oper, u16 ib_proto_oper)
196{
197 int rate, width;
198
199 rate = mlx5_ptys_rate_enum_to_int(ib_proto_oper);
200 if (rate < 0)
201 return -EINVAL;
202 width = mlx5_ptys_width_enum_to_int(ib_link_width_oper);
203 if (width < 0)
204 return -EINVAL;
205
206 return rate * width;
207}
208
209static int mlx5i_get_link_ksettings(struct net_device *netdev,
210 struct ethtool_link_ksettings *link_ksettings)
211{
212 u16 ib_link_width_oper;
213 u16 ib_proto_oper;
214 int speed, ret;
215
216 ret = mlx5i_get_port_settings(netdev, &ib_link_width_oper, &ib_proto_oper);
217 if (ret)
218 return ret;
219
220 ethtool_link_ksettings_zero_link_mode(link_ksettings, supported);
221 ethtool_link_ksettings_zero_link_mode(link_ksettings, advertising);
222
223 speed = mlx5i_get_speed_settings(ib_link_width_oper, ib_proto_oper);
224 if (speed < 0)
225 return -EINVAL;
226
227 link_ksettings->base.duplex = DUPLEX_FULL;
228 link_ksettings->base.port = PORT_OTHER;
229
230 link_ksettings->base.autoneg = AUTONEG_DISABLE;
231
232 link_ksettings->base.speed = speed;
233
234 return 0;
235}
236
237const struct ethtool_ops mlx5i_ethtool_ops = {
238 .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
239 ETHTOOL_COALESCE_MAX_FRAMES |
240 ETHTOOL_COALESCE_USE_ADAPTIVE,
241 .get_drvinfo = mlx5i_get_drvinfo,
242 .get_strings = mlx5i_get_strings,
243 .get_sset_count = mlx5i_get_sset_count,
244 .get_ethtool_stats = mlx5i_get_ethtool_stats,
245 .get_ringparam = mlx5i_get_ringparam,
246 .set_ringparam = mlx5i_set_ringparam,
247 .flash_device = mlx5i_flash_device,
248 .get_channels = mlx5i_get_channels,
249 .set_channels = mlx5i_set_channels,
250 .get_coalesce = mlx5i_get_coalesce,
251 .set_coalesce = mlx5i_set_coalesce,
252 .get_ts_info = mlx5i_get_ts_info,
253 .get_link_ksettings = mlx5i_get_link_ksettings,
254 .get_link = ethtool_op_get_link,
255};
256
257const struct ethtool_ops mlx5i_pkey_ethtool_ops = {
258 .get_drvinfo = mlx5i_get_drvinfo,
259 .get_link = ethtool_op_get_link,
260 .get_ts_info = mlx5i_get_ts_info,
261};
262