2 * Copyright (c) 2017, Mellanox Technologies. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 static void mlx5i_get_drvinfo(struct net_device *dev,
37 struct ethtool_drvinfo *drvinfo)
39 struct mlx5e_priv *priv = mlx5i_epriv(dev);
41 mlx5e_ethtool_get_drvinfo(priv, drvinfo);
42 strlcpy(drvinfo->driver, DRIVER_NAME "[ib_ipoib]",
43 sizeof(drvinfo->driver));
46 static void mlx5i_get_strings(struct net_device *dev, u32 stringset, u8 *data)
48 struct mlx5e_priv *priv = mlx5i_epriv(dev);
50 mlx5e_ethtool_get_strings(priv, stringset, data);
53 static int mlx5i_get_sset_count(struct net_device *dev, int sset)
55 struct mlx5e_priv *priv = mlx5i_epriv(dev);
57 return mlx5e_ethtool_get_sset_count(priv, sset);
60 static void mlx5i_get_ethtool_stats(struct net_device *dev,
61 struct ethtool_stats *stats,
64 struct mlx5e_priv *priv = mlx5i_epriv(dev);
66 mlx5e_ethtool_get_ethtool_stats(priv, stats, data);
69 static int mlx5i_set_ringparam(struct net_device *dev,
70 struct ethtool_ringparam *param)
72 struct mlx5e_priv *priv = mlx5i_epriv(dev);
74 return mlx5e_ethtool_set_ringparam(priv, param);
77 static void mlx5i_get_ringparam(struct net_device *dev,
78 struct ethtool_ringparam *param)
80 struct mlx5e_priv *priv = mlx5i_epriv(dev);
82 mlx5e_ethtool_get_ringparam(priv, param);
85 static int mlx5i_set_channels(struct net_device *dev,
86 struct ethtool_channels *ch)
88 struct mlx5e_priv *priv = mlx5i_epriv(dev);
90 return mlx5e_ethtool_set_channels(priv, ch);
93 static void mlx5i_get_channels(struct net_device *dev,
94 struct ethtool_channels *ch)
96 struct mlx5e_priv *priv = mlx5i_epriv(dev);
98 mlx5e_ethtool_get_channels(priv, ch);
101 static int mlx5i_set_coalesce(struct net_device *netdev,
102 struct ethtool_coalesce *coal)
104 struct mlx5e_priv *priv = mlx5i_epriv(netdev);
106 return mlx5e_ethtool_set_coalesce(priv, coal);
109 static int mlx5i_get_coalesce(struct net_device *netdev,
110 struct ethtool_coalesce *coal)
112 struct mlx5e_priv *priv = mlx5i_epriv(netdev);
114 return mlx5e_ethtool_get_coalesce(priv, coal);
117 static int mlx5i_get_ts_info(struct net_device *netdev,
118 struct ethtool_ts_info *info)
120 struct mlx5e_priv *priv = mlx5i_epriv(netdev);
122 return mlx5e_ethtool_get_ts_info(priv, info);
125 static int mlx5i_flash_device(struct net_device *netdev,
126 struct ethtool_flash *flash)
128 struct mlx5e_priv *priv = mlx5i_epriv(netdev);
130 return mlx5e_ethtool_flash_device(priv, flash);
133 enum 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,
141 static inline int mlx5_ptys_width_enum_to_int(enum mlx5_ptys_width 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;
153 enum 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,
163 static inline int mlx5_ptys_rate_enum_to_int(enum mlx5_ptys_rate 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;
177 static int mlx5i_get_port_settings(struct net_device *netdev,
178 u16 *ib_link_width_oper, u16 *ib_proto_oper)
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};
185 ret = mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_IB, 1);
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);
195 static int mlx5i_get_speed_settings(u16 ib_link_width_oper, u16 ib_proto_oper)
199 rate = mlx5_ptys_rate_enum_to_int(ib_proto_oper);
202 width = mlx5_ptys_width_enum_to_int(ib_link_width_oper);
209 static int mlx5i_get_link_ksettings(struct net_device *netdev,
210 struct ethtool_link_ksettings *link_ksettings)
212 u16 ib_link_width_oper;
216 ret = mlx5i_get_port_settings(netdev, &ib_link_width_oper, &ib_proto_oper);
220 ethtool_link_ksettings_zero_link_mode(link_ksettings, supported);
221 ethtool_link_ksettings_zero_link_mode(link_ksettings, advertising);
223 speed = mlx5i_get_speed_settings(ib_link_width_oper, ib_proto_oper);
227 link_ksettings->base.duplex = DUPLEX_FULL;
228 link_ksettings->base.port = PORT_OTHER;
230 link_ksettings->base.autoneg = AUTONEG_DISABLE;
232 link_ksettings->base.speed = speed;
237 const struct ethtool_ops mlx5i_ethtool_ops = {
238 .get_drvinfo = mlx5i_get_drvinfo,
239 .get_strings = mlx5i_get_strings,
240 .get_sset_count = mlx5i_get_sset_count,
241 .get_ethtool_stats = mlx5i_get_ethtool_stats,
242 .get_ringparam = mlx5i_get_ringparam,
243 .set_ringparam = mlx5i_set_ringparam,
244 .flash_device = mlx5i_flash_device,
245 .get_channels = mlx5i_get_channels,
246 .set_channels = mlx5i_set_channels,
247 .get_coalesce = mlx5i_get_coalesce,
248 .set_coalesce = mlx5i_set_coalesce,
249 .get_ts_info = mlx5i_get_ts_info,
250 .get_link_ksettings = mlx5i_get_link_ksettings,
251 .get_link = ethtool_op_get_link,