batman-adv: ELP - use new ethtool_link_get_ksettings API

Message ID 1456652670-18226-1-git-send-email-sven@narfation.org (mailing list archive)
State Accepted, archived
Delegated to: Marek Lindner
Headers

Commit Message

Sven Eckelmann Feb. 28, 2016, 9:44 a.m. UTC
  From: Antonio Quartulli <a@unstable.cc>

The ethtool API is changing in linux-4.6 and the B.A.T.M.A.N. V
code has to be changed accordingly.

Fixes: 5c3245172c01 ("batman-adv: ELP - compute the metric based on the estimated throughput")
Signed-off-by: Antonio Quartulli <a@unstable.cc>
[sven@narfation.org: Added compat code for __ethtool_get_link_ksettings]
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
resend of "RFC v2" as patch with my Signed-off-by added

 compat-include/linux/ethtool.h | 62 ++++++++++++++++++++++++++++++++++++++++++
 net/batman-adv/bat_v_elp.c     | 12 ++++----
 2 files changed, 68 insertions(+), 6 deletions(-)
 create mode 100644 compat-include/linux/ethtool.h
  

Comments

Marek Lindner Feb. 29, 2016, 2:23 a.m. UTC | #1
On Sunday, February 28, 2016 10:44:30 Sven Eckelmann wrote:
> From: Antonio Quartulli <a@unstable.cc>
> 
> The ethtool API is changing in linux-4.6 and the B.A.T.M.A.N. V
> code has to be changed accordingly.
> 
> Fixes: 5c3245172c01 ("batman-adv: ELP - compute the metric based on the
> estimated throughput") Signed-off-by: Antonio Quartulli <a@unstable.cc>
> [sven@narfation.org: Added compat code for __ethtool_get_link_ksettings]
> Signed-off-by: Sven Eckelmann <sven@narfation.org>
> ---
> resend of "RFC v2" as patch with my Signed-off-by added
> 
>  compat-include/linux/ethtool.h | 62
> ++++++++++++++++++++++++++++++++++++++++++ net/batman-adv/bat_v_elp.c     |
> 12 ++++----
>  2 files changed, 68 insertions(+), 6 deletions(-)
>  create mode 100644 compat-include/linux/ethtool.h

Applied in revision 3515604.

Thanks,
Marek
  
Andreas Pape March 14, 2016, 11:54 a.m. UTC | #2
Hi everybody,

"B.A.T.M.A.N" <b.a.t.m.a.n-bounces@lists.open-mesh.org> schrieb am
29.02.2016 03:23:42:

> Von: Marek Lindner <mareklindner@neomailbox.ch>
> An: b.a.t.m.a.n@lists.open-mesh.org
> Kopie: Antonio Quartulli <a@unstable.cc>
> Datum: 29.02.2016 03:24
> Betreff: Re: [B.A.T.M.A.N.] [PATCH] batman-adv: ELP - use new
> ethtool_link_get_ksettings API
> Gesendet von: "B.A.T.M.A.N" <b.a.t.m.a.n-bounces@lists.open-mesh.org>
>
> On Sunday, February 28, 2016 10:44:30 Sven Eckelmann wrote:
> > From: Antonio Quartulli <a@unstable.cc>
> >
> > The ethtool API is changing in linux-4.6 and the B.A.T.M.A.N. V
> > code has to be changed accordingly.
> >
> > Fixes: 5c3245172c01 ("batman-adv: ELP - compute the metric based on
the
> > estimated throughput") Signed-off-by: Antonio Quartulli
<a@unstable.cc>
> > [sven@narfation.org: Added compat code for
__ethtool_get_link_ksettings]
> > Signed-off-by: Sven Eckelmann <sven@narfation.org>
> > ---
> > resend of "RFC v2" as patch with my Signed-off-by added
> >
> >  compat-include/linux/ethtool.h | 62
> > ++++++++++++++++++++++++++++++++++++++++++ net/batman-adv/bat_v_elp.c
  |
> > 12 ++++----
> >  2 files changed, 68 insertions(+), 6 deletions(-)
> >  create mode 100644 compat-include/linux/ethtool.h
>
> Applied in revision 3515604.
>
> Thanks,
> Marek

This patch breaks compatibility with older kernels (2.6.32 in my case ;-).

Is this intended? If I try to compile this I get

..../compat-include/linux/ethtool.h:49: error: implicit declaration of
function '__ethtool_get_settings'

I stumbled across this when I tried to update and test my patches for dat
and bla due to the feedback I received after I updated the master branch.

Kind regards,
Andreas



..................................................................
PHOENIX CONTACT ELECTRONICS GmbH

Sitz der Gesellschaft / registered office of the company: 31812 Bad Pyrmont
USt-Id-Nr.: DE811742156
Amtsgericht Hannover HRB 100528 / district court Hannover HRB 100528
Geschäftsführer / Executive Board: Roland Bent, Dr. Martin Heubeck
  
Sven Eckelmann March 14, 2016, 12:08 p.m. UTC | #3
On Monday 14 March 2016 12:54:36 Andreas Pape wrote:
[...]
> This patch breaks compatibility with older kernels (2.6.32 in my case ;-).
> 
> Is this intended? If I try to compile this I get
> 
> ..../compat-include/linux/ethtool.h:49: error: implicit declaration of
> function '__ethtool_get_settings'
> 
> I stumbled across this when I tried to update and test my patches for dat
> and bla due to the feedback I received after I updated the master branch.

See https://patchwork.open-mesh.org/patch/15881/


Kind regards,
	Sven
  
Marek Lindner March 27, 2016, 7:45 a.m. UTC | #4
On Monday, March 14, 2016 12:54:36 Andreas Pape wrote:
> This patch breaks compatibility with older kernels (2.6.32 in my case ;-).
> 
> Is this intended? If I try to compile this I get
> 
> ..../compat-include/linux/ethtool.h:49: error: implicit declaration of
> function '__ethtool_get_settings'
> 
> I stumbled across this when I tried to update and test my patches for dat
> and bla due to the feedback I received after I updated the master branch.

Please note that we don't plan to support these dinosaurs (2.6.*) anymore. 
With the next release we are going to drop support for kernels older than 3.2. 

Cheers,
Marek
  

Patch

diff --git a/compat-include/linux/ethtool.h b/compat-include/linux/ethtool.h
new file mode 100644
index 0000000..87f7577
--- /dev/null
+++ b/compat-include/linux/ethtool.h
@@ -0,0 +1,62 @@ 
+/* Copyright (C) 2016  B.A.T.M.A.N. contributors:
+ *
+ * Antonio Quartulli
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * This file contains macros for maintaining compatibility with older versions
+ * of the Linux kernel.
+ */
+
+#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_ETHTOOL_H_
+#define _NET_BATMAN_ADV_COMPAT_LINUX_ETHTOOL_H_
+
+#include <linux/version.h>
+#include_next <linux/ethtool.h>
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 6, 0)
+
+#define ethtool_link_ksettings batadv_ethtool_link_ksettings
+
+struct batadv_ethtool_link_ksettings {
+	struct {
+		__u32	speed;
+		__u8	duplex;
+	} base;
+};
+
+#define __ethtool_get_link_ksettings(__dev, __link_settings) \
+	batadv_ethtool_get_link_ksettings(__dev, __link_settings)
+
+static inline int
+batadv_ethtool_get_link_ksettings(struct net_device *dev,
+				  struct ethtool_link_ksettings *link_ksettings)
+{
+	struct ethtool_cmd cmd;
+	int ret;
+
+	memset(&cmd, 0, sizeof(cmd));
+	ret = __ethtool_get_settings(dev, &cmd);
+
+	if (ret != 0)
+		return ret;
+
+	link_ksettings->base.duplex = cmd.duplex;
+	link_ksettings->base.speed = ethtool_cmd_speed(&cmd);
+
+	return 0;
+}
+
+#endif /* < KERNEL_VERSION(4, 6, 0) */
+
+#endif	/* _NET_BATMAN_ADV_COMPAT_LINUX_ETHTOOL_H_ */
diff --git a/net/batman-adv/bat_v_elp.c b/net/batman-adv/bat_v_elp.c
index e94b4a0..3844e7e 100644
--- a/net/batman-adv/bat_v_elp.c
+++ b/net/batman-adv/bat_v_elp.c
@@ -73,8 +73,8 @@  static void batadv_v_elp_start_timer(struct batadv_hard_iface *hard_iface)
 static u32 batadv_v_elp_get_throughput(struct batadv_hardif_neigh_node *neigh)
 {
 	struct batadv_hard_iface *hard_iface = neigh->if_incoming;
+	struct ethtool_link_ksettings link_settings;
 	struct station_info sinfo;
-	struct ethtool_cmd cmd;
 	u32 throughput;
 	int ret;
 
@@ -110,19 +110,19 @@  static u32 batadv_v_elp_get_throughput(struct batadv_hardif_neigh_node *neigh)
 	/* if not a wifi interface, check if this device provides data via
 	 * ethtool (e.g. an Ethernet adapter)
 	 */
-	memset(&cmd, 0, sizeof(cmd));
+	memset(&link_settings, 0, sizeof(link_settings));
 	rtnl_lock();
-	ret = __ethtool_get_settings(hard_iface->net_dev, &cmd);
+	ret = __ethtool_get_link_ksettings(hard_iface->net_dev, &link_settings);
 	rtnl_unlock();
 	if (ret == 0) {
 		/* link characteristics might change over time */
-		if (cmd.duplex == DUPLEX_FULL)
+		if (link_settings.base.duplex == DUPLEX_FULL)
 			hard_iface->bat_v.flags |= BATADV_FULL_DUPLEX;
 		else
 			hard_iface->bat_v.flags &= ~BATADV_FULL_DUPLEX;
 
-		throughput = ethtool_cmd_speed(&cmd);
-		if (throughput && throughput != SPEED_UNKNOWN)
+		throughput = link_settings.base.speed;
+		if (throughput && (throughput != SPEED_UNKNOWN))
 			return throughput * 10;
 	}