aboutsummaryrefslogtreecommitdiffstats
path: root/net/switchdev
diff options
context:
space:
mode:
authorJiri Pirko <jiri@resnulli.us>2015-01-15 17:49:36 -0500
committerDavid S. Miller <davem@davemloft.net>2015-01-18 00:23:57 -0500
commit03bf0c281234028388108d0aee720954f5fe6924 (patch)
treec1cdfebacbe5d09e904ef185faafd7d8dffc7ee8 /net/switchdev
parentff8b335610cac5509156f28e03355c895bcc94f5 (diff)
switchdev: introduce switchdev notifier
This patch introduces new notifier for purposes of exposing events which happen on switch driver side. The consumers of the event messages are mainly involved masters, namely bridge and ovs. Suggested-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: Jiri Pirko <jiri@resnulli.us> Signed-off-by: Scott Feldman <sfeldma@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/switchdev')
-rw-r--r--net/switchdev/switchdev.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/net/switchdev/switchdev.c b/net/switchdev/switchdev.c
index d162b21b14bd..22e02f4edd99 100644
--- a/net/switchdev/switchdev.c
+++ b/net/switchdev/switchdev.c
@@ -11,6 +11,8 @@
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/types.h> 12#include <linux/types.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/mutex.h>
15#include <linux/notifier.h>
14#include <linux/netdevice.h> 16#include <linux/netdevice.h>
15#include <net/switchdev.h> 17#include <net/switchdev.h>
16 18
@@ -50,3 +52,66 @@ int netdev_switch_port_stp_update(struct net_device *dev, u8 state)
50 return ops->ndo_switch_port_stp_update(dev, state); 52 return ops->ndo_switch_port_stp_update(dev, state);
51} 53}
52EXPORT_SYMBOL(netdev_switch_port_stp_update); 54EXPORT_SYMBOL(netdev_switch_port_stp_update);
55
56static DEFINE_MUTEX(netdev_switch_mutex);
57static RAW_NOTIFIER_HEAD(netdev_switch_notif_chain);
58
59/**
60 * register_netdev_switch_notifier - Register nofifier
61 * @nb: notifier_block
62 *
63 * Register switch device notifier. This should be used by code
64 * which needs to monitor events happening in particular device.
65 * Return values are same as for atomic_notifier_chain_register().
66 */
67int register_netdev_switch_notifier(struct notifier_block *nb)
68{
69 int err;
70
71 mutex_lock(&netdev_switch_mutex);
72 err = raw_notifier_chain_register(&netdev_switch_notif_chain, nb);
73 mutex_unlock(&netdev_switch_mutex);
74 return err;
75}
76EXPORT_SYMBOL(register_netdev_switch_notifier);
77
78/**
79 * unregister_netdev_switch_notifier - Unregister nofifier
80 * @nb: notifier_block
81 *
82 * Unregister switch device notifier.
83 * Return values are same as for atomic_notifier_chain_unregister().
84 */
85int unregister_netdev_switch_notifier(struct notifier_block *nb)
86{
87 int err;
88
89 mutex_lock(&netdev_switch_mutex);
90 err = raw_notifier_chain_unregister(&netdev_switch_notif_chain, nb);
91 mutex_unlock(&netdev_switch_mutex);
92 return err;
93}
94EXPORT_SYMBOL(unregister_netdev_switch_notifier);
95
96/**
97 * call_netdev_switch_notifiers - Call nofifiers
98 * @val: value passed unmodified to notifier function
99 * @dev: port device
100 * @info: notifier information data
101 *
102 * Call all network notifier blocks. This should be called by driver
103 * when it needs to propagate hardware event.
104 * Return values are same as for atomic_notifier_call_chain().
105 */
106int call_netdev_switch_notifiers(unsigned long val, struct net_device *dev,
107 struct netdev_switch_notifier_info *info)
108{
109 int err;
110
111 info->dev = dev;
112 mutex_lock(&netdev_switch_mutex);
113 err = raw_notifier_call_chain(&netdev_switch_notif_chain, val, info);
114 mutex_unlock(&netdev_switch_mutex);
115 return err;
116}
117EXPORT_SYMBOL(call_netdev_switch_notifiers);