switchdev.c (e5451c8f8330e03ad3cfa16048b4daf961af434f) switchdev.c (472681d57a5dde7c6d16b05469be57f1c4ed9d99)
1/*
2 * net/switchdev/switchdev.c - Switch device API
3 * Copyright (c) 2014-2015 Jiri Pirko <jiri@resnulli.us>
4 * Copyright (c) 2014-2015 Scott Feldman <sfeldma@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or

--- 6 unchanged lines hidden (view full) ---

15#include <linux/mutex.h>
16#include <linux/notifier.h>
17#include <linux/netdevice.h>
18#include <linux/etherdevice.h>
19#include <linux/if_bridge.h>
20#include <linux/list.h>
21#include <linux/workqueue.h>
22#include <linux/if_vlan.h>
1/*
2 * net/switchdev/switchdev.c - Switch device API
3 * Copyright (c) 2014-2015 Jiri Pirko <jiri@resnulli.us>
4 * Copyright (c) 2014-2015 Scott Feldman <sfeldma@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or

--- 6 unchanged lines hidden (view full) ---

15#include <linux/mutex.h>
16#include <linux/notifier.h>
17#include <linux/netdevice.h>
18#include <linux/etherdevice.h>
19#include <linux/if_bridge.h>
20#include <linux/list.h>
21#include <linux/workqueue.h>
22#include <linux/if_vlan.h>
23#include <linux/rtnetlink.h>
23#include <net/ip_fib.h>
24#include <net/switchdev.h>
25
26/**
27 * switchdev_trans_item_enqueue - Enqueue data item to transaction queue
28 *
29 * @trans: transaction
30 * @data: pointer to data being queued

--- 531 unchanged lines hidden (view full) ---

562 err = switchdev_port_obj_dump(lower_dev, obj, cb);
563 break;
564 }
565
566 return err;
567}
568EXPORT_SYMBOL_GPL(switchdev_port_obj_dump);
569
24#include <net/ip_fib.h>
25#include <net/switchdev.h>
26
27/**
28 * switchdev_trans_item_enqueue - Enqueue data item to transaction queue
29 *
30 * @trans: transaction
31 * @data: pointer to data being queued

--- 531 unchanged lines hidden (view full) ---

563 err = switchdev_port_obj_dump(lower_dev, obj, cb);
564 break;
565 }
566
567 return err;
568}
569EXPORT_SYMBOL_GPL(switchdev_port_obj_dump);
570
570static DEFINE_MUTEX(switchdev_mutex);
571static RAW_NOTIFIER_HEAD(switchdev_notif_chain);
572
573/**
574 * register_switchdev_notifier - Register notifier
575 * @nb: notifier_block
576 *
577 * Register switch device notifier. This should be used by code
578 * which needs to monitor events happening in particular device.
579 * Return values are same as for atomic_notifier_chain_register().
580 */
581int register_switchdev_notifier(struct notifier_block *nb)
582{
583 int err;
584
571static RAW_NOTIFIER_HEAD(switchdev_notif_chain);
572
573/**
574 * register_switchdev_notifier - Register notifier
575 * @nb: notifier_block
576 *
577 * Register switch device notifier. This should be used by code
578 * which needs to monitor events happening in particular device.
579 * Return values are same as for atomic_notifier_chain_register().
580 */
581int register_switchdev_notifier(struct notifier_block *nb)
582{
583 int err;
584
585 mutex_lock(&switchdev_mutex);
585 rtnl_lock();
586 err = raw_notifier_chain_register(&switchdev_notif_chain, nb);
586 err = raw_notifier_chain_register(&switchdev_notif_chain, nb);
587 mutex_unlock(&switchdev_mutex);
587 rtnl_unlock();
588 return err;
589}
590EXPORT_SYMBOL_GPL(register_switchdev_notifier);
591
592/**
593 * unregister_switchdev_notifier - Unregister notifier
594 * @nb: notifier_block
595 *
596 * Unregister switch device notifier.
597 * Return values are same as for atomic_notifier_chain_unregister().
598 */
599int unregister_switchdev_notifier(struct notifier_block *nb)
600{
601 int err;
602
588 return err;
589}
590EXPORT_SYMBOL_GPL(register_switchdev_notifier);
591
592/**
593 * unregister_switchdev_notifier - Unregister notifier
594 * @nb: notifier_block
595 *
596 * Unregister switch device notifier.
597 * Return values are same as for atomic_notifier_chain_unregister().
598 */
599int unregister_switchdev_notifier(struct notifier_block *nb)
600{
601 int err;
602
603 mutex_lock(&switchdev_mutex);
603 rtnl_lock();
604 err = raw_notifier_chain_unregister(&switchdev_notif_chain, nb);
604 err = raw_notifier_chain_unregister(&switchdev_notif_chain, nb);
605 mutex_unlock(&switchdev_mutex);
605 rtnl_unlock();
606 return err;
607}
608EXPORT_SYMBOL_GPL(unregister_switchdev_notifier);
609
610/**
611 * call_switchdev_notifiers - Call notifiers
612 * @val: value passed unmodified to notifier function
613 * @dev: port device
614 * @info: notifier information data
615 *
616 * Call all network notifier blocks. This should be called by driver
617 * when it needs to propagate hardware event.
618 * Return values are same as for atomic_notifier_call_chain().
606 return err;
607}
608EXPORT_SYMBOL_GPL(unregister_switchdev_notifier);
609
610/**
611 * call_switchdev_notifiers - Call notifiers
612 * @val: value passed unmodified to notifier function
613 * @dev: port device
614 * @info: notifier information data
615 *
616 * Call all network notifier blocks. This should be called by driver
617 * when it needs to propagate hardware event.
618 * Return values are same as for atomic_notifier_call_chain().
619 * rtnl_lock must be held.
619 */
620int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
621 struct switchdev_notifier_info *info)
622{
623 int err;
624
620 */
621int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
622 struct switchdev_notifier_info *info)
623{
624 int err;
625
626 ASSERT_RTNL();
627
625 info->dev = dev;
628 info->dev = dev;
626 mutex_lock(&switchdev_mutex);
627 err = raw_notifier_call_chain(&switchdev_notif_chain, val, info);
629 err = raw_notifier_call_chain(&switchdev_notif_chain, val, info);
628 mutex_unlock(&switchdev_mutex);
629 return err;
630}
631EXPORT_SYMBOL_GPL(call_switchdev_notifiers);
632
633struct switchdev_vlan_dump {
634 struct switchdev_obj_port_vlan vlan;
635 struct sk_buff *skb;
636 u32 filter_mask;

--- 450 unchanged lines hidden (view full) ---

1087 struct switchdev_fdb_dump dump = {
1088 .fdb.obj.orig_dev = dev,
1089 .fdb.obj.id = SWITCHDEV_OBJ_ID_PORT_FDB,
1090 .dev = dev,
1091 .skb = skb,
1092 .cb = cb,
1093 .idx = idx,
1094 };
630 return err;
631}
632EXPORT_SYMBOL_GPL(call_switchdev_notifiers);
633
634struct switchdev_vlan_dump {
635 struct switchdev_obj_port_vlan vlan;
636 struct sk_buff *skb;
637 u32 filter_mask;

--- 450 unchanged lines hidden (view full) ---

1088 struct switchdev_fdb_dump dump = {
1089 .fdb.obj.orig_dev = dev,
1090 .fdb.obj.id = SWITCHDEV_OBJ_ID_PORT_FDB,
1091 .dev = dev,
1092 .skb = skb,
1093 .cb = cb,
1094 .idx = idx,
1095 };
1096 int err;
1095
1097
1096 switchdev_port_obj_dump(dev, &dump.fdb.obj, switchdev_port_fdb_dump_cb);
1098 err = switchdev_port_obj_dump(dev, &dump.fdb.obj,
1099 switchdev_port_fdb_dump_cb);
1100 cb->args[1] = err;
1097 return dump.idx;
1098}
1099EXPORT_SYMBOL_GPL(switchdev_port_fdb_dump);
1100
1101static struct net_device *switchdev_get_lowest_dev(struct net_device *dev)
1102{
1103 const struct switchdev_ops *ops = dev->switchdev_ops;
1104 struct net_device *lower_dev;

--- 281 unchanged lines hidden ---
1101 return dump.idx;
1102}
1103EXPORT_SYMBOL_GPL(switchdev_port_fdb_dump);
1104
1105static struct net_device *switchdev_get_lowest_dev(struct net_device *dev)
1106{
1107 const struct switchdev_ops *ops = dev->switchdev_ops;
1108 struct net_device *lower_dev;

--- 281 unchanged lines hidden ---