Vivien Didelot | f515f19 | 2017-02-03 13:20:20 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Handling of a single switch chip, part of a switch fabric |
| 3 | * |
Vivien Didelot | 4333d61 | 2017-03-28 15:10:36 -0400 | [diff] [blame] | 4 | * Copyright (c) 2017 Savoir-faire Linux Inc. |
| 5 | * Vivien Didelot <vivien.didelot@savoirfairelinux.com> |
Vivien Didelot | f515f19 | 2017-02-03 13:20:20 -0500 | [diff] [blame] | 6 | * |
| 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. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/netdevice.h> |
| 14 | #include <linux/notifier.h> |
Vivien Didelot | ea5dd34 | 2017-05-17 15:46:03 -0400 | [diff] [blame^] | 15 | |
| 16 | #include "dsa_priv.h" |
Vivien Didelot | f515f19 | 2017-02-03 13:20:20 -0500 | [diff] [blame] | 17 | |
Vivien Didelot | 04d3a4c | 2017-02-03 13:20:21 -0500 | [diff] [blame] | 18 | static int dsa_switch_bridge_join(struct dsa_switch *ds, |
| 19 | struct dsa_notifier_bridge_info *info) |
| 20 | { |
| 21 | if (ds->index == info->sw_index && ds->ops->port_bridge_join) |
| 22 | return ds->ops->port_bridge_join(ds, info->port, info->br); |
| 23 | |
Vivien Didelot | 40ef2c9 | 2017-03-30 17:37:14 -0400 | [diff] [blame] | 24 | if (ds->index != info->sw_index && ds->ops->crosschip_bridge_join) |
| 25 | return ds->ops->crosschip_bridge_join(ds, info->sw_index, |
| 26 | info->port, info->br); |
Vivien Didelot | 04d3a4c | 2017-02-03 13:20:21 -0500 | [diff] [blame] | 27 | |
| 28 | return 0; |
| 29 | } |
| 30 | |
| 31 | static int dsa_switch_bridge_leave(struct dsa_switch *ds, |
| 32 | struct dsa_notifier_bridge_info *info) |
| 33 | { |
| 34 | if (ds->index == info->sw_index && ds->ops->port_bridge_leave) |
| 35 | ds->ops->port_bridge_leave(ds, info->port, info->br); |
| 36 | |
Vivien Didelot | 40ef2c9 | 2017-03-30 17:37:14 -0400 | [diff] [blame] | 37 | if (ds->index != info->sw_index && ds->ops->crosschip_bridge_leave) |
| 38 | ds->ops->crosschip_bridge_leave(ds, info->sw_index, info->port, |
| 39 | info->br); |
Vivien Didelot | 04d3a4c | 2017-02-03 13:20:21 -0500 | [diff] [blame] | 40 | |
| 41 | return 0; |
| 42 | } |
| 43 | |
Vivien Didelot | f515f19 | 2017-02-03 13:20:20 -0500 | [diff] [blame] | 44 | static int dsa_switch_event(struct notifier_block *nb, |
| 45 | unsigned long event, void *info) |
| 46 | { |
| 47 | struct dsa_switch *ds = container_of(nb, struct dsa_switch, nb); |
| 48 | int err; |
| 49 | |
| 50 | switch (event) { |
Vivien Didelot | 04d3a4c | 2017-02-03 13:20:21 -0500 | [diff] [blame] | 51 | case DSA_NOTIFIER_BRIDGE_JOIN: |
| 52 | err = dsa_switch_bridge_join(ds, info); |
| 53 | break; |
| 54 | case DSA_NOTIFIER_BRIDGE_LEAVE: |
| 55 | err = dsa_switch_bridge_leave(ds, info); |
| 56 | break; |
Vivien Didelot | f515f19 | 2017-02-03 13:20:20 -0500 | [diff] [blame] | 57 | default: |
| 58 | err = -EOPNOTSUPP; |
| 59 | break; |
| 60 | } |
| 61 | |
| 62 | /* Non-switchdev operations cannot be rolled back. If a DSA driver |
| 63 | * returns an error during the chained call, switch chips may be in an |
| 64 | * inconsistent state. |
| 65 | */ |
| 66 | if (err) |
| 67 | dev_dbg(ds->dev, "breaking chain for DSA event %lu (%d)\n", |
| 68 | event, err); |
| 69 | |
| 70 | return notifier_from_errno(err); |
| 71 | } |
| 72 | |
| 73 | int dsa_switch_register_notifier(struct dsa_switch *ds) |
| 74 | { |
| 75 | ds->nb.notifier_call = dsa_switch_event; |
| 76 | |
| 77 | return raw_notifier_chain_register(&ds->dst->nh, &ds->nb); |
| 78 | } |
| 79 | |
| 80 | void dsa_switch_unregister_notifier(struct dsa_switch *ds) |
| 81 | { |
| 82 | int err; |
| 83 | |
| 84 | err = raw_notifier_chain_unregister(&ds->dst->nh, &ds->nb); |
| 85 | if (err) |
| 86 | dev_err(ds->dev, "failed to unregister notifier (%d)\n", err); |
| 87 | } |