Netdev List
 help / color / mirror / Atom feed
* Re: [PATCH v3] net: mv643xx_eth: Fix highmem support in non-TSO egress path
From: Russell King - ARM Linux @ 2015-01-26 23:11 UTC (permalink / raw)
  To: Ezequiel Garcia; +Cc: David Miller, netdev, B38611, fabio.estevam, David.Laight
In-Reply-To: <54C3A1F9.1000403@free-electrons.com>

On Sat, Jan 24, 2015 at 10:45:29AM -0300, Ezequiel Garcia wrote:
> Hi all,
> 
> On 01/22/2015 11:33 AM, Ezequiel Garcia wrote:
> > Commit 69ad0dd7af22b61d9e0e68e56b6290121618b0fb
> > Author: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
> > Date:   Mon May 19 13:59:59 2014 -0300
> > 
> >     net: mv643xx_eth: Use dma_map_single() to map the skb fragments
> > 
> > caused a nasty regression by removing the support for highmem skb
> > fragments. By using page_address() to get the address of a fragment's
> > page, we are assuming a lowmem page. However, such assumption is incorrect,
> > as fragments can be in highmem pages, resulting in very nasty issues.
> > 
> > This commit fixes this by using the skb_frag_dma_map() helper,
> > which takes care of mapping the skb fragment properly. Additionally,
> > the type of mapping is now tracked, so it can be unmapped using
> > dma_unmap_page or dma_unmap_single when appropriate.
> > 
> > This commit also fixes the error path in txq_init() to release the
> > resources properly.
> > 
> > Fixes: 69ad0dd7af22 ("net: mv643xx_eth: Use dma_map_single() to map the skb fragments")
> > Reported-by: Russell King <rmk+kernel@arm.linux.org.uk>
> 
> Russell, when you have some time, please test this patch. I think it
> solves the regression and it manages to unmap the descriptors properly.

Yes, this seems to work as well, thanks.

-- 
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.

^ permalink raw reply

* RE: [PATCH v2] net: hyperv: else branch not necessary
From: Haiyang Zhang @ 2015-01-26 22:47 UTC (permalink / raw)
  To: Nicholas Mc Guire, KY Srinivasan
  Cc: devel@linuxdriverproject.org, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org
In-Reply-To: <1422209317-18975-1-git-send-email-der.herr@hofr.at>



> -----Original Message-----
> From: Nicholas Mc Guire [mailto:der.herr@hofr.at]
> Sent: Sunday, January 25, 2015 1:09 PM
> To: KY Srinivasan
> Cc: Haiyang Zhang; devel@linuxdriverproject.org; netdev@vger.kernel.org;
> linux-kernel@vger.kernel.org; Nicholas Mc Guire
> Subject: [PATCH v2] net: hyperv: else branch not necessary
> 
> As the if completes with a unconditional goto the else branch
> is not needed here.
> 
> Signed-off-by: Nicholas Mc Guire <der.herr@hofr.at>

Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Thank you!

> ---
> 
> v2: added missing subsystem string in subject line - patch unchanged
> 
> All paths of execution that did not exit through the if branch will
> go through the else branch so no need for an explicit else here
> 
> Patch was compile tested only for x86_64_defconfig + CONFIG_X86_VSMP=y
> CONFIG_HYPERV=m, CONFIG_HYPERV_NET=m
> 
> Patch is against 3.19.0-rc5 -next-20150123
> 
>  drivers/net/hyperv/rndis_filter.c |    8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/hyperv/rndis_filter.c
> b/drivers/net/hyperv/rndis_filter.c
> index 7bd8387..efb84a9 100644
> --- a/drivers/net/hyperv/rndis_filter.c
> +++ b/drivers/net/hyperv/rndis_filter.c
> @@ -833,10 +833,10 @@ int rndis_filter_set_packet_filter(struct
> rndis_device *dev, u32 new_filter)
>  		 * send completion for it.
>  		 */
>  		goto exit;
> -	} else {
> -		set_complete = &request->response_msg.msg.set_complete;
> -		status = set_complete->status;
> -	}
> +	}
> +
> +	set_complete = &request->response_msg.msg.set_complete;
> +	status = set_complete->status;
> 
>  cleanup:
>  	if (request)
> --
> 1.7.10.4

^ permalink raw reply

* Re: make allyesconfig i386 build failure with next-20150122 (caused by fb_agm1264k-fl driver)
From: Greg Kroah-Hartman @ 2015-01-26 22:46 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: devel, Stephen Rothwell, isdn, netdev, linux-kernel, linux-next,
	Jim Davis
In-Reply-To: <20150126215959.GA9853@roeck-us.net>

On Mon, Jan 26, 2015 at 01:59:59PM -0800, Guenter Roeck wrote:
> On Thu, Jan 22, 2015 at 12:10:33PM -0700, Jim Davis wrote:
> > make ARCH=i386 allyesconfig fails with
> > 
> > drivers/staging/built-in.o: In function `reset':
> > (.text+0x2ae89d): multiple definition of `reset'
> > drivers/isdn/built-in.o:(.text+0x185dc2): first defined here
> > make[1]: *** [drivers/built-in.o] Error 1
> 
> Culprit:
> 
> commit b2ebd4be6fa1d2329b63531b044f9e25474981cb
> Author: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
> Date:   Wed Dec 31 10:11:10 2014 +0100
> 
>     staging: fbtft: add fb_agm1264k-fl driver
> 
> A global function named 'reset' isn't really a good idea.
> 
> Not that the global function with the same name in the isdn code
> is better ;-).

Agreed, the fbtft code is now fixed.  Patches to fix the isdn code would
be gladly accepted as well :)

thanks,

greg k-h

^ permalink raw reply

* [PATCH 2/2] net: add device_poll functionality common to all net devices
From: Xander Huff @ 2015-01-26 22:46 UTC (permalink / raw)
  To: gregkh, davem, jeff.westfahl
  Cc: netdev, linux-kernel, jaeden.amero, ben.shelton, brad.mouring,
	rich.tollerton
In-Reply-To: <1422312393-61485-1-git-send-email-xander.huff@ni.com>

From: Jeff Westfahl <jeff.westfahl@ni.com>

The device_poll feature is generic to any device. Most net devices should
be able to use a set of common functionality to implement device_poll, such
as CAP_NET_ADMIN and rtnl_lock. Add this common functionality for all net
devices to use.

This is a standalone feature that should be submitted for review and
possible inclusion in mainline, or maybe in the RT patch.

Signed-off-by: Jeff Westfahl <jeff.westfahl@ni.com>
---
 include/linux/netdev_poll.h | 26 ++++++++++++++++++
 net/Kconfig                 |  3 +++
 net/core/Makefile           |  1 +
 net/core/dev_poll.c         | 64 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 94 insertions(+)
 create mode 100644 include/linux/netdev_poll.h
 create mode 100644 net/core/dev_poll.c

diff --git a/include/linux/netdev_poll.h b/include/linux/netdev_poll.h
new file mode 100644
index 0000000..3785454
--- /dev/null
+++ b/include/linux/netdev_poll.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2014 National Instruments Corp.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.
+ */
+
+#ifndef _LINUX_NETDEV_POLL_H_
+#define _LINUX_NETDEV_POLL_H_
+
+#ifdef CONFIG_NETDEV_POLL
+
+#include <linux/device_poll.h>
+
+int netdev_poll_init(struct device_poll *device_poll);
+
+#endif
+
+#endif /* _LINUX_NETDEV_POLL_H_ */
diff --git a/net/Kconfig b/net/Kconfig
index a073148..6e6ec69 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -324,5 +324,8 @@ source "net/caif/Kconfig"
 source "net/ceph/Kconfig"
 source "net/nfc/Kconfig"
 
+config NETDEV_POLL
+	bool
+	select DEVICE_POLL
 
 endif   # if NET
diff --git a/net/core/Makefile b/net/core/Makefile
index 0d357b1..4255163 100644
--- a/net/core/Makefile
+++ b/net/core/Makefile
@@ -19,3 +19,4 @@ obj-$(CONFIG_FIB_RULES) += fib_rules.o
 obj-$(CONFIG_TRACEPOINTS) += net-traces.o
 obj-$(CONFIG_NET_DROP_MONITOR) += drop_monitor.o
 obj-$(CONFIG_NETWORK_PHY_TIMESTAMPING) += timestamping.o
+obj-$(CONFIG_NETDEV_POLL) += dev_poll.o
diff --git a/net/core/dev_poll.c b/net/core/dev_poll.c
new file mode 100644
index 0000000..1f2d455
--- /dev/null
+++ b/net/core/dev_poll.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2014 National Instruments Corp.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.
+ */
+
+#include <linux/netdev_poll.h>
+#include <linux/netdevice.h>
+#include <linux/rtnetlink.h>
+
+/* netdev_poll internal functions */
+
+static int netdev_poll_reinit(struct device_poll *device_poll)
+{
+	int ret = 0;
+	struct net_device *netdev = to_net_dev(device_poll->device);
+
+	if (netif_running(netdev)) {
+		netdev->netdev_ops->ndo_stop(netdev);
+		ret = netdev->netdev_ops->ndo_open(netdev);
+	}
+
+	return ret;
+}
+
+static void netdev_poll_lock(struct device_poll *device_poll)
+{
+	rtnl_lock();
+}
+
+static void netdev_poll_unlock(struct device_poll *device_poll)
+{
+	rtnl_unlock();
+}
+
+/* netdev_poll external functions */
+
+int netdev_poll_init(struct device_poll *device_poll)
+{
+	if (!device_poll || !device_poll->device || !device_poll->ops)
+		return -EINVAL;
+
+	if (!device_poll->ops->reinit)
+		device_poll->ops->reinit = netdev_poll_reinit;
+	if (!device_poll->ops->lock)
+		device_poll->ops->lock = netdev_poll_lock;
+	if (!device_poll->ops->unlock)
+		device_poll->ops->unlock = netdev_poll_unlock;
+
+	/* Allow changes from any process with CAP_NET_ADMIN. */
+	device_poll->use_capability = 1;
+	device_poll->capability = CAP_NET_ADMIN;
+
+	return device_poll_init(device_poll);
+}
+EXPORT_SYMBOL(netdev_poll_init);
-- 
1.9.1

^ permalink raw reply related

* [PATCH 1/2] driver core: add device_poll interface
From: Xander Huff @ 2015-01-26 22:46 UTC (permalink / raw)
  To: gregkh, davem, jeff.westfahl
  Cc: netdev, linux-kernel, jaeden.amero, ben.shelton, brad.mouring,
	rich.tollerton

From: Jeff Westfahl <jeff.westfahl@ni.com>

Add the device_poll interface to the driver core. This is a generic
interface that any struct device can take advantage of to dynamically
switch between using interrupts and polling. Many drivers can be easily
modified to take advantage of this feature if desired.

This interface is most likely to be used along with the RT patch. It has
only been used thus far on Ethernet interfaces. Even with the standard
RT change to threaded interrupts for all devices, some RT applications
can be sensitive to even the minimal hardware interrupt that still occurs
with threaded interrupt handlers. The device_poll interface can be used
to completely eliminate all hardware interrupts for a device and the
associated jitter.

This is a standalone feature that should be submitted for review and
possible inclusion in mainline, or maybe in the RT patch.

Signed-off-by: Jeff Westfahl <jeff.westfahl@ni.com>
---
 drivers/base/Kconfig        |   3 +
 drivers/base/Makefile       |   1 +
 drivers/base/poll.c         | 327 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/device_poll.h | 105 ++++++++++++++
 4 files changed, 436 insertions(+)
 create mode 100644 drivers/base/poll.c
 create mode 100644 include/linux/device_poll.h

diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index 21cf46f..d23df71 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -174,4 +174,7 @@ config SYS_HYPERVISOR
 
 source "drivers/base/regmap/Kconfig"
 
+config DEVICE_POLL
+	bool
+
 endmenu
diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index 99a375a..92ab7f3 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_MODULES)	+= module.o
 endif
 obj-$(CONFIG_SYS_HYPERVISOR) += hypervisor.o
 obj-$(CONFIG_REGMAP)	+= regmap/
+obj-$(CONFIG_DEVICE_POLL) += poll.o
 
 ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG
 
