[PATCH 4/10 REV5] [ethtool] Add ethtool support

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Krishna Kumar
Date: Friday, September 14, 2007 - 2:02 am

Add ethtool support to enable/disable batching.

Signed-off-by: Krishna Kumar <krkumar2@in.ibm.com>
---
 include/linux/ethtool.h   |    2 ++
 include/linux/netdevice.h |    2 ++
 net/core/dev.c            |   44 ++++++++++++++++++++++++++++++++++++++++++++
 net/core/ethtool.c        |   27 +++++++++++++++++++++++++++
 4 files changed, 75 insertions(+)

diff -ruNp org/include/linux/ethtool.h new/include/linux/ethtool.h
--- org/include/linux/ethtool.h	2007-09-13 09:11:09.000000000 +0530
+++ new/include/linux/ethtool.h	2007-09-14 10:25:36.000000000 +0530
@@ -440,6 +440,8 @@ struct ethtool_ops {
 #define ETHTOOL_SFLAGS		0x00000026 /* Set flags bitmap(ethtool_value) */
 #define ETHTOOL_GPFLAGS		0x00000027 /* Get driver-private flags bitmap */
 #define ETHTOOL_SPFLAGS		0x00000028 /* Set driver-private flags bitmap */
+#define ETHTOOL_GBATCH		0x00000029 /* Get Batching (ethtool_value) */
+#define ETHTOOL_SBATCH		0x00000030 /* Set Batching (ethtool_value) */
 
 /* compatibility with older code */
 #define SPARC_ETH_GSET		ETHTOOL_GSET
diff -ruNp org/include/linux/netdevice.h new/include/linux/netdevice.h
--- org/include/linux/netdevice.h	2007-09-13 09:11:09.000000000 +0530
+++ new/include/linux/netdevice.h	2007-09-14 10:26:21.000000000 +0530
@@ -1331,6 +1331,8 @@ extern void		dev_set_promiscuity(struct 
 extern void		dev_set_allmulti(struct net_device *dev, int inc);
 extern void		netdev_state_change(struct net_device *dev);
 extern void		netdev_features_change(struct net_device *dev);
+extern int		dev_change_tx_batch_skb(struct net_device *dev,
+						unsigned long new_batch_skb);
 /* Load a device via the kmod */
 extern void		dev_load(struct net *net, const char *name);
 extern void		dev_mcast_init(void);
diff -ruNp org/net/core/dev.c new/net/core/dev.c
--- org/net/core/dev.c	2007-09-14 10:24:27.000000000 +0530
+++ new/net/core/dev.c	2007-09-14 10:25:36.000000000 +0530
@@ -963,6 +963,50 @@ void free_batching(struct net_dev
 	}
 }
 
+int dev_change_tx_batch_skb(struct net_device *dev, unsigned long new_batch_skb)
+{
+	int ret = 0;
+	struct sk_buff_head *blist = NULL;
+
+	if (!(dev->features & NETIF_F_BATCH_SKBS)) {
+		/* Driver doesn't support batching skb API */
+		ret = -EINVAL;
+		goto out;
+	}
+
+	/*
+	 * Check if new value is same as the current (paranoia to use !! for
+	 * new_batch_skb as that will be boolean via ethtool).
+	 */
+	if (!!dev->skb_blist == !!new_batch_skb)
+		goto out;
+
+	if (new_batch_skb &&
+	    (blist = kmalloc(sizeof *blist, GFP_KERNEL)) == NULL) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	/*
+	 * Block xmit as qdisc_restart() drops queue_lock before calling
+	 * driver xmit, and driver could find blist change under it.
+	 */
+	qdisc_block(dev);
+
+	spin_lock_bh(&dev->queue_lock);
+	if (new_batch_skb) {
+		skb_queue_head_init(blist);
+		dev->skb_blist = blist;
+	} else
+		free_batching(dev);
+	spin_unlock_bh(&dev->queue_lock);
+
+	qdisc_unblock(dev);
+
+out:
+	return ret;
+}
+
 /**
  *	dev_load 	- load a network module
  *	@name: name of interface
diff -ruNp org/net/core/ethtool.c new/net/core/ethtool.c
--- org/net/core/ethtool.c	2007-09-13 09:11:10.000000000 +0530
+++ new/net/core/ethtool.c	2007-09-14 10:25:36.000000000 +0530
@@ -556,6 +556,26 @@ static int ethtool_set_gso(struct net_de
 	return 0;
 }
 
+static int ethtool_get_batch(struct net_device *dev, char __user *useraddr)
+{
+	struct ethtool_value edata = { ETHTOOL_GBATCH };
+
+	edata.data = dev->skb_blist != NULL;
+	if (copy_to_user(useraddr, &edata, sizeof(edata)))
+		 return -EFAULT;
+	return 0;
+}
+
+static int ethtool_set_batch(struct net_device *dev, char __user *useraddr)
+{
+	struct ethtool_value edata;
+
+	if (copy_from_user(&edata, useraddr, sizeof(edata)))
+		return -EFAULT;
+
+	return dev_change_tx_batch_skb(dev, edata.data);
+}
+
 static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
 {
 	struct ethtool_test test;
@@ -813,6 +833,7 @@ int dev_ethtool(struct net *net, struct 
 	case ETHTOOL_GGSO:
 	case ETHTOOL_GFLAGS:
 	case ETHTOOL_GPFLAGS:
+	case ETHTOOL_GBATCH:
 		break;
 	default:
 		if (!capable(CAP_NET_ADMIN))
@@ -956,6 +977,12 @@ int dev_ethtool(struct net *net, struct 
 		rc = ethtool_set_value(dev, useraddr,
 				       dev->ethtool_ops->set_priv_flags);
 		break;
+	case ETHTOOL_GBATCH:
+		rc = ethtool_get_batch(dev, useraddr);
+		break;
+	case ETHTOOL_SBATCH:
+		rc = ethtool_set_batch(dev, useraddr);
+		break;
 	default:
 		rc = -EOPNOTSUPP;
 	}
-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 1/10 REV5] [Doc] HOWTO Documentation for batching, Krishna Kumar, (Fri Sep 14, 2:01 am)
[PATCH 4/10 REV5] [ethtool] Add ethtool support, Krishna Kumar, (Fri Sep 14, 2:02 am)
[PATCH 5/10 REV5] [IPoIB] Header file changes, Krishna Kumar, (Fri Sep 14, 2:02 am)
[PATCH 6/10 REV5] [IPoIB] CM &amp; Multicast changes, Krishna Kumar, (Fri Sep 14, 2:03 am)
[PATCH 7/10 REV5] [IPoIB] Verbs changes, Krishna Kumar, (Fri Sep 14, 2:03 am)
[PATCH 9/10 REV5] [IPoIB] Implement batching, Krishna Kumar, (Fri Sep 14, 2:04 am)
[PATCH 10/10 REV5] [E1000] Implement batching, Krishna Kumar, (Fri Sep 14, 2:04 am)
Re: [PATCH 3/10 REV5] [sched] Modify qdisc_run to support ..., Evgeniy Polyakov, (Fri Sep 14, 5:15 am)
Re: [PATCH 10/10 REV5] [E1000] Implement batching, Evgeniy Polyakov, (Fri Sep 14, 5:47 am)
Re: [PATCH 10/10 REV5] [E1000] Implement batching, Krishna Kumar2, (Sun Sep 16, 8:56 pm)
[PATCHES] TX batching, jamal, (Sun Sep 23, 10:53 am)
[PATCH 3/4][NET_BATCH] net core use batching, jamal, (Sun Sep 23, 11:00 am)
[PATCH 4/4][NET_SCHED] kill dev-&gt;gso_skb, jamal, (Sun Sep 23, 11:02 am)
Re: [PATCHES] TX batching, Jeff Garzik, (Sun Sep 23, 11:19 am)
Re: [PATCHES] TX batching, jamal, (Sun Sep 23, 12:11 pm)
Re: [PATCHES] TX batching, Kok, Auke, (Sun Sep 23, 12:36 pm)
Re: [PATCHES] TX batching, jamal, (Sun Sep 23, 2:20 pm)
Re: [PATCHES] TX batching, Kok, Auke, (Mon Sep 24, 12:00 am)
RE: [PATCH 1/4] [NET_SCHED] explict hold dev tx lock, Waskiewicz Jr, Peter P, (Mon Sep 24, 12:12 pm)
Re: [PATCHES] TX batching, jamal, (Mon Sep 24, 3:38 pm)
Re: [PATCHES] TX batching, Kok, Auke, (Mon Sep 24, 3:52 pm)
[DOC] Net batching driver howto, jamal, (Mon Sep 24, 3:54 pm)
RE: [PATCH 1/4] [NET_SCHED] explict hold dev tx lock, Waskiewicz Jr, Peter P, (Mon Sep 24, 3:57 pm)
RE: [PATCH 1/4] [NET_SCHED] explict hold dev tx lock, Waskiewicz Jr, Peter P, (Mon Sep 24, 4:47 pm)
Re: [PATCH 1/4] [NET_SCHED] explict hold dev tx lock, Stephen Hemminger, (Mon Sep 24, 5:14 pm)
Re: [PATCHES] TX batching, Jeff Garzik, (Mon Sep 24, 5:15 pm)
RE: [PATCH 1/4] [NET_SCHED] explict hold dev tx lock, Waskiewicz Jr, Peter P, (Mon Sep 24, 5:31 pm)
Re: [PATCH 1/4] [NET_SCHED] explict hold dev tx lock, Stephen Hemminger, (Tue Sep 25, 8:24 am)
Re: [DOC] Net batching driver howto, Randy Dunlap, (Tue Sep 25, 1:16 pm)
Re: [DOC] Net batching driver howto, jamal, (Tue Sep 25, 3:28 pm)
[PATCHES] TX batching, jamal, (Sun Sep 30, 11:50 am)
[PATCH 2/3][NET_BATCH] net core use batching, jamal, (Sun Sep 30, 11:52 am)
[PATCH 3/3][NET_SCHED] kill dev-&gt;gso_skb, jamal, (Sun Sep 30, 11:53 am)
Re: [PATCHES] TX batching, jamal, (Sun Sep 30, 12:19 pm)
Re: [PATCH 2/3][NET_BATCH] net core use batching, Bill Fink, (Sun Sep 30, 9:11 pm)
Re: [PATCH 2/3][NET_BATCH] net core use batching, Patrick McHardy, (Mon Oct 1, 3:42 am)
Re: [PATCH 2/3][NET_BATCH] net core use batching, Bill Fink, (Mon Oct 1, 9:25 pm)
Re: [PATCH 2/3][NET_BATCH] net core use batching, Bill Fink, (Tue Oct 2, 10:29 pm)
[PATCHES] TX batching, jamal, (Sun Oct 7, 11:34 am)
[PATCH 2/3][NET_BATCH] net core use batching, jamal, (Sun Oct 7, 11:38 am)
[PATCH 3/3][NET_BATCH] kill dev-&gt;gso_skb, jamal, (Sun Oct 7, 11:39 am)
Re: [PATCH 1/4] [NET_SCHED] explict hold dev tx lock, David Miller, (Sun Oct 7, 9:51 pm)
Re: [PATCH 2/3][NET_BATCH] net core use batching, Krishna Kumar2, (Sun Oct 7, 10:03 pm)
Re: [PATCH 1/3] [NET_BATCH] Introduce batching interface, Krishna Kumar2, (Mon Oct 8, 2:59 am)
Re: [PATCHES] TX batching, Evgeniy Polyakov, (Mon Oct 8, 5:51 am)
Re: [PATCHES] TX batching, jamal, (Mon Oct 8, 7:05 am)
Re: [PATCH 1/4] [NET_SCHED] explict hold dev tx lock, David Miller, (Mon Oct 8, 2:05 pm)
Re: parallel networking, David Miller, (Mon Oct 8, 2:11 pm)
Re: parallel networking, jamal, (Mon Oct 8, 3:30 pm)
Re: parallel networking, David Miller, (Mon Oct 8, 3:33 pm)
RE: parallel networking, Waskiewicz Jr, Peter P, (Mon Oct 8, 3:35 pm)
Re: parallel networking, jamal, (Mon Oct 8, 4:42 pm)
Re: parallel networking, Jeff Garzik, (Mon Oct 8, 6:53 pm)
Re: [PATCH 2/3][NET_BATCH] net core use batching, Krishna Kumar2, (Mon Oct 8, 8:09 pm)
Re: [PATCHES] TX batching, Krishna Kumar2, (Tue Oct 9, 1:14 am)
Re: [PATCHES] TX batching, jamal, (Tue Oct 9, 6:25 am)
Re: [PATCH 10/10 REV5] [E1000] Implement batching, Kok, Auke, (Tue Nov 13, 2:28 pm)
Re: [PATCH 10/10 REV5] [E1000] Implement batching, Krishna Kumar2, (Wed Nov 14, 1:30 am)