2 * net/switchdev/switchdev.c - Switch device API
3 * Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
11 #include <linux/kernel.h>
12 #include <linux/types.h>
13 #include <linux/init.h>
14 #include <linux/mutex.h>
15 #include <linux/notifier.h>
16 #include <linux/netdevice.h>
17 #include <net/switchdev.h>
20 * netdev_switch_parent_id_get - Get ID of a switch
24 * Get ID of a switch this port is part of.
26 int netdev_switch_parent_id_get(struct net_device *dev,
27 struct netdev_phys_item_id *psid)
29 const struct net_device_ops *ops = dev->netdev_ops;
31 if (!ops->ndo_switch_parent_id_get)
33 return ops->ndo_switch_parent_id_get(dev, psid);
35 EXPORT_SYMBOL(netdev_switch_parent_id_get);
38 * netdev_switch_port_stp_update - Notify switch device port of STP
41 * @state: port STP state
43 * Notify switch device port of bridge port STP state change.
45 int netdev_switch_port_stp_update(struct net_device *dev, u8 state)
47 const struct net_device_ops *ops = dev->netdev_ops;
49 if (!ops->ndo_switch_port_stp_update)
51 WARN_ON(!ops->ndo_switch_parent_id_get);
52 return ops->ndo_switch_port_stp_update(dev, state);
54 EXPORT_SYMBOL(netdev_switch_port_stp_update);
56 static DEFINE_MUTEX(netdev_switch_mutex);
57 static RAW_NOTIFIER_HEAD(netdev_switch_notif_chain);
60 * register_netdev_switch_notifier - Register nofifier
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().
67 int register_netdev_switch_notifier(struct notifier_block *nb)
71 mutex_lock(&netdev_switch_mutex);
72 err = raw_notifier_chain_register(&netdev_switch_notif_chain, nb);
73 mutex_unlock(&netdev_switch_mutex);
76 EXPORT_SYMBOL(register_netdev_switch_notifier);
79 * unregister_netdev_switch_notifier - Unregister nofifier
82 * Unregister switch device notifier.
83 * Return values are same as for atomic_notifier_chain_unregister().
85 int unregister_netdev_switch_notifier(struct notifier_block *nb)
89 mutex_lock(&netdev_switch_mutex);
90 err = raw_notifier_chain_unregister(&netdev_switch_notif_chain, nb);
91 mutex_unlock(&netdev_switch_mutex);
94 EXPORT_SYMBOL(unregister_netdev_switch_notifier);
97 * call_netdev_switch_notifiers - Call nofifiers
98 * @val: value passed unmodified to notifier function
100 * @info: notifier information data
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().
106 int call_netdev_switch_notifiers(unsigned long val, struct net_device *dev,
107 struct netdev_switch_notifier_info *info)
112 mutex_lock(&netdev_switch_mutex);
113 err = raw_notifier_call_chain(&netdev_switch_notif_chain, val, info);
114 mutex_unlock(&netdev_switch_mutex);
117 EXPORT_SYMBOL(call_netdev_switch_notifiers);