aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhu Yanjun <yanjun.zhu@oracle.com>2017-05-04 01:24:51 -0400
committerDoug Ledford <dledford@redhat.com>2017-05-04 19:31:46 -0400
commit0d7e2d2166f6b0b7d1959ca858052a15feb574cc (patch)
tree65bc75a84e0c268467bd06545bb297f8ccc6d042
parent24b43c99647bf9be4995e6a6c9c3a923c147770a (diff)
IB/ipoib: add get_link_ksettings in ethtool
In order to let the bonding driver report the correct speed of the underlaying interfaces, when they are IPoIB, the ethtool function get_link_ksettings() in the IPoIB driver is implemented. Cc: Joe Jin <joe.jin@oracle.com> Cc: Junxiao Bi <junxiao.bi@oracle.com> Suggested-by: HÃ¥kon Bugge <Haakon.Bugge@oracle.com> Signed-off-by: Zhu Yanjun <yanjun.zhu@oracle.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_ethtool.c59
-rw-r--r--include/uapi/linux/ethtool.h1
2 files changed, 60 insertions, 0 deletions
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_ethtool.c b/drivers/infiniband/ulp/ipoib/ipoib_ethtool.c
index 379c02fb4181..874b24366e4d 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_ethtool.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_ethtool.c
@@ -155,7 +155,66 @@ static int ipoib_get_sset_count(struct net_device __always_unused *dev,
155 return -EOPNOTSUPP; 155 return -EOPNOTSUPP;
156} 156}
157 157
158/* Return lane speed in unit of 1e6 bit/sec */
159static inline int ib_speed_enum_to_int(int speed)
160{
161 switch (speed) {
162 case IB_SPEED_SDR:
163 return SPEED_2500;
164 case IB_SPEED_DDR:
165 return SPEED_5000;
166 case IB_SPEED_QDR:
167 case IB_SPEED_FDR10:
168 return SPEED_10000;
169 case IB_SPEED_FDR:
170 return SPEED_14000;
171 case IB_SPEED_EDR:
172 return SPEED_25000;
173 }
174
175 return SPEED_UNKNOWN;
176}
177
178static int ipoib_get_link_ksettings(struct net_device *netdev,
179 struct ethtool_link_ksettings *cmd)
180{
181 struct ipoib_dev_priv *priv = netdev_priv(netdev);
182 struct ib_port_attr attr;
183 int ret, speed, width;
184
185 if (!netif_carrier_ok(netdev)) {
186 cmd->base.speed = SPEED_UNKNOWN;
187 cmd->base.duplex = DUPLEX_UNKNOWN;
188 return 0;
189 }
190
191 ret = ib_query_port(priv->ca, priv->port, &attr);
192 if (ret < 0)
193 return -EINVAL;
194
195 speed = ib_speed_enum_to_int(attr.active_speed);
196 width = ib_width_enum_to_int(attr.active_width);
197
198 if (speed < 0 || width < 0)
199 return -EINVAL;
200
201 /* Except the following are set, the other members of
202 * the struct ethtool_link_settings are initialized to
203 * zero in the function __ethtool_get_link_ksettings.
204 */
205 cmd->base.speed = speed * width;
206 cmd->base.duplex = DUPLEX_FULL;
207
208 cmd->base.phy_address = 0xFF;
209
210 cmd->base.autoneg = AUTONEG_ENABLE;
211 cmd->base.port = PORT_OTHER;
212
213 return 0;
214}
215
158static const struct ethtool_ops ipoib_ethtool_ops = { 216static const struct ethtool_ops ipoib_ethtool_ops = {
217 .get_link_ksettings = ipoib_get_link_ksettings,
159 .get_drvinfo = ipoib_get_drvinfo, 218 .get_drvinfo = ipoib_get_drvinfo,
160 .get_coalesce = ipoib_get_coalesce, 219 .get_coalesce = ipoib_get_coalesce,
161 .set_coalesce = ipoib_set_coalesce, 220 .set_coalesce = ipoib_set_coalesce,
diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h
index 5f4ea28eabe4..d179d7767f51 100644
--- a/include/uapi/linux/ethtool.h
+++ b/include/uapi/linux/ethtool.h
@@ -1494,6 +1494,7 @@ enum ethtool_link_mode_bit_indices {
1494#define SPEED_2500 2500 1494#define SPEED_2500 2500
1495#define SPEED_5000 5000 1495#define SPEED_5000 5000
1496#define SPEED_10000 10000 1496#define SPEED_10000 10000
1497#define SPEED_14000 14000
1497#define SPEED_20000 20000 1498#define SPEED_20000 20000
1498#define SPEED_25000 25000 1499#define SPEED_25000 25000
1499#define SPEED_40000 40000 1500#define SPEED_40000 40000