diff --git a/drivers/base/poll.c b/drivers/base/poll.c
new file mode 100644
index 0000000..911a296
--- /dev/null
+++ b/drivers/base/poll.c
@@ -0,0 +1,327 @@
+/*
+ * Copyright (C) 2014 National Instruments Corp.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.
+ */
+
+#include <linux/device_poll.h>
+#include <linux/device.h>
+#include <linux/sysfs.h>
+#include <linux/sched.h>
+#include <linux/stat.h>
+#include <linux/kthread.h>
+#include <linux/delay.h>
+
+/* sysfs attributes */
+
+#define to_ext_attr(x) container_of(x, struct dev_ext_attribute, attr)
+
+/* get sysfs attributes */
+
+ssize_t device_poll_get_interval(struct device *dev,
+				 struct device_attribute *attr, char *buf)
+{
+	struct dev_ext_attribute *ea = to_ext_attr(attr);
+	struct device_poll *device_poll = ea->var;
+
+	return sprintf(buf, "%d\n", device_poll->interval);
+}
+
+static ssize_t device_poll_get_policy(struct device *dev,
+				      struct device_attribute *attr, char *buf)
+{
+	struct dev_ext_attribute *ea = to_ext_attr(attr);
+	struct device_poll *device_poll = ea->var;
+
+	switch (device_poll->policy) {
+	case SCHED_NORMAL:
+		return sprintf(buf, "SCHED_NORMAL (SCHED_OTHER)\n");
+	case SCHED_FIFO:
+		return sprintf(buf, "SCHED_FIFO\n");
+	case SCHED_RR:
+		return sprintf(buf, "SCHED_RR\n");
+	case SCHED_BATCH:
+		return sprintf(buf, "SCHED_BATCH\n");
+	case SCHED_IDLE:
+		return sprintf(buf, "SCHED_IDLE\n");
+	default:
+		return sprintf(buf, "unknown\n");
+	}
+}
+
+static ssize_t device_poll_get_priority(struct device *dev,
+					struct device_attribute *attr,
+					char *buf)
+{
+	struct dev_ext_attribute *ea = to_ext_attr(attr);
+	struct device_poll *device_poll = ea->var;
+
+	return sprintf(buf, "%d\n", device_poll->priority);
+}
+
+/* set sysfs attributes */
+
+static ssize_t device_poll_set_interval(struct device *dev,
+					struct device_attribute *attr,
+					const char *buf, size_t size)
+{
+	struct dev_ext_attribute *ea = to_ext_attr(attr);
+	struct device_poll *device_poll = ea->var;
+	int interval;
+	int ret = 0;
+
+	if (device_poll->use_capability && !capable(device_poll->capability))
+		return -EPERM;
+
+	if (0 > kstrtoint(buf, 0, &interval))
+		return -EINVAL;
+
+	device_poll->ops->lock(device_poll);
+	if (device_poll->interval != interval) {
+		device_poll->interval = interval;
+
+		ret = device_poll->ops->reinit(device_poll);
+	}
+	device_poll->ops->unlock(device_poll);
+
+	if (ret)
+		return ret;
+
+	return size;
+}
+
+static ssize_t device_poll_set_policy(struct device *dev,
+				      struct device_attribute *attr,
+				      const char *buf, size_t size)
+{
+	struct dev_ext_attribute *ea = to_ext_attr(attr);
+	struct device_poll *device_poll = ea->var;
+	char policy_str[16] = { 0 };
+	int policy;
+	struct sched_param param;
+
+	if (device_poll->use_capability && !capable(device_poll->capability))
+		return -EPERM;
+
+	if (1 != sscanf(buf, "%15s", policy_str))
+		return -EINVAL;
+
+	if ((0 == strcmp(policy_str, "SCHED_NORMAL") ||
+	     (0 == strcmp(policy_str, "SCHED_OTHER"))))
+		policy = SCHED_NORMAL;
+	else if (0 == strcmp(policy_str, "SCHED_FIFO"))
+		policy = SCHED_FIFO;
+	else if (0 == strcmp(policy_str, "SCHED_RR"))
+		policy = SCHED_RR;
+	else if (0 == strcmp(policy_str, "SCHED_BATCH"))
+		policy = SCHED_BATCH;
+	else if (0 == strcmp(policy_str, "SCHED_IDLE"))
+		policy = SCHED_IDLE;
+	else
+		return -EINVAL;
+
+	device_poll->ops->lock(device_poll);
+	if (device_poll->policy != policy) {
+		device_poll->policy = policy;
+
+		if (device_poll->task) {
+			param.sched_priority = device_poll->priority;
+			sched_setscheduler(device_poll->task,
+					   device_poll->policy,
+					   &param);
+		}
+	}
+	device_poll->ops->unlock(device_poll);
+
+	return size;
+}
+
+static ssize_t device_poll_set_priority(struct device *dev,
+					struct device_attribute *attr,
+					const char *buf, size_t size)
+{
+	struct dev_ext_attribute *ea = to_ext_attr(attr);
+	struct device_poll *device_poll = ea->var;
+	int priority;
+	struct sched_param param;
+
+	if (device_poll->use_capability && !capable(device_poll->capability))
+		return -EPERM;
+
+	if (0 > kstrtoint(buf, 0, &priority))
+		return -EINVAL;
+
+	device_poll->ops->lock(device_poll);
+	if (device_poll->priority != priority) {
+		device_poll->priority = priority;
+
+		if (device_poll->task) {
+			param.sched_priority = device_poll->priority;
+			sched_setscheduler(device_poll->task,
+					   device_poll->policy,
+					   &param);
+		}
+	}
+	device_poll->ops->unlock(device_poll);
+
+	return size;
+}
+
+/* sysfs attributes */
+
+static const DEVICE_ATTR(interval, S_IWUSR | S_IRUGO,
+			 device_poll_get_interval, device_poll_set_interval);
+
+static const DEVICE_ATTR(policy, S_IWUSR | S_IRUGO,
+			 device_poll_get_policy, device_poll_set_policy);
+
+static const DEVICE_ATTR(priority, S_IWUSR | S_IRUGO,
+			 device_poll_get_priority, device_poll_set_priority);
+
+/* device_poll internal functions */
+
+static int device_poll_thread(void *info)
+{
+	struct device_poll *device_poll = info;
+	int polling_interval;
+	int polling_interval_us;
+	struct sched_param param;
+
+	polling_interval = device_poll->interval;
+
+	/* If we got changed to interrupt mode before the polling thread
+	   started. */
+	if (unlikely(0 >= polling_interval)) {
+		while (!kthread_should_stop())
+			usleep(1);
+		return -EINTR;
+	}
+
+	polling_interval_us = polling_interval * 1000;
+
+	param.sched_priority = device_poll->priority;
+	sched_setscheduler(current, device_poll->policy, &param);
+
+	while (!kthread_should_stop()) {
+		/* Ensure changes to device_poll->enabled made on other CPUs
+		   are seen here. */
+		smp_rmb();
+		if (device_poll->enabled)
+			device_poll->ops->interrupt(device_poll);
+
+		if (20 > polling_interval)
+			usleep_range(polling_interval_us, polling_interval_us);
+		else
+			msleep(polling_interval);
+	}
+
+	return 0;
+}
+
+/* device_poll external functions */
+
+int device_poll_init(struct device_poll *device_poll)
+{
+	int ret;
+
+	if (!device_poll || !device_poll->device || !device_poll->ops)
+		return -EINVAL;
+
+	if (!device_poll->ops->reinit || !device_poll->ops->lock ||
+	    !device_poll->ops->unlock || !device_poll->ops->interrupt)
+		return -EINVAL;
+
+	if (device_poll->use_capability && !cap_valid(device_poll->capability))
+		return -EINVAL;
+
+	device_poll->task = NULL;
+	device_poll->enabled = 0;
+
+	device_poll->interval_attr.attr = dev_attr_interval;
+	device_poll->policy_attr.attr = dev_attr_policy;
+	device_poll->priority_attr.attr = dev_attr_priority;
+
+	device_poll->interval_attr.var = device_poll;
+	device_poll->policy_attr.var = device_poll;
+	device_poll->priority_attr.var = device_poll;
+
+	if (device_poll->use_capability) {
+		device_poll->interval_attr.attr.attr.mode |= S_IWUGO;
+		device_poll->policy_attr.attr.attr.mode |= S_IWUGO;
+		device_poll->priority_attr.attr.attr.mode |= S_IWUGO;
+	}
+
+	sysfs_attr_init(&device_poll->interval_attr.attr.attr);
+	sysfs_attr_init(&device_poll->policy_attr.attr.attr);
+	sysfs_attr_init(&device_poll->priority_attr.attr.attr);
+
+	device_poll->attrs[0] = &device_poll->interval_attr.attr.attr;
+	device_poll->attrs[1] = &device_poll->policy_attr.attr.attr;
+	device_poll->attrs[2] = &device_poll->priority_attr.attr.attr;
+	device_poll->attrs[3] = NULL;
+
+	device_poll->attr_group.name = "device_poll";
+	device_poll->attr_group.attrs = device_poll->attrs;
+
+	ret = sysfs_create_group(&device_poll->device->kobj,
+				 &device_poll->attr_group);
+	if (ret)
+		device_poll_exit(device_poll);
+
+	return ret;
+}
+EXPORT_SYMBOL(device_poll_init);
+
+void device_poll_exit(struct device_poll *device_poll)
+{
+	if (!device_poll || !device_poll->device)
+		return;
+
+	sysfs_remove_group(&device_poll->device->kobj,
+			   &device_poll->attr_group);
+}
+EXPORT_SYMBOL(device_poll_exit);
+
+int device_poll_request_irq(struct device_poll *device_poll)
+{
+	int err;
+
+	if (!device_poll)
+		return -EINVAL;
+
+	/* If interrupts are enabled. */
+	if (device_poll->interval <= 0)
+		return -ERANGE;
+
+	/* Start up the polling thread. */
+	device_poll->task = kthread_run(device_poll_thread,
+					device_poll, "poll/%s",
+					dev_name(device_poll->device));
+	if (IS_ERR(device_poll->task)) {
+		err = PTR_ERR(device_poll->task);
+		device_poll->task = NULL;
+		dev_err(device_poll->device,
+			"Unable to create polling thread: %d\n", err);
+		return err;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL(device_poll_request_irq);
+
+void device_poll_free_irq(struct device_poll *device_poll)
+{
+	if (device_poll_is_active(device_poll)) {
+		kthread_stop(device_poll->task);
+		device_poll->task = NULL;
+	}
+}
+EXPORT_SYMBOL(device_poll_free_irq);
diff --git a/include/linux/device_poll.h b/include/linux/device_poll.h
new file mode 100644
index 0000000..846a3b4
--- /dev/null
+++ b/include/linux/device_poll.h
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2014 National Instruments Corp.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.
+ */
+
+#ifndef _LINUX_DEVICE_POLL_H_
+#define _LINUX_DEVICE_POLL_H_
+
+#ifdef CONFIG_DEVICE_POLL
+
+#include <linux/device.h>
+
+struct device_poll;
+
+struct device_poll_ops {
+	/* Reinitialize, if the mode changes. */
+	int (*reinit)(struct device_poll *device_poll);
+
+	/* Lock and unlock, for consistency when changing settings. */
+	void (*lock)(struct device_poll *device_poll);
+	void (*unlock)(struct device_poll *device_poll);
+
+	/* Polled interrupt handler. */
+	void (*interrupt)(struct device_poll *device_poll);
+};
+
+struct device_poll {
+	/* The following must be initialized by the driver before calling
+	   device_poll_init. */
+
+	/* The device for which we're polling. */
+	struct device *device;
+
+	/* Device operations. */
+	struct device_poll_ops *ops;
+
+	/* A capability can be specified to allow non-root users to modify
+	   the sysfs attributes. */
+	bool use_capability;
+	int capability;
+
+	/* Polling interval in milliseconds. A value of 0 or less means
+	   use interrupts. */
+	int interval;
+
+	/* Polling task policy and priority, such as SCHED_FIFO 10. */
+	int policy;
+	int priority;
+
+	/* The following are internal struct members and should not be touched
+	   by drivers. */
+
+	struct task_struct *task;
+	int enabled;
+
+	struct dev_ext_attribute interval_attr;
+	struct dev_ext_attribute policy_attr;
+	struct dev_ext_attribute priority_attr;
+	struct attribute *attrs[4];
+	struct attribute_group attr_group;
+};
+
+int device_poll_init(struct device_poll *device_poll);
+void device_poll_exit(struct device_poll *device_poll);
+
+int device_poll_request_irq(struct device_poll *device_poll);
+void device_poll_free_irq(struct device_poll *device_poll);
+
+static inline int device_poll_is_active(struct device_poll *device_poll)
+{
+	return likely(device_poll) && (device_poll->task != NULL);
+}
+
+static inline void device_poll_enable_irq(struct device_poll *device_poll)
+{
+	if (device_poll_is_active(device_poll)) {
+		device_poll->enabled = 1;
+		/* Ensure changes to device_poll->enabled are seen by the
+		   polling thread. */
+		smp_wmb();
+	}
+}
+
+static inline void device_poll_disable_irq(struct device_poll *device_poll)
+{
+	if (device_poll_is_active(device_poll)) {
+		device_poll->enabled = 0;
+		/* Ensure changes to device_poll->enabled are seen by the
+		   polling thread. */
+		smp_wmb();
+	}
+}
+
+#endif
+
+#endif /* _LINUX_DEVICE_POLL_H_ */
-- 
1.9.1

^ permalink raw reply related

* Re: [PATCH net-next] cxgb4: Fixes cxgb4_inet6addr_notifier unregister call
From: David Miller @ 2015-01-26 22:46 UTC (permalink / raw)
  To: hariprasad; +Cc: netdev, leedom, anish, nirranjan, praveenm
In-Reply-To: <1421854072-6427-1-git-send-email-hariprasad@chelsio.com>

From: Hariprasad Shenai <hariprasad@chelsio.com>
Date: Wed, 21 Jan 2015 20:57:52 +0530

> commit b5a02f503caa0837 ("cxgb4 : Update ipv6 address handling api") introduced
> a regression where unregister cxgb4_inet6addr_notifier wasn't getting called
> during module_exit.
> 
> Signed-off-by: Hariprasad Shenai <hariprasad@chelsio.com>

Applied, thanks.

^ permalink raw reply

* Re: [PATCH net-next] sunvnet: improve error handling when a remote crashes
From: Sowmini Varadhan @ 2015-01-26 22:45 UTC (permalink / raw)
  To: David L Stevens; +Cc: David Miller, netdev
In-Reply-To: <54C6A95F.8010602@oracle.com>

On (01/26/15 15:53), David L Stevens wrote:
> 
> I demoted it to a notice and we can change it to a counter when we add
> stats. This way it's clear that it's an unexpected state and it's easy
> to see them when we want them.

fair enough.

--Sowmini

^ permalink raw reply

* Re: [PATCH 0/2 net-next] sunvnet: fix null pointer deref and crash recovery
From: Sowmini Varadhan @ 2015-01-26 22:44 UTC (permalink / raw)
  To: David L Stevens; +Cc: David Miller, netdev
In-Reply-To: <54C6A976.4060502@oracle.com>

On (01/26/15 15:54), David L Stevens wrote:
> These patches fix an incorrect ordering in releasing ring data, clear pending
> tx buffers on a reset, and make the sunvnet driver more reliable when remote
> systems crash during active transmits.

Acked-by: Sowmini Varadhan <sowmini.varadhan@oracle.com>

^ permalink raw reply

* Re: [PATCH 1/2] rhashtable: Introduce rhashtable_walk_*
From: Herbert Xu @ 2015-01-26 22:42 UTC (permalink / raw)
  To: David Miller
  Cc: David.Laight, tgraf, ying.xue, kaber, paulmck, netdev,
	netfilter-devel
In-Reply-To: <20150126.143613.1798698028405169123.davem@davemloft.net>

On Mon, Jan 26, 2015 at 02:36:13PM -0800, David Miller wrote:
>
> I really think the amount of time and effort being put into making
> the walker function properly is excessive.
> 
> Let's just say that if you want to use rhashtable, you have to use a
> linked list, or similar separate mechanism, to have stable walks of
> the entire set of objects.

I definitely agree with that :)

However, I'd really like to get these primitives in first so that
at least I can convert the existing rhashtable walkers over and
get on with implementing rhashtable rehashing which is what I set
out to do.

As otherwise we'd be looking at fixing the existing users (in
particular, nft_hash) properly which might take a lot more time.

If and when we finally fix the existing users we can always remove
these primitives.

FWIW when I first wrote this patch I called it
rhashtable_walk_dangerously, I can readopt that name if you think
that will dissuade people from using it.

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply

* Re: [PATCH 2/2] net: mv643xx_eth: Fix highmem support in non-TSO egress path
From: David Miller @ 2015-01-26 22:40 UTC (permalink / raw)
  To: ezequiel.garcia; +Cc: netdev, linux, B38611, fabio.estevam
In-Reply-To: <1421844850-30886-3-git-send-email-ezequiel.garcia@free-electrons.com>

From: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
Date: Wed, 21 Jan 2015 09:54:10 -0300

