2 * Handling of a single switch chip, part of a switch fabric
4 * Copyright (c) 2017 Savoir-faire Linux Inc.
5 * Vivien Didelot <vivien.didelot@savoirfairelinux.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
13 #include <linux/netdevice.h>
14 #include <linux/notifier.h>
17 static int dsa_switch_bridge_join(struct dsa_switch *ds,
18 struct dsa_notifier_bridge_info *info)
20 if (ds->index == info->sw_index && ds->ops->port_bridge_join)
21 return ds->ops->port_bridge_join(ds, info->port, info->br);
23 if (ds->index != info->sw_index && ds->ops->crosschip_bridge_join)
24 return ds->ops->crosschip_bridge_join(ds, info->sw_index,
25 info->port, info->br);
30 static int dsa_switch_bridge_leave(struct dsa_switch *ds,
31 struct dsa_notifier_bridge_info *info)
33 if (ds->index == info->sw_index && ds->ops->port_bridge_leave)
34 ds->ops->port_bridge_leave(ds, info->port, info->br);
36 if (ds->index != info->sw_index && ds->ops->crosschip_bridge_leave)
37 ds->ops->crosschip_bridge_leave(ds, info->sw_index, info->port,
43 static int dsa_switch_event(struct notifier_block *nb,
44 unsigned long event, void *info)
46 struct dsa_switch *ds = container_of(nb, struct dsa_switch, nb);
50 case DSA_NOTIFIER_BRIDGE_JOIN:
51 err = dsa_switch_bridge_join(ds, info);
53 case DSA_NOTIFIER_BRIDGE_LEAVE:
54 err = dsa_switch_bridge_leave(ds, info);
61 /* Non-switchdev operations cannot be rolled back. If a DSA driver
62 * returns an error during the chained call, switch chips may be in an
66 dev_dbg(ds->dev, "breaking chain for DSA event %lu (%d)\n",
69 return notifier_from_errno(err);
72 int dsa_switch_register_notifier(struct dsa_switch *ds)
74 ds->nb.notifier_call = dsa_switch_event;
76 return raw_notifier_chain_register(&ds->dst->nh, &ds->nb);
79 void dsa_switch_unregister_notifier(struct dsa_switch *ds)
83 err = raw_notifier_chain_unregister(&ds->dst->nh, &ds->nb);
85 dev_err(ds->dev, "failed to unregister notifier (%d)\n", err);