> +		if (!IS_TSO_HEADER(txq, desc->buf_ptr)) {
> +
> +			/* The first descriptor is either a TSO header or
> +			 * the linear part of the skb.
> +			 */

Similar to the first patch, please remove this empty line.

Thanks.

^ permalink raw reply

* Re: [PATCH 1/2] net: mvneta: Fix highmem support in the non-TSO egress path
From: David Miller @ 2015-01-26 22:40 UTC (permalink / raw)
  To: ezequiel.garcia; +Cc: netdev, linux, B38611, fabio.estevam
In-Reply-To: <1421844850-30886-2-git-send-email-ezequiel.garcia@free-electrons.com>

From: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
Date: Wed, 21 Jan 2015 09:54:09 -0300

> +		if (!IS_TSO_HEADER(txq, tx_desc->buf_phys_addr)) {
> +
> +			/* The first descriptor is either a TSO header or
> +			 * the linear part of the skb.
> +			 */

This empty line is unnecessary and inapparopriate, please remove it.

^ permalink raw reply

* RE: [PATCH] i40e: don't enable and init FCOE by default when do PF reset
From: Dev, Vasu @ 2015-01-26 22:38 UTC (permalink / raw)
  To: ethan zhao
  Cc: Kirsher, Jeffrey T, Ethan Zhao, Ronciak, John, Brandeburg, Jesse,
	Allan, Bruce W, Wyborny, Carolyn, Skidmore, Donald C,
	Rose, Gregory V, Vick, Matthew, Williams, Mitch A, Parikh, Neerav,
	Linux NICS, e1000-devel@lists.sourceforge.net,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	brian.maly@oracle.com
In-Reply-To: <54BDB7F3.2020400@oracle.com>

> -----Original Message-----
> From: ethan zhao [mailto:ethan.zhao@oracle.com]
> Sent: Monday, January 19, 2015 6:06 PM
> To: Dev, Vasu
> Cc: Kirsher, Jeffrey T; Ethan Zhao; Ronciak, John; Brandeburg, Jesse; Allan,
> Bruce W; Wyborny, Carolyn; Skidmore, Donald C; Rose, Gregory V; Vick,
> Matthew; Williams, Mitch A; Parikh, Neerav; Linux NICS; e1000-
> devel@lists.sourceforge.net; netdev@vger.kernel.org; linux-
> kernel@vger.kernel.org; brian.maly@oracle.com
> Subject: Re: [PATCH] i40e: don't enable and init FCOE by default when do PF
> reset
> 
> 
> On 2015/1/20 5:10, Dev, Vasu wrote:
> >> -----Original Message-----
> >> From: ethan zhao [mailto:ethan.zhao@oracle.com]
> >> Sent: Friday, January 16, 2015 7:01 PM
> >> To: Kirsher, Jeffrey T
> >> Cc: Dev, Vasu; Ethan Zhao; Ronciak, John; Brandeburg, Jesse; Allan,
> >> Bruce W; Wyborny, Carolyn; Skidmore, Donald C; Rose, Gregory V; Vick,
> >> Matthew; Williams, Mitch A; Parikh, Neerav; Linux NICS; e1000-
> >> devel@lists.sourceforge.net; netdev@vger.kernel.org; linux-
> >> kernel@vger.kernel.org; brian.maly@oracle.com
> >> Subject: Re: [PATCH] i40e: don't enable and init FCOE by default when
> >> do PF reset
> >>
> >> Vasu,
> >>
> >>     What' your idea about the v2, any suggestion ?  Jeff is looking
> >> forward to see it.
> >>
> > Jeff was asking for v2 in response to your last comment as "disable FCOE as
> default configuration as a temporary step" but I think that is the fix and user
> should n't enable FCoE until they have FCoE enabled X710 FCoE with either
> fabric or VN2VN mode FCoE setup.
>   As a Linux distro, we don't know users have FCoE capable X710 or not, so
> we couldn't disable the FCoE configuration
>   by default in the released kernel except FCoE is officially not supported yet
> with X710, but if yes, fix those bugs I
>   mentioned is the only choice.
> 

Yes must be fixed but I don't see your VLAN issue in my XL710  setup having engineering FW 4.33 with FCoE enabled, I could create VLANs and bring them up or down. 

As for the patch under discussion, it won't help any way whether fcoe enabled or not as I explained before. So I guess my setup differs in XL710 FW version, so upgrading FW should fix the issue and then you could keep FCoE configuration enabled in your distro w/o any concern to XL710 FCoE capable or not in XL710. We can take any FW related further discussion off list.

Thanks,
Vasu

> 
> Thanks,
> Ethan
> 
> 
> >
> > Thanks,
> > Vasu
> >
> >> Thanks,
> >> Ethan
> >>
> >>
> >> On 2015/1/16 22:47, Jeff Kirsher wrote:
> >>> On Fri, 2015-01-16 at 09:48 +0800, ethan zhao wrote:
> >>>> Vasu,
> >>>>
> >>>>       OK, disable FCOE as default configuration as a temporary step
> >>>> to make it  work.
> >>> Sounds like I should expect a v2 coming, correct?
> >>>
> >>>> Thanks,
> >>>> Ethan
> >>>>
> >>>> On 2015/1/16 7:45, Dev, Vasu wrote:
> >>>>>> -----Original Message-----
> >>>>>> From: ethan zhao [mailto:ethan.zhao@oracle.com]
> >>>>>> Sent: Tuesday, January 13, 2015 6:41 PM
> >>>>>> To: Dev, Vasu
> >>>>>> Cc: Ethan Zhao; Ronciak, John; Kirsher, Jeffrey T; Brandeburg,
> >>>>>> Jesse; Allan, Bruce W; Wyborny, Carolyn; Skidmore, Donald C;
> >>>>>> Rose, Gregory V; Vick, Matthew; Williams, Mitch A; Parikh,
> >>>>>> Neerav; Linux NICS; e1000- devel@lists.sourceforge.net;
> >>>>>> netdev@vger.kernel.org;
> >>>>>> linux- kernel@vger.kernel.org; brian.maly@oracle.com
> >>>>>> Subject: Re: [PATCH] i40e: don't enable and init FCOE by default
> >>>>>> when do PF reset
> >>>>>>
> >>>>>> Vasu,
> >>>>>>
> >>>>>> On 2015/1/14 3:38, Dev, Vasu wrote:
> >>>>>>>> -----Original Message-----
> >>>>>>>>>>> diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c
> >>>>>>>>>>> b/drivers/net/ethernet/intel/i40e/i40e_main.c
> >>>>>>>>>>> index a5f2660..a2572cc 100644
> >>>>>>>>>>> --- a/drivers/net/ethernet/intel/i40e/i40e_main.c
> >>>>>>>>>>> +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
> >>>>>>>>>>> @@ -6180,9 +6180,12 @@ static void
> >>>>>>>>>>> i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit)
> >>>>>>>>>>>         }
> >>>>>>>>>>>      #endif /* CONFIG_I40E_DCB */
> >>>>>>>>>>>      #ifdef I40E_FCOE
> >>>>>>>>>>> -   ret = i40e_init_pf_fcoe(pf);
> >>>>>>>>>>> -   if (ret)
> >>>>>>>>>>> -           dev_info(&pf->pdev->dev, "init_pf_fcoe failed: %d\n",
> ret);
> >>>>>>>>>>> +   if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
> >>>>>>>>>>> +           ret = i40e_init_pf_fcoe(pf);
> >>>>>>>>> Calling i40e_init_pf_fcoe() here conflicts with its
> >>>>>>>> I40E_FLAG_FCOE_ENABLED pre-condition since
> >>>>>> I40E_FLAG_FCOE_ENABLED is
> >>>>>>>> set by very same i40e_init_pf_fcoe(), in turn
> >>>>>>>> i40e_init_pf_fcoe() will never get called.
> >>>>>>>>
> >>>>>>>> I don't think so,  here ,i40e_reset_and_rebuild()  is not the
> >>>>>>>> only and the first place that  i40e_init_pf_fcoe() is called,
> >>>>>>>> see i40e_probe(), that is the first chance.
> >>>>>>>>
> >>>>>>>> i40e_probe()
> >>>>>>>> -->i40e_sw_init()
> >>>>>>>>          -->i40e_init_pf_fcoe()
> >>>>>>>>
> >>>>>>>> And the I40E_FLAG_FCOE_ENABLED is possible be set by
> >>>>>>>> i40e_fcoe_enable() or i40e_fcoe_disable() interface before the
> >>>>>>>> reset action is to be done.
> >>>>>>>>
> >>>>>>> It is set by i40e_init_pf_fcoe() and you are right that the
> >>>>>>> modified call flow
> >>>>>> by your patch won't impact setting of I40E_FLAG_FCOE_ENABLED
> >> anyway
> >>>>>> which could have prevented calling i40e_init_pf_fcoe() as I
> >>>>>> described above, so this is not an issue with the patch.
> >>>>>>>> BTW, the reason I post this patch is that we hit a bug, after
> >>>>>>>> setup vlan, the PF is enabled to FCOE.
> >>>>>>>>
> >>>>>>> Then that BUG would still remain un-fixed and calling
> >>>>>>> i40e_init_pf_fcoe()
> >>>>>> under I40E_FLAG_FCOE_ENABLED  flag really won't affect call flow
> >>>>>> to fix anything. I mean I40E_FLAG_FCOE_ENABLED  condition will be
> >>>>>> true with "pf-
> >>>>>>> hw.func_caps.fcoe == true" and otherwise calling
> >>>>>>> i40e_init_pf_fcoe() simply
> >>>>>> returns back early on after checking "pf->hw.func_caps.fcoe ==
> >>>>>> false", so how that bug is fixed here by added
> >> I40E_FLAG_FCOE_ENABLED  condition ?
> >>>>>> What is the bug ?
> >>>>>>      The func_caps.fcoe is assigned by following call path, under
> >>>>>> our test environment,
> >>>>>>
> >>>>>>      i40e_probe()
> >>>>>>       ->i40e_get_capabilities()
> >>>>>>          ->i40e_aq_discover_capabilities()
> >>>>>>             ->i40e_parse_discover_capabilities()
> >>>>>>
> >>>>>>      Or
> >>>>>>
> >>>>>>      i40e_reset_and_rebuild()
> >>>>>>       ->i40e_get_capabilities()
> >>>>>>         ->i40e_aq_discover_capabilities()
> >>>>>>           ->i40e_parse_discover_capabilities()
> >>>>>>
> >>>>>>      Under our test environment, the "pf->hw.func_caps.fcoe" is
> >>>>>> true. so if
> >>>>>> i40e_reset_and_rebuild() is called for VLAN setup, ethtool
> >>>>>> diagnostic
> >> test.
> >>>>>>      And then i40e_init_pf_fcoe() is to be called,
> >>>>>>
> >>>>>>      While if (!pf->hw.func_caps.fcoe) wouldn't return,
> >>>>>>
> >>>>> I said it would return with "pf->hw.func_caps.fcoe == false" in my
> >>>>> last
> >> response, more details below.
> >>>>>>      So  pf->flags is set to I40E_FLAG_FCOE_ENABLED.
> >>>>>>
> >>>>>>      With my patch,  i40e_init_pf_fcoe() is only called after
> >>>>>> I40E_FLAG_FCOE_ENABLED is set before reset.
> >>>>>>
> >>>>>> Enable FCOE in i40e_probe() or not is another issue.
> >>>>>>
> >>>>> Nope since both cases we should do i40e_init_pf_fcoe() or don't
> >>>>> based
> >> on fcoe cap true or false.
> >>>>> I don't have much to add as I described before with the your patch
> >>>>> that
> >> "calling i40e_init_pf_fcoe() under I40E_FLAG_FCOE_ENABLED  flag
> >> really won't affect call flow to fix anything. I mean
> >> I40E_FLAG_FCOE_ENABLED condition will be true with
> >> "pf->hw.func_caps.fcoe == true" and otherwise calling
> >> i40e_init_pf_fcoe() simply returns back early on after checking "pf-
> >>> hw.func_caps.fcoe == false".
> >>>>> May be I'm missing something, I guess next either go with
> >> CONFIG_I40E_FCOE disable as I suggested before and now it in upstream
> >> kernel or we can have further off list discussion to fix the issue
> >> you are trying to fix with the patch.
> >>>>> Thanks,
> >>>>> Vasu
> >>>>>
> >>>>>> Thanks,
> >>>>>> Ethan
> >>>>>>
> >>>>>>
> >>>>>>>>> Jeff Kirsher should be getting out a patch queued by me which
> >>>>>>>>> adds
> >>>>>>>> I40E_FCoE Kbuild option, in that FCoE is disabled by default
> >>>>>>>> and user could enable FCoE only if needed, that patch would do
> >>>>>>>> same of skipping
> >>>>>>>> i40e_init_pf_fcoe() whether FCoE capability in device enabled
> >>>>>>>> or not in default config.
> >>>>>>>> The following patch will not fix the above issue --
> >>>>>>>> configuration of PF will be changed via reset.
> >>>>>>>> How about the FCOE is configured and disabled by
> >>>>>>>> i40e_fcoe_disable() , then reset happens ?
> >>>>>>>>
> >>>>>>> May be but if the BUG is due to FCoE being enabled then having
> >>>>>>> it disabled
> >>>>>> in config will avoid the bug for non FCoE config option and once
> >>>>>> bug is understood then that has to be fixed for FCoE enabled
> >>>>>> config also as I asked above.
> >>>>>>> Thanks Ethan for detailed response.
> >>>>>>> Vasu
> >>>>>>>
> >>>>>>>>>     From patchwork Wed Oct  2 23:26:08 2013
> >>>>>>>>> Content-Type: text/plain; charset="utf-8"
> >>>>>>>>> MIME-Version: 1.0
> >>>>>>>>> Content-Transfer-Encoding: 7bit
> >>>>>>>>> Subject: [net] i40e: adds FCoE configure option
> >>>>>>>>> Date: Thu, 03 Oct 2013 07:26:08 -0000
> >>>>>>>>> From: Vasu Dev <vasu.dev@intel.com>
> >>>>>>>>> X-Patchwork-Id: 11797
> >>>>>>>>>
> >>>>>>>>> Adds FCoE config option I40E_FCOE, so that FCoE can be enabled
> >>>>>>>>> as needed but otherwise have it disabled by default.
> >>>>>>>>>
> >>>>>>>>> This also eliminate multiple FCoE config checks, instead now
> >>>>>>>>> just one config check for CONFIG_I40E_FCOE.
> >>>>>>>>>
> >>>>>>>>> The I40E FCoE was added with 3.17 kernel and therefore this
> >>>>>>>>> patch shall be applied to stable 3.17 kernel also.
> >>>>>>>>>
> >>>>>>>>> CC: <stable@vger.kernel.org>
> >>>>>>>>> Signed-off-by: Vasu Dev <vasu.dev@intel.com>
> >>>>>>>>> Tested-by: Jim Young <jamesx.m.young@intel.com>
> >>>>>>>>>
> >>>>>>>>> ---
> >>>>>>>>> drivers/net/ethernet/intel/Kconfig           |   11 +++++++++++
> >>>>>>>>>      drivers/net/ethernet/intel/i40e/Makefile     |    2 +-
> >>>>>>>>>      drivers/net/ethernet/intel/i40e/i40e_osdep.h |    4 ++--
> >>>>>>>>>      3 files changed, 14 insertions(+), 3 deletions(-)
> >>>>>>>>>
> >>>>>>>>> diff --git a/drivers/net/ethernet/intel/Kconfig
> >>>>>>>>> b/drivers/net/ethernet/intel/Kconfig
> >>>>>>>>> index 5b8300a..4d61ef5 100644
> >>>>>>>>> --- a/drivers/net/ethernet/intel/Kconfig
> >>>>>>>>> +++ b/drivers/net/ethernet/intel/Kconfig
> >>>>>>>>> @@ -281,6 +281,17 @@ config I40E_DCB
> >>>>>>>>>
> >>>>>>>>>               If unsure, say N.
> >>>>>>>>>
> >>>>>>>>> +config I40E_FCOE
> >>>>>>>>> +       bool "Fibre Channel over Ethernet (FCoE)"
> >>>>>>>>> +       default n
> >>>>>>>>> +       depends on I40E && DCB && FCOE
> >>>>>>>>> +       ---help---
> >>>>>>>>> +         Say Y here if you want to use Fibre Channel over
> >>>>>>>>> +Ethernet
> >> (FCoE)
> >>>>>>>>> +         in the driver. This will create new netdev for exclusive FCoE
> >>>>>>>>> +         use with XL710 FCoE offloads enabled.
> >>>>>>>>> +
> >>>>>>>>> +         If unsure, say N.
> >>>>>>>>> +
> >>>>>>>>>      config I40EVF
> >>>>>>>>>             tristate "Intel(R) XL710 X710 Virtual Function
> >>>>>>>>> Ethernet
> >> support"
> >>>>>>>>>             depends on PCI_MSI diff --git
> >>>>>>>>> a/drivers/net/ethernet/intel/i40e/Makefile
> >>>>>>>>> b/drivers/net/ethernet/intel/i40e/Makefile
> >>>>>>>>> index 4b94ddb..c405819 100644
> >>>>>>>>> --- a/drivers/net/ethernet/intel/i40e/Makefile
> >>>>>>>>> +++ b/drivers/net/ethernet/intel/i40e/Makefile
> >>>>>>>>> @@ -44,4 +44,4 @@ i40e-objs := i40e_main.o \
> >>>>>>>>>             i40e_virtchnl_pf.o
> >>>>>>>>>
> >>>>>>>>>      i40e-$(CONFIG_I40E_DCB) += i40e_dcb.o i40e_dcb_nl.o
> >>>>>>>>> -i40e-$(CONFIG_FCOE:m=y) += i40e_fcoe.o
> >>>>>>>>> +i40e-$(CONFIG_I40E_FCOE) += i40e_fcoe.o
> >>>>>>>>> diff --git a/drivers/net/ethernet/intel/i40e/i40e_osdep.h
> >>>>>>>>> b/drivers/net/ethernet/intel/i40e/i40e_osdep.h
> >>>>>>>>> index 045b5c4..ad802dd 100644
> >>>>>>>>> --- a/drivers/net/ethernet/intel/i40e/i40e_osdep.h
> >>>>>>>>> +++ b/drivers/net/ethernet/intel/i40e/i40e_osdep.h
> >>>>>>>>> @@ -78,7 +78,7 @@ do {                                                            \
> >>>>>>>>>      } while (0)
> >>>>>>>>>
> >>>>>>>>>      typedef enum i40e_status_code i40e_status; -#if
> >>>>>>>>> defined(CONFIG_FCOE)
> >>>>>>>>> || defined(CONFIG_FCOE_MODULE)
> >>>>>>>>> +#ifdef CONFIG_I40E_FCOE
> >>>>>>>>>      #define I40E_FCOE
> >>>>>>>>> -#endif /* CONFIG_FCOE or CONFIG_FCOE_MODULE */
> >>>>>>>>> +#endif
> >>>>>>>>>      #endif /* _I40E_OSDEP_H_ */
> >>>>>>>>>
> >>>>>>>>>>> +           if (ret)
> >>>>>>>>>>> +                   dev_info(&pf->pdev->dev,
> >>>>>>>>>>> +                            "init_pf_fcoe failed: %d\n", ret);
> >>>>>>>>>>> +   }
> >>>>>>>>>>>
> >>>>>>>>>>>      #endif
> >>>>>>>>>>>         /* do basic switch setup */
> >>>>>>>>>>> --
> >>>>>>>>>>> 1.8.3.1
> >>>>>>>> Thanks,
> >>>>>>>> Ethan


^ permalink raw reply

* Re: [PATCH 1/2] rhashtable: Introduce rhashtable_walk_*
From: David Miller @ 2015-01-26 22:36 UTC (permalink / raw)
  To: herbert
  Cc: David.Laight, tgraf, ying.xue, kaber, paulmck, netdev,
	netfilter-devel
In-Reply-To: <20150126222259.GC30116@gondor.apana.org.au>

From: Herbert Xu <herbert@gondor.apana.org.au>
Date: Tue, 27 Jan 2015 09:23:00 +1100

> On Mon, Jan 26, 2015 at 10:09:24AM +0000, David Laight wrote:
>>
>> That doesn't look right to me.
>> Surely you shouldn't be calling rcu_read_lock() when the mutex
>> request is interrupted.
>> 
>> So maybe:
>> 	err = mutex_lock_interruptible(&ht->mutex);
>> 	if (err)
>> 		return err;
>> 	rcu_read_lock();
> 
> No, we need to grab the RCU read lock while holding the mutex
> in order to prevent future resizes from happening once we release
> the mutex.
> 
> We don't want to hold the mutex which would stop other walks from
> starting.

I really think the amount of time and effort being put into making
the walker function properly is excessive.

Let's just say that if you want to use rhashtable, you have to use a
linked list, or similar separate mechanism, to have stable walks of
the entire set of objects.

^ permalink raw reply

* Re: [PATCH] drivers: net: xgene: fix: Out of order descriptor bytes read
From: David Miller @ 2015-01-26 22:34 UTC (permalink / raw)
  To: isubramanian
  Cc: eric.dumazet, netdev, linux-kernel, linux-arm-kernel, mlangsdo,
	patches, kchudgar
In-Reply-To: <CAKh23FmxvV82mVrHq5jv-FE+e6u6CkW+xL_a2_ULAQgP_mM2VA@mail.gmail.com>

From: Iyappan Subramanian <isubramanian@apm.com>
Date: Mon, 26 Jan 2015 13:12:23 -0800

>>> @@ -369,6 +369,8 @@ static int xgene_enet_process_ring(struct xgene_enet_desc_ring *ring,
>>>               if (unlikely(xgene_enet_is_desc_slot_empty(raw_desc)))
>>>                       break;
>>>
>>> +             /* read fpqnum field after dataaddr field */
>>> +             smp_rmb();
>>>               if (is_rx_desc(raw_desc))
>>>                       ret = xgene_enet_rx_frame(ring, raw_desc);
>>>               else
>>
>> Reading your changelog, it looks like you need a plain rmb() here.
> 
> rmb() translates into dsb, which in arm64 serializes everything
> including instructions and thus expensive compared to dmb.
> 
> Do you see any issue with smp_rmb() (which translates into dmb) ?

smp_rmb() is not appropriate.  You're not serializing accesses between
two cpus, you're serializing the cpu with the device.

^ permalink raw reply

* Re: [PATCH] net: Linn Ethernet Packet Sniffer driver
From: Florian Fainelli @ 2015-01-26 22:30 UTC (permalink / raw)
  To: Stathis Voukelatos, netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA
  Cc: Stathis Voukelatos, abrestic-F7+t8E8rja9g9hUCZPvPmw
In-Reply-To: <1422007621-13567-1-git-send-email-stathis.voukelatos-zgcZaY4qg+21Qrn1Bg8BZw@public.gmane.org>

On 23/01/15 02:07, Stathis Voukelatos wrote:
> This patch adds support the Ethernet Packet Sniffer H/W module
> developed by Linn Products Ltd and found in the IMG Pistachio SoC.
> The module allows Ethernet packets to be parsed, matched against
> a user-defined pattern and timestamped. It sits between a 100M
> Ethernet MAC and PHY and is completely passive with respect to
> Ethernet frames.

Is there any latency penalty involved in capturing (or not) packets as
opposed to having this capture HW unused?

> 
> Matched packet bytes and timestamp values are returned through a
> FIFO. Timestamps are provided to the module through an externally
> generated Gray-encoded counter.
> 
> The command pattern for packet matching is stored in module RAM
> and consists of a sequence of 16-bit entries. Each entry includes
> an 8-bit command code and and 8-bit data value. Valid command
> codes are:
> 0 - Don't care
> 1 - Match: packet data must match command string byte
> 2 - Copy: packet data will be copied to FIFO
> 3 - Match/Stamp: if packet data matches string byte, a timestamp
>                  is copied into the FIFO
> 4 - Copy/Done: packet data will be copied into the FIFO.
>                This command terminates the command string.
> 
> The driver consists of two modules:
> - Core: it provides an API to user space using the Generic Netlink
>         framework. Specific backend implementations, like the
>         Ethernet Packet Sniffer, register one or more channels
>         with the Core. For each channel a Genl family is created.
>         User space can access a channel by sending Genl messages
>         to the Genl family associated with the channel. Packet
>         matching events are multicast.

Instead of having this new generic netlink family to control sniffing,
could we imagine registering a netdevice which does not nothing but
still allows for tools like tcpdump, af_packet and other capture tools
to work transparently and just leverage the HW capture?

> 
> - Ethernet Packet Sniffer backend: provides the driver for the
>         Linn Ethernet Packet Sniffer H/W modules.
> 
> The split between a core and backend modules allows software-only
> implementations to be added for platforms where no H/W support
> is available.
> 
> Based on 3.19-rc5
> 
> Signed-off-by: Stathis Voukelatos <stathis.voukelatos-zgcZaY4qg+21Qrn1Bg8BZw@public.gmane.org>
> ---
>  .../bindings/net/linn-ether-packet-sniffer.txt     |  27 ++
>  .../devicetree/bindings/vendor-prefixes.txt        |   1 +
>  MAINTAINERS                                        |   7 +
>  drivers/net/Kconfig                                |   2 +
>  drivers/net/Makefile                               |   1 +
>  drivers/net/pkt-sniffer/Kconfig                    |  23 ++
>  drivers/net/pkt-sniffer/Makefile                   |   8 +
>  drivers/net/pkt-sniffer/backends/ether/channel.c   | 366 ++++++++++++++++++
>  drivers/net/pkt-sniffer/backends/ether/channel.h   |  76 ++++
>  drivers/net/pkt-sniffer/backends/ether/hw.h        |  46 +++
>  drivers/net/pkt-sniffer/backends/ether/platform.c  | 231 +++++++++++
>  drivers/net/pkt-sniffer/core/dev_table.c           | 124 ++++++
>  drivers/net/pkt-sniffer/core/module.c              |  37 ++
>  drivers/net/pkt-sniffer/core/nl.c                  | 427 +++++++++++++++++++++
>  drivers/net/pkt-sniffer/core/nl.h                  |  34 ++
>  drivers/net/pkt-sniffer/core/snf_core.h            |  64 +++
>  include/linux/pkt_sniffer.h                        |  89 +++++
>  17 files changed, 1563 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt
>  create mode 100644 drivers/net/pkt-sniffer/Kconfig
>  create mode 100644 drivers/net/pkt-sniffer/Makefile
>  create mode 100644 drivers/net/pkt-sniffer/backends/ether/channel.c
>  create mode 100644 drivers/net/pkt-sniffer/backends/ether/channel.h
>  create mode 100644 drivers/net/pkt-sniffer/backends/ether/hw.h
>  create mode 100644 drivers/net/pkt-sniffer/backends/ether/platform.c
>  create mode 100644 drivers/net/pkt-sniffer/core/dev_table.c
>  create mode 100644 drivers/net/pkt-sniffer/core/module.c
>  create mode 100644 drivers/net/pkt-sniffer/core/nl.c
>  create mode 100644 drivers/net/pkt-sniffer/core/nl.h
>  create mode 100644 drivers/net/pkt-sniffer/core/snf_core.h
>  create mode 100644 include/linux/pkt_sniffer.h
> 
> diff --git a/Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt b/Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt
> new file mode 100644
> index 0000000..6b6e105
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt
> @@ -0,0 +1,27 @@
> +* Linn Products Ethernet Packet Sniffer
> +
> +Required properties:
> +- compatible : must be "linn,eth-sniffer"
> +- reg : physical addresses and sizes of registers. Must contain 3 entries:
> +          first entry: registers memory space
> +          second entry: TX command memory
> +          third entry: RX command memory
> +- reg-names : must contain the following 3 entries:
> +                  "regs", "tx-ram", "rx-ram"
> +- interrupts : sniffer interrupt specifier
> +- clocks : specify the system clock for the peripheral
> +- clock-names : must contain the "sys" entry
> +- fifo-block-words : number of words in one data FIFO entry
> +
> +Example:
> +
> +sniffer@1814a000 {
> +        compatible = "linn,eth-sniffer";
> +        reg = <0x1814a000 0x100>, <0x1814a400 0x400>, <0x1814a800 0x400>;
> +        reg-names = "regs", "tx-ram", "rx-ram";
> +        interrupts = <GIC_SHARED 58 IRQ_TYPE_LEVEL_HIGH>;
> +        interrupt-names = "eth-sniffer-irq";
> +        clocks = <&system_clk>;
> +        clock-names = "sys";
> +        fifo-block-words = <4>;
> +    };
> diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt
> index b1df0ad..2c96f35 100644
> --- a/Documentation/devicetree/bindings/vendor-prefixes.txt
> +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
> @@ -90,6 +90,7 @@ lacie	LaCie
>  lantiq	Lantiq Semiconductor
>  lenovo	Lenovo Group Ltd.
>  lg	LG Corporation
> +linn	Linn Products Ltd.
>  linux	Linux-specific binding
>  lsi	LSI Corp. (LSI Logic)
>  lltc	Linear Technology Corporation
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 2fa3853..7dbc6e7 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -5708,6 +5708,13 @@ M:	Sasha Levin <sasha.levin-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
>  S:	Maintained
>  F:	tools/lib/lockdep/
>  
> +LINN PACKET SNIFFER DRIVER
> +M: Stathis Voukelatos <stathis.voukelatos-zgcZaY4qg+21Qrn1Bg8BZw@public.gmane.org>
> +S: Maintained
> +F: include/linux/pkt_sniffer.h
> +F: drivers/net/pkt-sniffer/
> +F: Documentation/devicetree/bindings/net/linn-ether-packet-sniffer.txt
> +
>  LINUX FOR IBM pSERIES (RS/6000)
>  M:	Paul Mackerras <paulus-hXjcm30GF6XQT0dZR+AlfA@public.gmane.org>
>  W:	http://www.ibm.com/linux/ltc/projects/ppc
> diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
> index d6607ee..219c786 100644
> --- a/drivers/net/Kconfig
> +++ b/drivers/net/Kconfig
> @@ -380,4 +380,6 @@ config VMXNET3
>  
>  source "drivers/net/hyperv/Kconfig"
>  
> +source "drivers/net/pkt-sniffer/Kconfig"
> +
>  endif # NETDEVICES
> diff --git a/drivers/net/Makefile b/drivers/net/Makefile
> index e25fdd7..441111b 100644
> --- a/drivers/net/Makefile
> +++ b/drivers/net/Makefile
> @@ -66,3 +66,4 @@ obj-$(CONFIG_USB_NET_DRIVERS) += usb/
>  
>  obj-$(CONFIG_HYPERV_NET) += hyperv/
>  obj-$(CONFIG_NTB_NETDEV) += ntb_netdev.o
> +obj-$(CONFIG_PKT_SNIFFER) += pkt-sniffer/
> diff --git a/drivers/net/pkt-sniffer/Kconfig b/drivers/net/pkt-sniffer/Kconfig
> new file mode 100644
> index 0000000..26b4f98
> --- /dev/null
> +++ b/drivers/net/pkt-sniffer/Kconfig
> @@ -0,0 +1,23 @@
> +menuconfig PKT_SNIFFER
> +    tristate "Linn packet sniffer support"
> +    ---help---
> +    Say Y to add support for Linn packet sniffer drivers.
> +
> +    The core driver can also be built as a module. If so, the module
> +    will be called snf_core.
> +
> +if PKT_SNIFFER
> +
> +config PKT_SNIFFER_ETHER
> +    tristate "Ethernet packet sniffer"
> +    depends on MIPS
> +    default n
> +    help
> +        Say Y here if you want to use the Linn Ethernet packet sniffer
> +        module. It can be found in the upcoming Pistachio SoC by
> +        Imagination Technologies.
> +
> +        The driver can also be built as a module. If so, the module
> +        will be called snf_ether.
> +
> +endif # PKT_SNIFFER
> diff --git a/drivers/net/pkt-sniffer/Makefile b/drivers/net/pkt-sniffer/Makefile
> new file mode 100644
> index 0000000..07e7339
> --- /dev/null
> +++ b/drivers/net/pkt-sniffer/Makefile
> @@ -0,0 +1,8 @@
> +snf_core-y += core/nl.o
> +snf_core-y += core/dev_table.o
> +snf_core-y += core/module.o
> +obj-$(CONFIG_PKT_SNIFFER) += snf_core.o
> +
> +snf_ether-y += backends/ether/platform.o
> +snf_ether-y += backends/ether/channel.o
> +obj-$(CONFIG_PKT_SNIFFER_ETHER) += snf_ether.o
> diff --git a/drivers/net/pkt-sniffer/backends/ether/channel.c b/drivers/net/pkt-sniffer/backends/ether/channel.c
> new file mode 100644
> index 0000000..d483b58
> --- /dev/null
> +++ b/drivers/net/pkt-sniffer/backends/ether/channel.c
> @@ -0,0 +1,366 @@
> +/*
> + * Ethernet Mii packet sniffer driver
> + *  - channel functions
> + *
> + * Copyright (C) 2015 Linn Products Ltd
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2
> + * 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.
> + *
> + * Written by:
> + * Stathis Voukelatos <stathis.voukelatos-zgcZaY4qg+21Qrn1Bg8BZw@public.gmane.org>
> + */
> +#include <linux/io.h>
> +#include <linux/of.h>
> +#include <linux/pkt_sniffer.h>
> +#include "../../core/snf_core.h"
> +#include "hw.h"
> +#include "channel.h"
> +
> +#define to_ether_snf_chan(dev) container_of(dev, struct ether_snf_chan, chan)
> +
> +static int esnf_start(struct snf_chan *dev);
> +static int esnf_stop(struct snf_chan *dev);
> +static int esnf_set_pattern(struct snf_chan *dev, const u8 *pattern, int count);
> +static int esnf_num_recs_avail(struct snf_chan *dev);
> +static int esnf_max_ptn_entries(struct snf_chan *dev);
> +static int esnf_max_match_bytes(struct snf_chan *dev);
> +static int validate_pattern(
> +			struct ether_snf_chan *ch,
> +			const u8 *buf,
> +			int count);
> +static void read_fifo_data(struct ether_snf_chan *ch);
> +static u32 gray_decode(u32 gray);
> +
> +/* Initialises a sniffer channel */
> +int channel_init(
> +	struct ether_snf_chan *ch,
> +	struct platform_device *pdev,
> +	void *regs,
> +	int fifo_blk_words,
> +	int tx)
> +{
> +	struct resource *res;
> +	u32 *ptr;
> +	int i;
> +
> +	ch->regs = regs;
> +	ch->dev = &pdev->dev;
> +	ch->data_irq_bit = tx ? TX_DATA_IRQ_BIT : RX_DATA_IRQ_BIT;
> +	ch->full_irq_bit = tx ? TX_FULL_IRQ_BIT : RX_FULL_IRQ_BIT;
> +	ch->reg_enable = ch->regs +
> +			 (tx ? TX_SNIFFER_ENABLE : RX_SNIFFER_ENABLE);
> +	ch->reg_occ = ch->regs + (tx ? TX_FIFO_OCC : RX_FIFO_OCC);
> +	ch->reg_fifo = ch->regs + (tx ? TX_FIFO_DAT : RX_FIFO_DAT);
> +
> +	/* Retrieve and remap the address space for the command memory */
> +	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
> +					   tx ? "tx-ram" : "rx-ram");
> +	if (!res)
> +		return -ENOSYS;
> +	ch->cmd_ram = devm_ioremap_resource(&pdev->dev, res);
> +	if (IS_ERR(ch->cmd_ram))
> +		return PTR_ERR(ch->cmd_ram);
> +
> +	/* It is 2 bytes/command, hence divide by 2 */
> +	ch->max_cmds = resource_size(res) / 2;
> +
> +	/* Initialise the command pattern RAM */
> +	for (i = 0, ptr = ch->cmd_ram; i < resource_size(res); i += 4)
> +		iowrite32((PTN_CMD_DONTCARE << 24) | (PTN_CMD_DONTCARE << 8),
> +			  ptr++);
> +
> +	ch->fifo_blk_words = fifo_blk_words;
> +	ch->started = 0;
> +
> +	/* Register the channel methods */
> +	ch->chan.start = esnf_start;
> +	ch->chan.stop = esnf_stop;
> +	ch->chan.set_pattern = esnf_set_pattern;
> +	ch->chan.num_recs_avail = esnf_num_recs_avail;
> +	ch->chan.max_ptn_entries = esnf_max_ptn_entries;
> +	ch->chan.max_match_bytes = esnf_max_match_bytes;
> +
> +	strncpy(ch->name, tx ? "TX" : "RX", MAX_CHAN_NAME_SIZE - 1);
> +
> +	dev_dbg(ch->dev, "%s channel initialized\n", ch->name);
> +
> +	return 0;
> +}
> +
> +/* Registers the channel with the sniffer core module */
> +int channel_register(struct ether_snf_chan *ch, const char *name)
> +{
> +	int id;
> +
> +	id = snf_channel_add(&ch->chan, name);
> +	if (id < 0)
> +		return id;
> +
> +	ch->id = id;
> +	dev_info(ch->dev, "%s channel added\n", ch->name);
> +	return 0;
> +}
> +
> +/* Unregisters the channel */
> +int channel_unregister(struct ether_snf_chan *ch)
> +{
> +	int ret;
> +
> +	ch->chan.stop(&ch->chan);
> +	ret = snf_channel_remove(ch->id);
> +	if (!ret)
> +		dev_info(ch->dev, "%s channel removed\n", ch->name);
> +	return ret;
> +}
> +
> +/* Process match event data */
> +void channel_data_available(struct ether_snf_chan *ch)
> +{
> +	int ret;
> +
> +	dev_dbg(ch->dev, "%s match event\n", ch->name);
> +
> +	read_fifo_data(ch);
> +	ret = snf_channel_notify_match(&ch->chan, &ch->evt);
> +	if (ret < 0)
> +		dev_err(ch->dev, "%s: event notification failed\n", ch->name);
> +}
> +
> +/* Channel methods */
> +
> +/* Enables the channel */
> +static int esnf_start(struct snf_chan *dev)
> +{
> +	struct ether_snf_chan *ch = to_ether_snf_chan(dev);
> +
> +	if (!ch->started) {
> +		/* Enable interrupts */
> +		iowrite32(ch->data_irq_bit | ch->full_irq_bit,
> +			  ch->regs + SET_INTERRUPT_ENABLE);
> +		/* Enable the packet matching logic */
> +		iowrite32(ENABLE_BIT, ch->reg_enable);
> +
> +		ch->started = 1;
> +		dev_info(ch->dev, "%s channel started\n", ch->name);
> +	} else {
> +		dev_dbg(ch->dev, "%s channel already running\n", ch->name);
> +	}
> +
> +	return 0;
> +}
> +
> +/* Disables the channel */
> +static int esnf_stop(struct snf_chan *dev)
> +{
> +	struct ether_snf_chan *ch = to_ether_snf_chan(dev);
> +
> +	if (ch->started) {
> +		/* Disable interrupts */
> +		iowrite32(ch->data_irq_bit | ch->full_irq_bit,
> +			  ch->regs + CLEAR_INTERRUPT_ENABLE);
> +		/* Stop the sniffer channel */
> +		iowrite32(0, ch->reg_enable);
> +		/* Clear any pending interrupts */
> +		iowrite32(ch->data_irq_bit | ch->full_irq_bit,
> +			  ch->regs + INTERRUPT_STATUS);
> +
> +		ch->started = 0;
> +		dev_info(ch->dev, "%s channel stopped\n", ch->name);
> +	} else {
> +		dev_dbg(ch->dev, "%s channel already stopped\n", ch->name);
> +	}
> +
> +	return 0;
> +}
> +
> +/* Sets the command string (pattern) for the channel
> + * The bytes in the pattern buffer are in the following order:
> + */
> +static int esnf_set_pattern(struct snf_chan *dev, const u8 *pattern, int count)
> +{
> +	struct ether_snf_chan *ch = to_ether_snf_chan(dev);
> +	int i, shift = 0;
> +	u32  val = 0, *ptr;
> +
> +	if (ch->started) {
> +		dev_err(ch->dev,
> +			"cannot apply cmd pattern. %s channel is active\n",
> +			ch->name);
> +		return -EBUSY;
> +	}
> +
> +	if (!validate_pattern(ch, pattern, count)) {
> +		dev_err(ch->dev,
> +			"invalid cmd pattern for %s channel\n",
> +			ch->name);
> +		return -EINVAL;
> +	}
> +
> +	for (ptr = ch->cmd_ram, i = 0, shift = 24; i < (2*count); i++) {
> +		val |= ((u32)pattern[i]) << shift;
> +		if (!shift) {
> +			iowrite32(val, ptr++);
> +			val = 0;
> +			shift = 24;
> +		} else {
> +			shift -= 8;
> +		}
> +	}
> +	if (shift)
> +		iowrite32(val, ptr);
> +
> +	return 0;
> +}
> +
> +/* Returns the number of pending match events that are
> + * available to retrieve
> + */
> +static int esnf_num_recs_avail(struct snf_chan *dev)
> +{
> +	struct ether_snf_chan *ch = to_ether_snf_chan(dev);
> +
> +	return ioread32(ch->reg_occ);
> +}
> +
> +/* Returns max number of commands supported by the channel */
> +static int esnf_max_ptn_entries(struct snf_chan *dev)
> +{
> +	struct ether_snf_chan *ch = to_ether_snf_chan(dev);
> +
> +	return ch->max_cmds;
> +}
> +
> +/* Returns max number of bytes that can be returned by a match */
> +static int esnf_max_match_bytes(struct snf_chan *dev)
> +{
> +	struct ether_snf_chan *ch = to_ether_snf_chan(dev);
> +
> +	/* Subtract the word that may be used for the timestamp */
> +	return (ch->fifo_blk_words - 1) * 4;
> +}
> +
> +/* Checks if the supplied command string is compatible with the
> + * capabilities of the H/W
> + */
> +static int validate_pattern(struct ether_snf_chan *ch, const u8 *buf, int count)
> +{
> +	int i, complete, max_copy_bytes;
> +	int ts = 0;
> +	int copy_before = 0;
> +	int copy_after = 0;
> +
> +	if (count > ch->max_cmds)
> +		return 0;
> +
> +	/* Iterate through the commands in the string */
> +	for (i = 0, complete = 0; (i < count) && !complete; i++) {
> +		u8 cmd = buf[2*i];
> +
> +		switch (cmd) {
> +		case PTN_CMD_DONTCARE:
> +		case PTN_CMD_MATCH:
> +			break;
> +
> +		case PTN_CMD_MATCHSTAMP:
> +			/* The timestamp needs to be word-aligned in the FIFO
> +			 * therefore, the number of 'copy' commands before it
> +			 * needs to be a multiple of 4
> +			 */
> +			if (copy_before & 3)
> +				return 0;
> +			/* Signal that a timestamp will be present */
> +			ts = 1;
> +			break;
> +
> +		case PTN_CMD_COPY:
> +			/* Increment count of bytes that will be returned */
> +			if (ts)
> +				copy_after++;
> +			else
> +				copy_before++;
> +			break;
> +
> +		case PTN_CMD_COPYDONE:
> +			/* Increment count of bytes that will be returned
> +			 * This command terminates the string
> +			 */
> +			if (ts)
> +				copy_after++;
> +			else
> +				copy_before++;
> +			complete = 1;
> +			break;
> +
> +		default:
> +			return 0;
> +		}
> +	}
> +
> +	/* Check if the string was properly terminated
> +	 * and contained valid number of commands
> +	 */
> +	if (complete) {
> +		max_copy_bytes = ch->fifo_blk_words * 4;
> +		if (ts)
> +			max_copy_bytes -= 4;
> +		if ((copy_before + copy_after) > max_copy_bytes)
> +			return 0;
> +		ch->ts_present = ts;
> +		ch->nfb_before = copy_before;
> +		ch->nfb_after = copy_after;
> +		return 1;
> +	} else {
> +		return 0;
> +	}
> +}
> +
> +/* Read a block from the data FIFO */
> +static void read_fifo_data(struct ether_snf_chan *ch)
> +{
> +	int i;
> +	u32 val, *ptr;
> +	int ts = ch->ts_present;
> +	int dw = ch->fifo_blk_words;
> +	int bytes_before = ch->nfb_before;
> +	int bytes_after = ch->nfb_after;
> +
> +	ptr = (u32 *)ch->evt.data;
> +	for (i = 0; i < dw; i++) {
> +		val = ioread32(ch->reg_fifo);
> +		if (bytes_before > 0) {
> +			/* Bytes before the timestamp */
> +			*ptr++ = cpu_to_be32(val);
> +			bytes_before -= 4;
> +		} else if (ts) {
> +			/* Timestamp is Gray encoded */
> +			ch->evt.ts = (u64)gray_decode(val);
> +			ts = 0;
> +		} else if (bytes_after > 0) {
> +			/* Bytes after the timestamp */
> +			*ptr++ = cpu_to_be32(val);
> +			bytes_after -= 4;
> +		}
> +	}
> +
> +	ch->evt.ts_valid = ch->ts_present;
> +	ch->evt.len = ch->nfb_before + ch->nfb_after;
> +}
> +
> +/* Gray decoder */
> +static u32 gray_decode(u32 gray)
> +{
> +	gray ^= (gray >> 16);
> +	gray ^= (gray >> 8);
> +	gray ^= (gray >> 4);
> +	gray ^= (gray >> 2);
> +	gray ^= (gray >> 1);
> +	return gray;
> +}
> +
> diff --git a/drivers/net/pkt-sniffer/backends/ether/channel.h b/drivers/net/pkt-sniffer/backends/ether/channel.h
> new file mode 100644
> index 0000000..4f00b33
> --- /dev/null
> +++ b/drivers/net/pkt-sniffer/backends/ether/channel.h
> @@ -0,0 +1,76 @@
> +/*
> + * Ethernet Mii packet sniffer driver
> + *  - channel interface
> + *
> + * Copyright (C) 2015 Linn Products Ltd
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2
> + * 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.
> + *
> + * Written by:
> + * Stathis Voukelatos <stathis.voukelatos-zgcZaY4qg+21Qrn1Bg8BZw@public.gmane.org>
> + */
> +#ifndef _ETHER_SNIFFER_CHANNEL_H_
> +#define _ETHER_SNIFFER_CHANNEL_H_
> +
> +#include <linux/platform_device.h>
> +#include "../../core/snf_core.h"
> +
> +#define MAX_CHAN_NAME_SIZE 5
> +
> +struct ether_snf_chan {
> +	/* Sniffer core structure */
> +	struct snf_chan chan;
> +	/* Pointer to device struct */
> +	struct device *dev;
> +	/* Registers */
> +	u8 __iomem *regs;
> +	/* Command string memory */
> +	u32 __iomem *cmd_ram;
> +	/* Bit number for the data IRQ */
> +	int data_irq_bit;
> +	/* Bit number for the FIFO full IRQ */
> +	int full_irq_bit;
> +	/* Channel enable register */
> +	u8 __iomem *reg_enable;
> +	/* Data FIFO register */
> +	u8 __iomem *reg_fifo;
> +	/* FIFO occupancy register */
> +	u8 __iomem *reg_occ;
> +	/* Max number of commands in the string */
> +	int max_cmds;
> +	/* Max matching bytes that can fit in a FIFO block */
> +	int fifo_blk_words;
> +	/* Number of bytes in the FIFO before the timestamp */
> +	int nfb_before;
> +	/* Number of bytes in the FIFO after the timestamp */
> +	int nfb_after;
> +	/* Timestamp present flag */
> +	int ts_present;
> +	/* ID assigned to channel by the sniffer core */
> +	int id;
> +	/* Channel active flag */
> +	int started;
> +	/* Channel name (only used by debug messages) */
> +	char name[MAX_CHAN_NAME_SIZE];
> +	/* Struct to hold data from a packet match */
> +	struct snf_match_evt evt;
> +};
> +
> +int channel_init(
> +		struct ether_snf_chan *ch,
> +		struct platform_device *pdev,
> +		void *regs,
> +		int fifo_blk_words,
> +		int tx);
> +int channel_register(struct ether_snf_chan *ch, const char *name);
> +int channel_unregister(struct ether_snf_chan *ch);
> +void channel_data_available(struct ether_snf_chan *ch);
> +
> +#endif
> diff --git a/drivers/net/pkt-sniffer/backends/ether/hw.h b/drivers/net/pkt-sniffer/backends/ether/hw.h
> new file mode 100644
> index 0000000..edb1093
> --- /dev/null
> +++ b/drivers/net/pkt-sniffer/backends/ether/hw.h
> @@ -0,0 +1,46 @@
> +/*
> + * Ethernet Mii packet sniffer driver
> + *  - register map
> + *
> + * Copyright (C) 2015 Linn Products Ltd
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2
> + * 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.
> + *
> + * Written by:
> + * Stathis Voukelatos <stathis.voukelatos-zgcZaY4qg+21Qrn1Bg8BZw@public.gmane.org>
> + */
> +#ifndef _ETHER_SNIFFER_HW_H_
> +#define _ETHER_SNIFFER_HW_H_
> +
> +#include <linux/bitops.h>
> +
> +/* Registers */
> +#define INTERRUPT_ENABLE        0x00
> +#define SET_INTERRUPT_ENABLE    0x04
> +#define CLEAR_INTERRUPT_ENABLE  0x08
> +#define INTERRUPT_STATUS        0x0c
> +#define TX_FIFO_DAT             0x10
> +#define RX_FIFO_DAT             0x14
> +#define TX_FIFO_OCC             0x18
> +#define RX_FIFO_OCC             0x1c
> +#define TX_SNIFFER_ENABLE       0x20
> +#define RX_SNIFFER_ENABLE       0x24
> +
> +/* IRQ register bits */
> +#define TX_DATA_IRQ_BIT         BIT(0)
> +#define RX_DATA_IRQ_BIT         BIT(1)
> +#define TX_FULL_IRQ_BIT         BIT(2)
> +#define RX_FULL_IRQ_BIT         BIT(3)
> +
> +/* Enable register bits */
> +#define ENABLE_BIT              BIT(0)
> +
> +#endif
> +
> diff --git a/drivers/net/pkt-sniffer/backends/ether/platform.c b/drivers/net/pkt-sniffer/backends/ether/platform.c
> new file mode 100644
> index 0000000..78e7e1c
> --- /dev/null
> +++ b/drivers/net/pkt-sniffer/backends/ether/platform.c
> @@ -0,0 +1,231 @@
> +/*
> + * Ethernet Mii packet sniffer driver
> + *
> + * Copyright (C) 2015 Linn Products Ltd
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2
> + * 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.
> + *
> + * Written by:
> + * Stathis Voukelatos <stathis.voukelatos-zgcZaY4qg+21Qrn1Bg8BZw@public.gmane.org>
> + */
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/interrupt.h>
> +#include <linux/of_device.h>
> +#include <linux/platform_device.h>
> +#include <linux/clk.h>
> +#include "../../core/snf_core.h"
> +#include "hw.h"
> +#include "channel.h"
> +
> +static const char esnf_driver_name[] = "eth-sniffer";
> +
> +/* Names for the TX and RX channel.
> + * User space will used these names to access the channels
> + * through the generic netlink interface
> + */
> +static const char tx_channel_name[] = "snf_ether_tx";
> +static const char rx_channel_name[] = "snf_ether_rx";
> +
> +struct ether_snf {
> +	u8 __iomem *regs;
> +	int irq;
> +	struct clk *sys_clk;
> +	struct ether_snf_chan txc;
> +	struct ether_snf_chan rxc;
> +};
> +
> +/* Interrupt thread function */
> +static irqreturn_t esnf_irq_thread(int irq, void *dev_id)
> +{
> +	struct platform_device *pdev = (struct platform_device *)dev_id;
> +	struct ether_snf *esnf = (struct ether_snf *)platform_get_drvdata(pdev);
> +	u32 irq_status;
> +
> +	if (unlikely(esnf->irq != irq))
> +		return IRQ_NONE;
> +
> +	irq_status = ioread32(esnf->regs + INTERRUPT_STATUS) &
> +				 ioread32(esnf->regs + INTERRUPT_ENABLE);
> +
> +	dev_dbg(&pdev->dev, "irq: 0x%08x\n", irq_status);
> +
> +	/* TX FIFO full */
> +	if (unlikely(irq_status & TX_FULL_IRQ_BIT))
> +		dev_notice(&pdev->dev, "TX FIFO full");
> +
> +	/* RX FIFO full */
> +	if (unlikely(irq_status & RX_FULL_IRQ_BIT))
> +		dev_notice(&pdev->dev, "RX FIFO full");
> +
> +	/* TX match data available */
> +	if (irq_status & TX_DATA_IRQ_BIT) {
> +		dev_dbg(&pdev->dev, "TX data");
> +		channel_data_available(&esnf->txc);
> +	}
> +
> +	/* RX match data available */
> +	if (irq_status & RX_DATA_IRQ_BIT) {
> +		dev_dbg(&pdev->dev, "RX data");
> +		channel_data_available(&esnf->rxc);
> +	}
> +
> +	/* Clear interrupts */
> +	iowrite32(irq_status, esnf->regs + INTERRUPT_STATUS);
> +
> +	return IRQ_HANDLED;
> +}
> +
> +/* Called when the packet sniffer device is bound with the driver */
> +static int esnf_driver_probe(struct platform_device *pdev)
> +{
> +	struct ether_snf *esnf;
> +	struct resource *res;
> +	int ret, irq;
> +	u32 fifo_blk_words;
> +	void __iomem *regs;
> +	struct device_node *ofn = pdev->dev.of_node;
> +
> +	/* Allocate the device data structure */
> +	esnf = devm_kzalloc(&pdev->dev, sizeof(*esnf), GFP_KERNEL);
> +	if (!esnf)
> +		return -ENOMEM;
> +
> +	/* Retrieve and remap register memory space */
> +	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
> +	if (!res)
> +		return -ENODEV;
> +
> +	regs = devm_ioremap_resource(&pdev->dev, res);
> +	if (IS_ERR(regs))
> +		return PTR_ERR(regs);
> +
> +	esnf->regs = regs;
> +
> +	/* Read the FIFO block size from the DT */
> +	if (!ofn)
> +		return -ENODEV;
> +
> +	ret = of_property_read_u32(
> +				ofn,
> +				"fifo-block-words",
> +				&fifo_blk_words);
> +	if (ret < 0)
> +		return ret;
> +
> +	if (((fifo_blk_words - 1)*4) > MAX_MATCH_BYTES) {
> +		dev_err(&pdev->dev,
> +			"Invalid FIFO block size entry in device tree\n");
> +		return -EINVAL;
> +	}
> +
> +	esnf->sys_clk = devm_clk_get(&pdev->dev, "sys");
> +	if (IS_ERR(esnf->sys_clk)) {
> +		ret = PTR_ERR(esnf->sys_clk);
> +		return ret;
> +	}
> +	ret = clk_prepare_enable(esnf->sys_clk);
> +	if (ret < 0)
> +		return ret;
> +
> +	/* Initialise the TX and RX channels */
> +	ret = channel_init(&esnf->txc, pdev, regs, fifo_blk_words, 1);
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "Failed to init TX channel (%d)\n", ret);
> +		goto fail1;
> +	}
> +	ret = channel_init(&esnf->rxc, pdev, regs, fifo_blk_words, 0);
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "Failed to init RX channel (%d)\n", ret);
> +		goto fail1;
> +	}
> +
> +	/* Register the channels with the sniffer core module */
> +	ret = channel_register(&esnf->txc, tx_channel_name);
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "Failed to register TX chan (%d)\n", ret);
> +		goto fail1;
> +	}
> +	ret = channel_register(&esnf->rxc, rx_channel_name);
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "Failed to register RX chan (%d)\n", ret);
> +		goto fail2;
> +	}
> +
> +	platform_set_drvdata(pdev, esnf);
> +
> +	/* Register the interrupt handler */
> +	irq = platform_get_irq(pdev, 0);
> +	if (irq < 0)
> +		goto fail3;
> +	esnf->irq = irq;
> +	ret = devm_request_threaded_irq(
> +				&pdev->dev,
> +				irq,
> +				NULL,
> +				esnf_irq_thread,
> +				IRQF_ONESHOT,
> +				esnf_driver_name,
> +				pdev);
> +	if (ret < 0)
> +		goto fail3;
> +
> +	return 0;
> +
> +fail3:
> +	channel_unregister(&esnf->rxc);
> +fail2:
> +	channel_unregister(&esnf->txc);
> +fail1:
> +	clk_disable_unprepare(esnf->sys_clk);
> +	return ret;
> +}
> +
> +/* Called when the packet sniffer device unregisters with the driver */
> +static int esnf_driver_remove(struct platform_device *pdev)
> +{
> +	struct ether_snf *esnf = (struct ether_snf *)platform_get_drvdata(pdev);
> +	int ret;
> +
> +	ret = channel_unregister(&esnf->txc);
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "Failed to unregister TX chan (%d)\n", ret);
> +		return ret;
> +	}
> +	ret = channel_unregister(&esnf->rxc);
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "Failed to unregister RX chan (%d)\n", ret);
> +		return ret;
> +	}
> +	clk_disable_unprepare(esnf->sys_clk);
> +	return 0;
> +}
> +
> +static const struct of_device_id esnf_of_match_table[] = {
> +	{ .compatible = "linn,eth-sniffer", .data = NULL },
> +	{},
> +};
> +MODULE_DEVICE_TABLE(of, esnf_of_match_table);
> +
> +static struct platform_driver esnf_platform_driver = {
> +	.driver = {
> +		.name = esnf_driver_name,
> +		.of_match_table = esnf_of_match_table,
> +	},
> +	.probe = esnf_driver_probe,
> +	.remove = esnf_driver_remove,
> +};
> +
> +module_platform_driver(esnf_platform_driver);
> +
> +MODULE_DESCRIPTION("Linn Ethernet Packet Sniffer");
> +MODULE_AUTHOR("Linn Products Ltd");
> +MODULE_LICENSE("GPL v2");
> +
> diff --git a/drivers/net/pkt-sniffer/core/dev_table.c b/drivers/net/pkt-sniffer/core/dev_table.c
> new file mode 100644
> index 0000000..3a07838
> --- /dev/null
> +++ b/drivers/net/pkt-sniffer/core/dev_table.c
> @@ -0,0 +1,124 @@
> +/*
> + * Packet sniffer core driver: channel management
> + *
> + * Copyright (C) 2014 Linn Products Ltd
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2
> + * 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.
> + *
> + * Written by:
> + * Stathis Voukelatos <stathis.voukelatos-zgcZaY4qg+21Qrn1Bg8BZw@public.gmane.org>
> + */
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include "snf_core.h"
> +#include "nl.h"
> +
> +#define MAX_CHANNELS   256
> +
> +static DEFINE_MUTEX(tlock);
> +
> +static struct snf_chan *dev_tab[MAX_CHANNELS];
> +static unsigned int ref_count[MAX_CHANNELS];
> +
> +static inline int verify_args(int id)
> +{
> +	return (id < MAX_CHANNELS);
> +}
> +
> +/* Registers a sniffer channel and returns and id for it */
> +int snf_channel_add(struct snf_chan *dev, const char *name)
> +{
> +	int i;
> +	int ret = -EEXIST;
> +
> +	mutex_lock(&tlock);
> +
> +	for (i = 0; i < MAX_CHANNELS; i++) {
> +		if (!dev_tab[i]) {
> +			/* Initialise the netlink interface for the channel */
> +			ret = snf_netlink_init(i, dev, name);
> +			if (ret < 0)
> +				goto fail;
> +
> +			dev_tab[i] = dev;
> +			ref_count[i] = 0;
> +			mutex_unlock(&tlock);
> +			return i;
> +		}
> +	}
> +
> +fail:
> +	mutex_unlock(&tlock);
> +	return ret;
> +}
> +EXPORT_SYMBOL(snf_channel_add);
> +
> +/* Removes a sniffer channel */
> +int snf_channel_remove(int id)
> +{
> +	int ret = 0;
> +	struct snf_chan *dev;
> +
> +	if (!verify_args(id))
> +		return -EINVAL;
> +
> +	mutex_lock(&tlock);
> +
> +	dev = dev_tab[id];
> +
> +	if (!dev) {
> +		ret = -ENODEV;
> +		goto fail;
> +	}
> +
> +	if (ref_count[id] > 0) {
> +		ret = -EBUSY;
> +		goto fail;
> +	}
> +
> +	dev_tab[id] = NULL;
> +
> +	/* Release netlink API resources */
> +	snf_netlink_release(dev);
> +
> +fail:
> +	mutex_unlock(&tlock);
> +	return ret;
> +}
> +EXPORT_SYMBOL(snf_channel_remove);
> +
> +/* Returns a pointer to the specified sniffer channel
> + * and increments its reference counter
> + */
> +struct snf_chan *snf_channel_get(int id)
> +{
> +	struct snf_chan *dev;
> +
> +	if (!verify_args(id))
> +		return NULL;
> +
> +	mutex_lock(&tlock);
> +	dev = dev_tab[id];
> +	if (dev)
> +		ref_count[id]++;
> +	mutex_unlock(&tlock);
> +
> +	return dev;
> +}
> +
> +/* Decrements the reference counter for the channel */
> +void snf_channel_put(int id)
> +{
> +	mutex_lock(&tlock);
> +	if (ref_count[id] > 0)
> +		ref_count[id]--;
> +	mutex_unlock(&tlock);
> +}
> +
> diff --git a/drivers/net/pkt-sniffer/core/module.c b/drivers/net/pkt-sniffer/core/module.c
> new file mode 100644
> index 0000000..af6a1aa
> --- /dev/null
> +++ b/drivers/net/pkt-sniffer/core/module.c
> @@ -0,0 +1,37 @@
> +/*
> + * Packet sniffer core driver:
> + *  - backend channel management
> + *  - interface to userland via generic netlink
> + *
> + * Copyright (C) 2015 Linn Products Ltd
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2
> + * 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.
> + *
> + * Written by:
> + * Stathis Voukelatos <stathis.voukelatos-zgcZaY4qg+21Qrn1Bg8BZw@public.gmane.org>
> + */
> +#include <linux/module.h>
> +#include <linux/init.h>
> +
> +static int __init snf_core_init(void)
> +{
> +	return 0;
> +}
> +
> +static void __exit snf_core_cleanup(void)
> +{
> +}
> +
> +module_init(snf_core_init);
> +module_exit(snf_core_cleanup);
> +
> +MODULE_LICENSE("GPL v2");
> +MODULE_DESCRIPTION("Core packet sniffer driver");
> +MODULE_AUTHOR("Linn Products Ltd");
> diff --git a/drivers/net/pkt-sniffer/core/nl.c b/drivers/net/pkt-sniffer/core/nl.c
> new file mode 100644
> index 0000000..6839147
> --- /dev/null
> +++ b/drivers/net/pkt-sniffer/core/nl.c
> @@ -0,0 +1,427 @@
> +/*
> + * Packet sniffer core driver: generic netlink interface
> + *
> + * Copyright (C) 2015 Linn Products Ltd
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2
> + * 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.
> + *
> + * Written by:
> + * Stathis Voukelatos <stathis.voukelatos-zgcZaY4qg+21Qrn1Bg8BZw@public.gmane.org>
> + */
> +#include <linux/version.h>
> +#include <net/netlink.h>
> +#include <net/genetlink.h>
> +#include <linux/slab.h>
> +#include <linux/module.h>
> +#include <linux/pkt_sniffer.h>
> +#include "snf_core.h"
> +#include "nl.h"
> +
> +/* Netlink API data for a sniffer channel */
> +struct snf_netlink {
> +	/* genl family */
> +	struct genl_family           fml;
> +	/* genl operations */
> +	struct genl_ops             *ops;
> +	/* genl mcast group, where sniffer match
> +	 * events will be sent
> +	 */
> +	struct genl_multicast_group  grp;
> +};
> +
> +/* Attribute policies */
> +static struct nla_policy snf_policy[SNF_ATTR_MAX + 1] = {
> +	[SNF_ATTR_PATTERN] = { .type = NLA_NESTED },
> +};
> +
> +static struct nla_policy snf_ptn_policy[SNF_ATTR_PTN_MAX + 1] = {
> +	[SNF_ATTR_PTN_ENTRY] = { .type = NLA_U16 },
> +};
> +
> +/* Generic Netlink family template definition */
> +static int pre_doit_func(const struct genl_ops *ops,
> +			 struct sk_buff *skb,
> +			 struct genl_info *info);
> +
> +static void post_doit_func(const struct genl_ops *ops,
> +			   struct sk_buff *skb,
> +			   struct genl_info *info);
> +
> +static struct genl_family snf_family_tmpl = {
> +	.id = GENL_ID_GENERATE,
> +	.hdrsize = 0,
> +	.version = SNF_GNL_VERSION,
> +	.maxattr = SNF_ATTR_MAX,
> +	.pre_doit = pre_doit_func,
> +	.post_doit = post_doit_func
> +};
> +
> +static int send_reply_uint32(
> +			struct genl_info *info,
> +			int cmd,
> +			int attr,
> +			u32 val);
> +
> +/* Generic Netlink operations template definition */
> +
> +static int do_it_start(struct sk_buff *skb, struct genl_info *info);
> +static int do_it_stop(struct sk_buff *skb, struct genl_info *info);
> +static int do_it_set_pattern(struct sk_buff *skb, struct genl_info *info);
> +static int do_it_num_rec_avail(struct sk_buff *skb, struct genl_info *info);
> +static int do_it_ptn_max_cmds(struct sk_buff *skb, struct genl_info *info);
> +static int do_it_max_match_bytes(struct sk_buff *skb, struct genl_info *info);
> +
> +#define SNF_GENL_OP(_cmd, _func)	 \
> +	{				 \
> +		.cmd	= _cmd,          \
> +		.policy = snf_policy,    \
> +		.doit   = _func,         \
> +		.dumpit = NULL,          \
> +		.flags  = 0,             \
> +		.internal_flags = 0      \
> +	}
> +
> +#define SNF_CHAN_OPS							   \
> +	{								   \
> +		SNF_GENL_OP(SNF_CMD_START,         do_it_start),	   \
> +		SNF_GENL_OP(SNF_CMD_STOP,          do_it_stop),		   \
> +		SNF_GENL_OP(SNF_CMD_SETPATTERN,    do_it_set_pattern),     \
> +		SNF_GENL_OP(SNF_CMD_NUMRECAVAIL,   do_it_num_rec_avail),   \
> +		SNF_GENL_OP(SNF_CMD_PTNMAXCMDS,    do_it_ptn_max_cmds),    \
> +		SNF_GENL_OP(SNF_CMD_MAXMATCHBYTES, do_it_max_match_bytes)  \
> +	}
> +
> +static struct genl_ops snf_ops_tmpl[] = SNF_CHAN_OPS;
> +
> +#define NUM_GENL_OPS ARRAY_SIZE(snf_ops_tmpl)
> +
> +/* Multicast a netlink event containing data from a sniffer match event.
> + * Data are included in the netlink message as a nested attribute
> + * containing the timestamp (optional) and matching packet bytes
> +*/
> +int snf_channel_notify_match(struct snf_chan *dev, struct snf_match_evt *mt)
> +{
> +	int i, ret = 0;
> +	struct sk_buff *msg = NULL;
> +	void *msg_hdr, *nest_hdr;
> +	struct snf_netlink *nl = (struct snf_netlink *)dev->cstate;
> +
> +	if (!nl) {
> +		ret = -EINVAL;
> +		goto fail;
> +	}
> +
> +	msg = genlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
> +	if (!msg) {
> +		ret = -ENOMEM;
> +		goto fail;
> +	}
> +
> +	msg_hdr = genlmsg_put(msg,
> +			      0,
> +			      0,
> +			      &nl->fml,
> +			      0,
> +			      SNF_CMD_MATCHEVENT);
> +	if (!msg_hdr) {
> +		ret = -EMSGSIZE;
> +		goto fail;
> +	}
> +
> +	/* Add the nested attribute with the data */
> +	if ((mt->ts_valid) || (mt->len > 0)) {
> +		nest_hdr = nla_nest_start(msg, SNF_ATTR_MATCHEVENT);
> +		if (!nest_hdr) {
> +			ret = -EMSGSIZE;
> +			goto fail;
> +		}
> +		if (mt->ts_valid) {
> +			ret = nla_put_u64(msg, SNF_ATTR_MATCH_TS, mt->ts);
> +			if (ret < 0)
> +				goto fail;
> +		}
> +		for (i = 0; i < mt->len; i++) {
> +			ret = nla_put_u8(msg,
> +					 SNF_ATTR_MATCH_PKTBYTE,
> +					 mt->data[i]);
> +			if (ret < 0)
> +				goto fail;
> +		}
> +		nla_nest_end(msg, nest_hdr);
> +	}
> +
> +	ret = genlmsg_end(msg, msg_hdr);
> +	if (ret < 0)
> +		goto fail;
> +	ret = genlmsg_multicast(&nl->fml, msg, 0, 0, GFP_ATOMIC);
> +
> +	/* The ESRCH code is returned when there is no socket listening on the
> +	 * multicast group, so we do not really treat is as an error
> +	 */
> +	if (ret == -ESRCH)
> +		ret = 0;
> +	return ret;
> +
> +fail:
> +	if (msg)
> +		nlmsg_free(msg);
> +	return ret;
> +}
> +EXPORT_SYMBOL(snf_channel_notify_match);
> +
> +/* Initialise the generic netlink API for a sniffer channel
> + * Registers family, ops and multicast group for events
> + */
> +int snf_netlink_init(int id, struct snf_chan *dev, const char *name)
> +{
> +	int i, ret;
> +	struct snf_netlink *nl = NULL;
> +
> +	nl = kmalloc(sizeof(*nl), GFP_KERNEL);
> +	if (!nl) {
> +		ret = -ENOMEM;
> +		goto fail1;
> +	}
> +
> +	nl->fml = snf_family_tmpl;
> +
> +	/* Set the family name */
> +	strncpy(nl->fml.name, name, GENL_NAMSIZ-1);
> +
> +	/* Allocate ops array and copy template data */
> +	nl->ops = kmalloc(sizeof(snf_ops_tmpl), GFP_KERNEL);
> +	if (!nl->ops) {
> +		ret = -ENOMEM;
> +		goto fail2;
> +	}
> +	memcpy(nl->ops, snf_ops_tmpl, sizeof(snf_ops_tmpl));
> +
> +	/* In the internal_flags field we store the id
> +	 * of the device the ops belong to
> +	 */
> +	for (i = 0; i < NUM_GENL_OPS; i++)
> +		nl->ops[i].internal_flags = id;
> +
> +	snprintf(nl->grp.name, GENL_NAMSIZ-1, SNF_EVENT_GRP);
> +
> +	ret = _genl_register_family_with_ops_grps(
> +						&nl->fml,
> +						nl->ops,
> +						NUM_GENL_OPS,
> +						&nl->grp,
> +						1);
> +	if (ret < 0) {
> +		pr_err("%s: failed to register family %s (%d)\n",
> +		       KBUILD_MODNAME, name, ret);
> +		goto fail3;
> +	}
> +
> +	pr_info("%s: registered genl family for channel %d: %s\n",
> +		KBUILD_MODNAME, id, name);
> +	dev->cstate = nl;
> +
> +	return 0;
> +
> +fail3:
> +	kfree(nl->ops);
> +fail2:
> +	kfree(nl);
> +fail1:
> +	return ret;
> +}
> +
> +/* Shuts down the netlink API for a sniffer channel
> + * and frees resources
> + */
> +void snf_netlink_release(struct snf_chan *dev)
> +{
> +	struct snf_netlink *nl = (struct snf_netlink *)dev->cstate;
> +	/* Unregister family and free ops
> +	 * NOTE: this will also unregister the ops and the mcast group
> +	 */
> +	genl_unregister_family(&nl->fml);
> +	pr_info("%s: unregistered genl family: %s\n",
> +		KBUILD_MODNAME, nl->fml.name);
> +
> +	kfree(nl->ops);
> +	kfree(nl);
> +	dev->cstate = NULL;
> +}
> +
> +/* pre_doit function that retrieves a pointer to the sniffer channel device
> + * from the instance and channel number stored in the ops internal_flag field
> + */
> +static int pre_doit_func(const struct genl_ops *ops,
> +			 struct sk_buff *skb,
> +			 struct genl_info *info)
> +{
> +	info->user_ptr[0] = snf_channel_get(ops->internal_flags);
> +	return info->user_ptr[0] ? 0 : -ENODEV;
> +}
> +
> +/* post_doit function that releases a sniffer channel device */
> +static void post_doit_func(const struct genl_ops *ops,
> +			   struct sk_buff *skb,
> +			   struct genl_info *info)
> +{
> +	snf_channel_put(ops->internal_flags);
> +}
> +
> +/* doit command handlers */
> +
> +/* Start the sniffer channel */
> +static int do_it_start(struct sk_buff *skb, struct genl_info *info)
> +{
> +	struct snf_chan *dev = (struct snf_chan *)info->user_ptr[0];
> +
> +	return dev->start(dev);
> +}
> +
> +/* Stop the sniffer channel */
> +static int do_it_stop(struct sk_buff *skb, struct genl_info *info)
> +{
> +	int ret;
> +	struct snf_match_evt mt;
> +	struct snf_chan *dev = (struct snf_chan *)info->user_ptr[0];
> +
> +	ret = dev->stop(dev);
> +	if (ret < 0)
> +		return ret;
> +
> +	/* Multicast an empty match event to notify any user-space
> +	 * listeners that the sniffer is stopping
> +	 */
> +	memset(&mt, 0, sizeof(mt));
> +	return snf_channel_notify_match(dev, &mt);
> +}
> +
> +/* Set the command pattern. The string is received in a nested
> + * attribute containing a sequence of 16-bit valued.
> + * Each value consists of a command (8 bits) and data (8 bits)
> +*/
> +static int do_it_set_pattern(struct sk_buff *skb, struct genl_info *info)
> +{
> +	int ret = 0;
> +	int rem, count;
> +	struct nlattr *nla;
> +	u16 entry;
> +	u8 *buf = NULL;
> +	struct snf_chan *dev = (struct snf_chan *)info->user_ptr[0];
> +	int max_entries = dev->max_ptn_entries(dev);
> +
> +	if (!info->attrs[SNF_ATTR_PATTERN]) {
> +		ret = -EINVAL;
> +		goto fail;
> +	}
> +
> +	ret = nla_validate_nested(info->attrs[SNF_ATTR_PATTERN],
> +				  SNF_ATTR_PTN_ENTRY, snf_ptn_policy);
> +	if (ret < 0)
> +		goto fail;
> +
> +	buf = kmalloc(max_entries*2, GFP_KERNEL);
> +	if (!buf) {
> +		ret = -ENOMEM;
> +		goto fail;
> +	}
> +
> +	/* Iterate over the contents of the nested attribute
> +	 * and extract into the buffer
> +	 */
> +	count = 0;
> +	nla_for_each_nested(nla, info->attrs[SNF_ATTR_PATTERN], rem) {
> +		if (count >= max_entries) {
> +			ret = -EINVAL;
> +			goto fail;
> +		}
> +		entry = nla_get_u16(nla);
> +		buf[2*count] = PTNENTRY_CMD(entry);
> +		buf[2*count + 1] = PTNENTRY_DATA(entry);
> +		count++;
> +	}
> +
> +	ret = dev->set_pattern(dev, buf, count);
> +
> +fail:
> +	kfree(buf);
> +	return ret;
> +}
> +
> +/* Number of pending match events */
> +static int do_it_num_rec_avail(struct sk_buff *skb, struct genl_info *info)
> +{
> +	struct snf_chan *dev = (struct snf_chan *)info->user_ptr[0];
> +
> +	return send_reply_uint32(
> +			info,
> +			SNF_CMD_NUMRECAVAIL,
> +			SNF_ATTR_NUMRECAVAIL,
> +			dev->num_recs_avail(dev));
> +}
> +
> +/* Max number of commands that are supported in the command pattern */
> +static int do_it_ptn_max_cmds(struct sk_buff *skb, struct genl_info *info)
> +{
> +	struct snf_chan *dev = (struct snf_chan *)info->user_ptr[0];
> +
> +	return send_reply_uint32(
> +			info,
> +			SNF_CMD_PTNMAXCMDS,
> +			SNF_ATTR_PTNMAXCMDS,
> +			dev->max_ptn_entries(dev));
> +}
> +
> +/* Max bytes that can be returned by a packet match event */
> +static int do_it_max_match_bytes(struct sk_buff *skb, struct genl_info *info)
> +{
> +	struct snf_chan *dev = (struct snf_chan *)info->user_ptr[0];
> +
> +	return send_reply_uint32(
> +			info,
> +			SNF_CMD_MAXMATCHBYTES,
> +			SNF_ATTR_MAXMATCHBYTES,
> +			dev->max_match_bytes(dev));
> +}
> +
> +/* Helper function for sending a reply containing a single u32 attribute */
> +static int send_reply_uint32(struct genl_info *info, int cmd, int attr, u32 val)
> +{
> +	void *hdr;
> +	int ret = 0;
> +	struct sk_buff *msg;
> +	struct snf_chan *dev = (struct snf_chan *)info->user_ptr[0];
> +	struct snf_netlink *nl = (struct snf_netlink *)dev->cstate;
> +
> +	msg = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
> +	if (!msg) {
> +		ret = -ENOMEM;
> +		goto fail;
> +	}
> +
> +	hdr = genlmsg_put_reply(msg, info, &nl->fml, 0, cmd);
> +	if (!hdr) {
> +		ret = -EMSGSIZE;
> +		goto fail;
> +	}
> +	ret = nla_put_u32(msg, attr, val);
> +	if (ret < 0)
> +		goto fail;
> +	ret = genlmsg_end(msg, hdr);
> +	if (ret < 0)
> +		goto fail;
> +
> +	return genlmsg_reply(msg, info);
> +
> +fail:
> +	if (msg)
> +		nlmsg_free(msg);
> +	return ret;
> +}
> +
> diff --git a/drivers/net/pkt-sniffer/core/nl.h b/drivers/net/pkt-sniffer/core/nl.h
> new file mode 100644
> index 0000000..f7bf579
> --- /dev/null
> +++ b/drivers/net/pkt-sniffer/core/nl.h
> @@ -0,0 +1,34 @@
> +/*
> + * Packet sniffer core driver: generic netlink interface
> + *
> + * Copyright (C) 2015 Linn Products Ltd
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2
> + * 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.
> + *
> + * Written by:
> + * Stathis Voukelatos <stathis.voukelatos-zgcZaY4qg+21Qrn1Bg8BZw@public.gmane.org>
> + */
> +#ifndef __SNF_NL_H
> +#define __SNF_NL_H
> +
> +#include <net/genetlink.h>
> +#include "snf_core.h"
> +
> +/* Initialise netlink interface for a sniffer channel,
> + * register netlink families etc.
> + */
> +int snf_netlink_init(int id, struct snf_chan *dev, const char *name);
> +
> +/* Shutdown netlink interface, unregister
> + * families etc.
> + */
> +void snf_netlink_release(struct snf_chan *dev);
> +
> +#endif
> diff --git a/drivers/net/pkt-sniffer/core/snf_core.h b/drivers/net/pkt-sniffer/core/snf_core.h
> new file mode 100644
> index 0000000..062de70
> --- /dev/null
> +++ b/drivers/net/pkt-sniffer/core/snf_core.h
> @@ -0,0 +1,64 @@
> +/*
> + * Packet sniffer core driver
> + * - this header provides the interface to specific backend packet
> + *   sniffer implementations
> + *
> + * Copyright (C) 2015 Linn Products Ltd
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2
> + * 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.
> + *
> + * Written by:
> + * Stathis Voukelatos <stathis.voukelatos-zgcZaY4qg+21Qrn1Bg8BZw@public.gmane.org>
> + */
> +#ifndef __SNF_CORE_H
> +#define __SNF_CORE_H
> +
> +#include <linux/types.h>
> +
> +/* This is a global maximum. Each backend will have its own limit */
> +#define MAX_MATCH_BYTES 512
> +
> +/* Sniffer channel data structure */
> +struct snf_chan {
> +	int  (*start)(struct snf_chan *dev);
> +	int  (*stop)(struct snf_chan *dev);
> +	int  (*set_pattern)(struct snf_chan *dev, const u8 *pattern, int count);
> +	int  (*num_recs_avail)(struct snf_chan *dev);
> +	int  (*max_ptn_entries)(struct snf_chan *dev);
> +	int  (*max_match_bytes)(struct snf_chan *dev);
> +
> +	void *cstate;
> +};
> +
> +/* Data from a sniffer match event */
> +struct snf_match_evt {
> +	int ts_valid;     /* flag indicating if timestamp is present */
> +	u64 ts;           /* timestamp value */
> +	u8 data[MAX_MATCH_BYTES]; /* packet data bytes matched by sniffer */
> +	int len;          /* number of valid bytes in the 'data' buffer */
> +};
> +
> +/* Adds a sniffer channel to the registry */
> +int snf_channel_add(struct snf_chan *dev, const char *name);
> +
> +/* Removes the channel with the specified id from the registry */
> +int snf_channel_remove(int id);
> +
> +/* Returns handle to a channel and increments reference count */
> +struct snf_chan *snf_channel_get(int id);
> +
> +/* Decrements reference count for the specified channel */
> +void snf_channel_put(int id);
> +
> +/* Multicast a notification to user space for a sniffer match event */
> +int snf_channel_notify_match(struct snf_chan *dev, struct snf_match_evt *mt);
> +
> +#endif
> +
> diff --git a/include/linux/pkt_sniffer.h b/include/linux/pkt_sniffer.h
> new file mode 100644
> index 0000000..3e73d14
> --- /dev/null
> +++ b/include/linux/pkt_sniffer.h
> @@ -0,0 +1,89 @@
> +/*
> + * Linn packet sniffer driver interface
> + *
> + * Copyright (C) 2015 Linn Products Ltd
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2
> + * 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.
> + *
> + * Written by:
> + * Stathis Voukelatos <stathis.voukelatos-zgcZaY4qg+21Qrn1Bg8BZw@public.gmane.org>
> + */
> +#ifndef __PKT_SNIFFER_H
> +#define __PKT_SNIFFER_H
> +
> +/* Commands for the pattern string */
> +#define PTN_CMD_DONTCARE    0
> +#define PTN_CMD_MATCH       1
> +#define PTN_CMD_COPY        2
> +#define PTN_CMD_MATCHSTAMP  3
> +#define PTN_CMD_COPYDONE    4
> +
> +/* Creates an entry for the pattern string.
> + * An entry consists of a command byte and a data byte
> +*/
> +#define MAKE_PTN_ENTRY(cmd, data) (((((int)cmd) & 0xff) << 8) | (data & 0xff))
> +/* Gets the cmd and data portion of a pattern string entry */
> +#define PTNENTRY_CMD(val)        (((val) >> 8) & 0xff)
> +#define PTNENTRY_DATA(val)       ((val) & 0xff)
> +
> +/* Generic Netlink commands */
> +enum {
> +	SNF_CMD_UNSPEC,
> +	SNF_CMD_START,          /* start the sniffer */
> +	SNF_CMD_STOP,           /* stop the sniffer */
> +	SNF_CMD_SETPATTERN,     /* set the command pattern */
> +	SNF_CMD_NUMRECAVAIL,    /* number of pending match events */
> +	SNF_CMD_MATCHEVENT,     /* match event notification */
> +	SNF_CMD_PTNMAXCMDS,     /* max number of commands supported */
> +	SNF_CMD_MAXMATCHBYTES,  /* max number of bytes in match event */
> +	__SNF_CMD_MAX
> +};
> +#define SNF_CMD_MAX (__SNF_CMD_MAX - 1)
> +
> +/* Generic Netlink attributes */
> +enum {
> +	SNF_ATTR_UNSPEC,
> +	SNF_ATTR_PTNMAXCMDS,    /* max number of commands supported */
> +	SNF_ATTR_PATTERN,       /* nested attribute containing commands */
> +	SNF_ATTR_NUMRECAVAIL,   /* number of pending match events */
> +	SNF_ATTR_MATCHEVENT,    /* nested attribute for a match event */
> +	SNF_ATTR_MAXMATCHBYTES, /* max bytes in a match event */
> +	__SNF_ATTR_MAX
> +};
> +#define SNF_ATTR_MAX (__SNF_ATTR_MAX - 1)
> +
> +/* Attributes that are included in the nested attribute
> + * for the command string
> + */
> +enum {
> +	SNF_ATTR_PTN_UNSPEC,
> +	SNF_ATTR_PTN_ENTRY,    /* command entry containing a command id */
> +	__SNF_ATTR_PTN_MAX     /* and data byte */
> +};
> +#define SNF_ATTR_PTN_MAX (__SNF_ATTR_PTN_MAX - 1)
> +
> +/* Attributes included in the nested attribute
> + * of a match event notification
> + */
> +enum {
> +	SNF_ATTR_MATCH_UNSPEC,
> +	SNF_ATTR_MATCH_TS,      /* timestamp (returned with a match event) */
> +	SNF_ATTR_MATCH_PKTBYTE, /* packet data (returned with a match event) */
> +	__SNF_ATTR_MATCH_MAX
> +};
> +#define SNF_ATTR_MATCH_MAX (__SNF_ATTR_MATCH_MAX - 1)
> +
> +/* Family version */
> +#define SNF_GNL_VERSION 1
> +
> +/* Multicast group name */
> +#define SNF_EVENT_GRP    "snf_evt_grp"
> +
> +#endif
> 


-- 
Florian
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply

* Re: [PATCH 1/2] rhashtable: Introduce rhashtable_walk_*
From: Herbert Xu @ 2015-01-26 22:23 UTC (permalink / raw)
  To: David Laight
  Cc: Thomas Graf, Ying Xue, davem@davemloft.net, kaber@trash.net,
	paulmck@linux.vnet.ibm.com, netdev@vger.kernel.org,
	netfilter-devel@vger.kernel.org
In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6D1CAD2C12@AcuExch.aculab.com>

On Mon, Jan 26, 2015 at 10:09:24AM +0000, David Laight wrote:
>
> That doesn't look right to me.
> Surely you shouldn't be calling rcu_read_lock() when the mutex
> request is interrupted.
> 
> So maybe:
> 	err = mutex_lock_interruptible(&ht->mutex);
> 	if (err)
> 		return err;
> 	rcu_read_lock();

No, we need to grab the RCU read lock while holding the mutex
in order to prevent future resizes from happening once we release
the mutex.

We don't want to hold the mutex which would stop other walks from
starting.

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply

* Re: [PATCH 1/2] rhashtable: Introduce rhashtable_walk_*
From: Herbert Xu @ 2015-01-26 22:21 UTC (permalink / raw)
  To: Thomas Graf; +Cc: Ying Xue, davem, kaber, paulmck, netdev, netfilter-devel
In-Reply-To: <20150126082000.GA22262@casper.infradead.org>

On Mon, Jan 26, 2015 at 08:20:00AM +0000, Thomas Graf wrote:
> On 01/26/15 at 10:21am, Herbert Xu wrote:
> > +int rhashtable_walk_start(struct rhashtable_iter *iter)
> > +{
> > +	struct rhashtable *ht = iter->ht;
> > +	int err;
> > +
> > +	err = mutex_lock_interruptible(&ht->mutex);
> > +	rcu_read_lock();
> > +
> > +	if (!err)
> > +		mutex_unlock(&ht->mutex);
> > +
> > +	return err;
> > +}
> > +EXPORT_SYMBOL_GPL(rhashtable_walk_start);
> 
> This doesn't seem to work for Netlink dumps as it would define
> a RCU read side section across user read()s.

No it does not.  The start call roughly corresponds to the start
call in seq_file which does not span across reads.

> I assume you relying on RCU to defer the initial table relinking
> in the resizing to be postponed. Wouldn't it be better to hold
> the mutex instead, we could sleep during the dump.

Note that this is not the final solution but just the first step.
So right now it does not prevent/postpone resizes completely.  It's
only meant to be a strict improvement over what we currently have.

So indeed resizes will be stopped within a single read but not
across reads for seq_file.  Similarly for netlink dump resizes
will only be stopped for a single skb.

I will do the rest of what we discussed once I implement rehashing
since there will be dependencies on it.
 
> Same here, we leave the iterator with the bucket lock held.

This is intentional, it is what udp_diag does.  We'll have to do
this if you ever want to convert UDP sockets over to rhashtable
so we might as well do it now.

If you don't hold the bucket lock then anyone that recycles objects
like UDP will end up walking into the ether.

As before this is not held across reads but only within a read.
Please see patch #2.

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply

* [PATCH iproute2] ss: group DCTCP socket statistics
From: Hagen Paul Pfeifer @ 2015-01-26 22:17 UTC (permalink / raw)
  To: netdev; +Cc: Hagen Paul Pfeifer, Stephen Hemminger

Keep ss output consistent and format DCTCP socket statistics similar to skmen
and timer where a group of logical values are grouped by brackets. This makes
parser scripts *and* humans more happy.


Current output of 'ss -inetm dst :80':
ESTAB       0      0 192.168.11.14:55511 173.194.66.189:443
	timer:(keepalive,14sec,0) uid:1000 ino:428768
	sk:ffff88020ceb5b00 <-> skmem:(r0,rb372480,t0,tb87040,f0,w0,o0,bl0)
	ts sack wscale:7,7 rto:250 rtt:49.225/20.837 ato:40 mss:1408 cwnd:10
	ce_state 23 alpha 23 ab_ecn 23 ab_tot 23 send 2.3Mbps
	lastsnd:121026 lastrcv:121026 lastack:30850 pacing_rate 4.6Mbps
	retrans:0/2 rcv_rtt:40.416 rcv_space:2920

New grouped output:
ESTAB       0      0 192.168.11.14:55511 173.194.66.189:443
	timer:(keepalive,14sec,0) uid:1000 ino:428768
	sk:ffff88020ceb5b00 <-> skmem:(r0,rb372480,t0,tb87040,f0,w0,o0,bl0)
	ts sack wscale:7,7 rto:250 rtt:49.225/20.837 ato:40 mss:1408 cwnd:10
	dctcp(ce_state:23,alpha:23,ab_ecn:23,ab_tot:23) send 2.3Mbps
	lastsnd:121026 lastrcv:121026 lastack:30850 pacing_rate 4.6Mbps
	retrans:0/2 rcv_rtt:40.416 rcv_space:2920

Cc: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Daniel Borkmann <dborkman@redhat.com>
Acked-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Hagen Paul Pfeifer <hagen@jauu.net>
---
 misc/ss.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/misc/ss.c b/misc/ss.c
index f434f57..7d02650 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -1713,11 +1713,11 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r,
 				= RTA_DATA(tb[INET_DIAG_DCTCPINFO]);
 
 			if (dinfo->dctcp_enabled) {
-				printf(" ce_state %u alpha %u ab_ecn %u ab_tot %u",
+				printf("dctcp:(ce_state:%u,alpha:%u,ab_ecn:%u,ab_tot:%u)",
 				       dinfo->dctcp_ce_state, dinfo->dctcp_alpha,
 				       dinfo->dctcp_ab_ecn, dinfo->dctcp_ab_tot);
 			} else {
-				printf(" fallback_mode");
+				printf("dctcp:fallback_mode");
 			}
 		}
 
-- 
2.2.2

^ permalink raw reply related

* Re: make allyesconfig i386 build failure with next-20150122 (caused by fb_agm1264k-fl driver)
From: Guenter Roeck @ 2015-01-26 21:59 UTC (permalink / raw)
  To: Jim Davis
  Cc: Stephen Rothwell, linux-next, linux-kernel, Greg Kroah-Hartman,
	devel, isdn, netdev, Thomas Petazzoni
In-Reply-To: <CA+r1ZhhXF+hicy7JKo3jAbgSbO4KOLm6BwPosTKNb+E_Cb4yPQ@mail.gmail.com>

On Thu, Jan 22, 2015 at 12:10:33PM -0700, Jim Davis wrote:
> make ARCH=i386 allyesconfig fails with
> 
> drivers/staging/built-in.o: In function `reset':
> (.text+0x2ae89d): multiple definition of `reset'
> drivers/isdn/built-in.o:(.text+0x185dc2): first defined here
> make[1]: *** [drivers/built-in.o] Error 1

Culprit:

commit b2ebd4be6fa1d2329b63531b044f9e25474981cb
Author: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Date:   Wed Dec 31 10:11:10 2014 +0100

    staging: fbtft: add fb_agm1264k-fl driver

A global function named 'reset' isn't really a good idea.

Not that the global function with the same name in the isdn code
is better ;-).

Guenter

^ permalink raw reply

* Re: [PATCH] drivers: net: xgene: fix: Out of order descriptor bytes read
From: Eric Dumazet @ 2015-01-26 21:32 UTC (permalink / raw)
  To: Iyappan Subramanian
  Cc: David Miller, netdev, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, mlangsdo, patches,
	Keyur Chudgar
In-Reply-To: <1422307652.29618.30.camel@edumazet-glaptop2.roam.corp.google.com>

On Mon, 2015-01-26 at 13:27 -0800, Eric Dumazet wrote:

> What happens if you compile a kernel with CONFIG_SMP=n ?
> 
> 
> Most drivers in drivers/net use rmb() in this case, not smp_rmb() or
> barrier()

Note that dma_rmb() was recently added as well.

^ permalink raw reply

* Re: [PATCH v3 net-next] net: ipv6: Add sysctl entry to disable MTU updates from RA
From: Dan Williams @ 2015-01-26 21:32 UTC (permalink / raw)
  To: Harout Hedeshian; +Cc: 'David Miller', netdev, 'Vadim Kochan'
In-Reply-To: <028401d03983$6ed4e750$4c7eb5f0$@codeaurora.org>

On Mon, 2015-01-26 at 09:16 -0700, Harout Hedeshian wrote:
> 
> > -----Original Message-----
> > From: netdev-owner@vger.kernel.org [mailto:netdev-owner@vger.kernel.org]
> > On Behalf Of Dan Williams
> > Sent: Monday, January 26, 2015 8:04 AM
> > To: Harout Hedeshian
> > Cc: David Miller; netdev@vger.kernel.org; Vadim Kochan
> > Subject: Re: [PATCH v3 net-next] net: ipv6: Add sysctl entry to disable
> > MTU updates from RA
> > 
> > On Sun, 2015-01-25 at 09:28 -0700, Harout Hedeshian wrote:
> > > On 01/25/2015 12:21 AM, Vadim Kochan wrote:
> > > > On Sat, Jan 24, 2015 at 11:14:32PM -0800, David Miller wrote:
> > > >> From: Harout Hedeshian <harouth@codeaurora.org>
> > > >> Date: Tue, 20 Jan 2015 10:06:05 -0700
> > > >>
> > > >>> The kernel forcefully applies MTU values received in router
> > > >>> advertisements provided the new MTU is less than the current. This
> > > >>> behavior is undesirable when the user space is managing the MTU.
> > > > Instead
> > > >>> a sysctl flag 'accept_ra_mtu' is introduced such that the user
> > > >>> space can control whether or not RA provided MTU updates should be
> > applied.
> > > > The
> > > >>> default behavior is unchanged; user space must explicitly set this
> > > > flag
> > > >>> to 0 for RA MTUs to be ignored.
> > > >>>
> > > >>> Signed-off-by: Harout Hedeshian <harouth@codeaurora.org>
> > > >> Under what circumstances would userland ignore a router advertized
> > > >> MTU, and are the RFCs ok with this?
> > > >> --
> > > >> 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
> > > > Hi,
> > > >
> > > > I don't know if it make sense but I had the same use case when was
> > > > working on supporting IPv6 infrastructure for home gateway.
> > > > One of the provider had requirements to have ability set force IPv6
> > > > MTU value via TR parameters and disable update it via RA.
> > > Hi David,
> > >
> > > We are optionally allowing the kernel shift this responsibility to the
> > > userland. The idea would be that the kernel would ignore it, not so
> > > much the userland. Just like Vadim, we may not want to use the MTU
> > > value which comes from the network. Instead, we get an MTU value from
> > > the cellular modem via configuration message, and that is the MTU we
> > use.
> > 
> > Are you talking about an ethernet interface exposed by the modem, or a
> > separate network interface connected to a normal LAN?  In the modem
> > case, why would the network-provided RA's MTU be incorrect, but the
> > modem's MTU be correct?  If the normal LAN case, why would the modem's
> > MTU be correct for a different network that is broadcasting its own RAs?
> > Just curious...
> > 
> > Dan
> 
> Hi Dan,
> 
> This is a really good question. In the case of a normal LAN, we will allow the kernel to handle the MTU values as they have been today (basically, keep the accept_ra_mtu=1). The issue is not really about the correctness of the RA MTU value (we assume this value is correct, otherwise we are in serious trouble).The issue is on the modem interfaces. To the modem, each protocol family is its own interface. This analogy breaks down for us in Linux because v4 and v6 are fundamentally the same net_device interface. From what I can tell, there is no /proc/sys/net/ipv4/conf/<dev>/mtu which means that IPv4 will take the MTU value from dev->mtu (see ipv4_mtu() ). In contrast, IPv6 maintains a separate MTU and will apply the RA MTUs such that they are less than the device's MTU (dev->mtu). For consi
 stency, we have been asked to always pick the minimum value of the IPv4 and IPv6 MTU, and that will become the overall interface MTU. If the kernel goes and changes the V6 MTU without us kn!
 ow!
>  ing, the userland daemon which maintains the MTU parity will be out of sync. We *could* theoretically let the kernel apply RA MTU updates and we listen for netlink events, but that is unnecessarily complicated as we are already listening in multiple places for these MTU updates. Additionally, we have a problem where the default dev->mtu is 1500 bytes. If we have an IPv6-only network, then it is possible that the network will want to use an MTU > 1500 (esp. multimedia optimized carrier networks). Currently, ndisc.c compares the new MTU value with dev->mtu, if bigger, the RA is ignored. I don't see a good alternative to this because there is no way for ndisc.c to know what the device's maximum physical capabilities are (or that we even want to use such a large MTU). Because of that, we ha
 ve to have an out-of-band mechanism to adjust the interface MTU since we know that the hardware is capable of transmitting packets greater than 1500 bytes. Thus, instead of letting the kern!
 el!

I believe the IPv4 MTU is taken from the device MTU, eg 'ip link set dev
wwp0s26f7u2i8 mtu XXXX'.  I believe that's also where the IPv6 MTU is
taken from, unless it's set via /proc.

But thanks for the explanation, it makes sense.

Dan

>   handle RA MTUs in some special circumstances, it is safer and!
>   cleaner to disable RA MTUs on the modem interface altogether and let userland pick the correct MTU. 
> 
> One way to clean up this mess would be to make some changes in the way the kernel handles MTUs. 
> 1. Make dev->mtu actually be the MTU the device is capable. For example, jumbo frame capable devices would set this to 9000 upon enumeration instead of 1500. This value would not be editable from userland. There would no longer be a need for driver to implement the MTU adjustment ndo.
> 2. *ALL* protocols must maintain their own MTU values. This would mean a new per-device proc entry for IPv4 at a minimum. The defaults of these values can remain 1500.
> 
> If we did this, then the kernel can apply RA MTUs > 1500, and we would get it for free (no changes in IPv6 code). IPv4 would be parity with IPv6 in terms of decoupling MTU from dev->mtu. This means userland can completely not care about the IPv6 MTU, and we can push back on the MTU consistency requirement. Of course, this is a pretty drastic change in interpretation of dev->mtu and would break a lot of userland utilities. Or maybe we leave #1 editable in userland so the utilities and IOCTLs still work, however, userland will now have to additionally adjust IPv4 MTU...
> 
> If the kernel community likes this approach, I would be happy to upload some patches which creates a new definition for IPv4 MTU. I think #1 will need more discussion.
> 
> If v4 and v6 were truly decoupled, then we could get rid of this minimum selection mess and special case handling for large IPv6 MTUs and this patch could go away.
> 
> 
> Thanks,
> Harout
> 
> 
> 
> --
> 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

^ permalink raw reply

* [PATCH net 2/2] vxlan: setup the right link netns in newlink hdlr
From: Nicolas Dichtel @ 2015-01-26 21:28 UTC (permalink / raw)
  To: netdev
  Cc: davem, dmitry.tarnyagin, arvid.brodin, alex.aring, linux-wpan,
	Nicolas Dichtel
In-Reply-To: <1422307694-10079-1-git-send-email-nicolas.dichtel@6wind.com>

Rename the netns to src_net to avoid confusion with the netns where the
interface stands. The user may specify IFLA_NET_NS_[PID|FD] to create
a x-netns netndevice: IFLA_NET_NS_[PID|FD] points to the netns where the
netdevice stands and src_net to the link netns.

Note that before commit f01ec1c017de ("vxlan: add x-netns support"), it was
possible to create a x-netns vxlan netdevice, but the netdevice was not
operational.

Fixes: f01ec1c017de ("vxlan: add x-netns support")
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
 drivers/net/vxlan.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index 7fbd89fbe107..a8c755dcab14 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -2432,10 +2432,10 @@ static void vxlan_sock_work(struct work_struct *work)
 	dev_put(vxlan->dev);
 }
 
-static int vxlan_newlink(struct net *net, struct net_device *dev,
+static int vxlan_newlink(struct net *src_net, struct net_device *dev,
 			 struct nlattr *tb[], struct nlattr *data[])
 {
-	struct vxlan_net *vn = net_generic(net, vxlan_net_id);
+	struct vxlan_net *vn = net_generic(src_net, vxlan_net_id);
 	struct vxlan_dev *vxlan = netdev_priv(dev);
 	struct vxlan_rdst *dst = &vxlan->default_dst;
 	__u32 vni;
@@ -2445,7 +2445,7 @@ static int vxlan_newlink(struct net *net, struct net_device *dev,
 	if (!data[IFLA_VXLAN_ID])
 		return -EINVAL;
 
-	vxlan->net = dev_net(dev);
+	vxlan->net = src_net;
 
 	vni = nla_get_u32(data[IFLA_VXLAN_ID]);
 	dst->remote_vni = vni;
@@ -2481,7 +2481,7 @@ static int vxlan_newlink(struct net *net, struct net_device *dev,
 	if (data[IFLA_VXLAN_LINK] &&
 	    (dst->remote_ifindex = nla_get_u32(data[IFLA_VXLAN_LINK]))) {
 		struct net_device *lowerdev
-			 = __dev_get_by_index(net, dst->remote_ifindex);
+			 = __dev_get_by_index(src_net, dst->remote_ifindex);
 
 		if (!lowerdev) {
 			pr_info("ifindex %d does not exist\n", dst->remote_ifindex);
@@ -2557,7 +2557,7 @@ static int vxlan_newlink(struct net *net, struct net_device *dev,
 	    nla_get_u8(data[IFLA_VXLAN_UDP_ZERO_CSUM6_RX]))
 		vxlan->flags |= VXLAN_F_UDP_ZERO_CSUM6_RX;
 
-	if (vxlan_find_vni(net, vni, use_ipv6 ? AF_INET6 : AF_INET,
+	if (vxlan_find_vni(src_net, vni, use_ipv6 ? AF_INET6 : AF_INET,
 			   vxlan->dst_port)) {
 		pr_info("duplicate VNI %u\n", vni);
 		return -EEXIST;
-- 
2.2.2

^ permalink raw reply related

* [PATCH net 0/2] netns: audit netdevice creation with IFLA_NET_NS_[PID|FD]
From: Nicolas Dichtel @ 2015-01-26 21:28 UTC (permalink / raw)
  To: netdev; +Cc: davem, dmitry.tarnyagin, arvid.brodin, alex.aring, linux-wpan


When one of these attributes is set, the netdevice is created into the netns
pointed by IFLA_NET_NS_[PID|FD] (see the call to rtnl_create_link() in
rtnl_newlink()). Let's call this netns the dest_net. After this creation, if the
newlink handler exists, it is called with a netns argument that points to the
netns where the netlink message has been received (called src_net in the code)
which is the link netns.
Hence, with one of these attributes, it's possible to create a x-netns
netdevice.

Here is the result of my code review:
- all ip tunnels (sit, ipip, ip6_tunnels, gre[tap][v6], ip_vti[6]) does not
  really allows to use this feature: the netdevice is created in the dest_net
  and the src_net is completely ignored in the newlink handler.
- VLAN properly handles this x-netns creation.
- bridge ignores src_net, which seems fine (NETIF_F_NETNS_LOCAL is set).
- CAIF subsystem is not clear for me (I don't know how it works), but it seems
  to wrongly use src_net. Patch #1 tries to fix this, but it was done only by
  code review (and only compile-tested), so please carefully review it. I may
  miss something.
- HSR subsystem uses src_net to parse IFLA_HSR_SLAVE[1|2], but the netdevice has
  the flag NETIF_F_NETNS_LOCAL, so the question is: does this netdevice really
  supports x-netns? If not, the newlink handler should use the dest_net instead
  of src_net, I can provide the patch.
- ieee802154 uses also src_net and does not have NETIF_F_NETNS_LOCAL. Same
  question: does this netdevice really supports x-netns?
- bonding ignores src_net and flag NETIF_F_NETNS_LOCAL is set, ie x-netns is not
  supported. Fine.
- CAN does not support rtnl/newlink, ok.
- ipvlan uses src_net and does not have NETIF_F_NETNS_LOCAL. After looking at
  the code, it seems that this drivers support x-netns. Am I right?
- macvlan/macvtap uses src_net and seems to have x-netns support.
- team ignores src_net and has the flag NETIF_F_NETNS_LOCAL, ie x-netns is not
  supported. Ok.
- veth uses src_net and have x-netns support ;-) Ok.
- VXLAN didn't properly handle this. The link netns (vxlan->net) is the src_net
  and not dest_net (see patch #2). Note that it was already possible to create a
  x-netns vxlan before the commit f01ec1c017de ("vxlan: add x-netns support")
  but the nedevice remains broken.

To summarize:
 - CAIF patch must be carefully reviewed
 - for HSR, ieee802154, ipvlan: is x-netns supported?

 drivers/net/caif/caif_hsi.c |  1 -
 drivers/net/vxlan.c         | 10 +++++-----
 net/caif/chnl_net.c         |  1 -
 3 files changed, 5 insertions(+), 7 deletions(-)

Regards,
Nicolas

^ permalink raw reply

* [PATCH net 1/2] caif: remove wrong dev_net_set() call
From: Nicolas Dichtel @ 2015-01-26 21:28 UTC (permalink / raw)
  To: netdev
  Cc: davem, dmitry.tarnyagin, arvid.brodin, alex.aring, linux-wpan,
	Nicolas Dichtel, Sjur Brændeland
In-Reply-To: <1422307694-10079-1-git-send-email-nicolas.dichtel@6wind.com>

src_net points to the netns where the netlink message has been received. This
netns may be different from the netns where the interface is created (because
the user may add IFLA_NET_NS_[PID|FD]). In this case, src_net is the link netns.

It seems wrong to override the netns in the newlink() handler because if it
was not already src_net, it means that the user explicitly asks to create the
netdevice in another netns.

CC: Sjur Brændeland <sjur.brandeland@stericsson.com>
CC: Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no>
Fixes: 8391c4aab1aa ("caif: Bugfixes in CAIF netdevice for close and flow control")
Fixes: c41254006377 ("caif-hsi: Add rtnl support")
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
 drivers/net/caif/caif_hsi.c | 1 -
 net/caif/chnl_net.c         | 1 -
 2 files changed, 2 deletions(-)

diff --git a/drivers/net/caif/caif_hsi.c b/drivers/net/caif/caif_hsi.c
index 5e40a8b68cbe..b3b922adc0e4 100644
--- a/drivers/net/caif/caif_hsi.c
+++ b/drivers/net/caif/caif_hsi.c
@@ -1415,7 +1415,6 @@ static int caif_hsi_newlink(struct net *src_net, struct net_device *dev,
 
 	cfhsi = netdev_priv(dev);
 	cfhsi_netlink_parms(data, cfhsi);
-	dev_net_set(cfhsi->ndev, src_net);
 
 	get_ops = symbol_get(cfhsi_get_ops);
 	if (!get_ops) {
diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
index 4589ff67bfa9..67a4a36febd1 100644
--- a/net/caif/chnl_net.c
+++ b/net/caif/chnl_net.c
@@ -470,7 +470,6 @@ static int ipcaif_newlink(struct net *src_net, struct net_device *dev,
 	ASSERT_RTNL();
 	caifdev = netdev_priv(dev);
 	caif_netlink_parms(data, &caifdev->conn_req);
-	dev_net_set(caifdev->netdev, src_net);
 
 	ret = register_netdevice(dev);
 	if (ret)
-- 
2.2.2

^ permalink raw reply related

* Re: [PATCH] drivers: net: xgene: fix: Out of order descriptor bytes read
From: Eric Dumazet @ 2015-01-26 21:27 UTC (permalink / raw)
  To: Iyappan Subramanian
  Cc: David Miller, netdev, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, mlangsdo, patches,
	Keyur Chudgar
In-Reply-To: <CAKh23FmxvV82mVrHq5jv-FE+e6u6CkW+xL_a2_ULAQgP_mM2VA@mail.gmail.com>

On Mon, 2015-01-26 at 13:12 -0800, Iyappan Subramanian wrote:
> On Thu, Jan 22, 2015 at 2:50 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> > On Thu, 2015-01-22 at 12:03 -0800, Iyappan Subramanian wrote:
> >> This patch fixes the following kernel crash,
> >>
> >>       WARNING: CPU: 2 PID: 0 at net/ipv4/tcp_input.c:3079 tcp_clean_rtx_queue+0x658/0x80c()
> >>       Call trace:
> >
> >>
> >> Software writes poison data into the descriptor bytes[15:8] and upon
> >> receiving the interrupt, if those bytes are overwritten by the hardware with
> >> the valid data, software also reads bytes[7:0] and executes receive/tx
> >> completion logic.
> >>
> >> If the CPU executes the above two reads in out of order fashion, then the
> >> bytes[7:0] will have older data and causing the kernel panic.  We have to
> >> force the order of the reads and thus this patch introduces read memory
> >> barrier between these reads.
> >>
> >> Signed-off-by: Iyappan Subramanian <isubramanian@apm.com>
> >> Signed-off-by: Keyur Chudgar <kchudgar@apm.com>
> >> Tested-by: Mark Langsdorf <mlangsdo@redhat.com>
> >> ---
> >>  drivers/net/ethernet/apm/xgene/xgene_enet_main.c | 2 ++
> >>  1 file changed, 2 insertions(+)
> >>
> >> diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_main.c b/drivers/net/ethernet/apm/xgene/xgene_enet_main.c
> >> index 83a5028..3622cdb 100644
> >> --- a/drivers/net/ethernet/apm/xgene/xgene_enet_main.c
> >> +++ b/drivers/net/ethernet/apm/xgene/xgene_enet_main.c
> >> @@ -369,6 +369,8 @@ static int xgene_enet_process_ring(struct xgene_enet_desc_ring *ring,
> >>               if (unlikely(xgene_enet_is_desc_slot_empty(raw_desc)))
> >>                       break;
> >>
> >> +             /* read fpqnum field after dataaddr field */
> >> +             smp_rmb();
> >>               if (is_rx_desc(raw_desc))
> >>                       ret = xgene_enet_rx_frame(ring, raw_desc);
> >>               else
> >
> > Reading your changelog, it looks like you need a plain rmb() here.
> 
> rmb() translates into dsb, which in arm64 serializes everything
> including instructions and thus expensive compared to dmb.
> 
> Do you see any issue with smp_rmb() (which translates into dmb) ?

What happens if you compile a kernel with CONFIG_SMP=n ?


Most drivers in drivers/net use rmb() in this case, not smp_rmb() or
barrier()

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox