Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 2 | /* |
| 3 | * net/dsa/dsa_priv.h - Hardware switch handling |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 4 | * Copyright (c) 2008-2009 Marvell Semiconductor |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __DSA_PRIV_H |
| 8 | #define __DSA_PRIV_H |
| 9 | |
Vladimir Oltean | 412a152 | 2020-09-23 14:40:37 -0700 | [diff] [blame] | 10 | #include <linux/if_bridge.h> |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 11 | #include <linux/phy.h> |
Alexander Duyck | 5075314 | 2014-09-15 13:00:19 -0400 | [diff] [blame] | 12 | #include <linux/netdevice.h> |
Florian Fainelli | 04ff53f | 2015-07-31 11:42:57 -0700 | [diff] [blame] | 13 | #include <linux/netpoll.h> |
Vivien Didelot | ea5dd34 | 2017-05-17 15:46:03 -0400 | [diff] [blame] | 14 | #include <net/dsa.h> |
Alexander Lobakin | e131a56 | 2020-04-21 16:41:08 +0300 | [diff] [blame] | 15 | #include <net/gro_cells.h> |
Alexander Duyck | 5075314 | 2014-09-15 13:00:19 -0400 | [diff] [blame] | 16 | |
Vivien Didelot | 52c96f9 | 2017-05-19 17:00:51 -0400 | [diff] [blame] | 17 | enum { |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 18 | DSA_NOTIFIER_AGEING_TIME, |
Vivien Didelot | 52c96f9 | 2017-05-19 17:00:51 -0400 | [diff] [blame] | 19 | DSA_NOTIFIER_BRIDGE_JOIN, |
| 20 | DSA_NOTIFIER_BRIDGE_LEAVE, |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 21 | DSA_NOTIFIER_FDB_ADD, |
| 22 | DSA_NOTIFIER_FDB_DEL, |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 23 | DSA_NOTIFIER_LAG_CHANGE, |
| 24 | DSA_NOTIFIER_LAG_JOIN, |
| 25 | DSA_NOTIFIER_LAG_LEAVE, |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 26 | DSA_NOTIFIER_MDB_ADD, |
| 27 | DSA_NOTIFIER_MDB_DEL, |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 28 | DSA_NOTIFIER_VLAN_ADD, |
| 29 | DSA_NOTIFIER_VLAN_DEL, |
Vladimir Oltean | bfcb813 | 2020-03-27 21:55:42 +0200 | [diff] [blame] | 30 | DSA_NOTIFIER_MTU, |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 31 | DSA_NOTIFIER_TAG_PROTO, |
Vivien Didelot | 52c96f9 | 2017-05-19 17:00:51 -0400 | [diff] [blame] | 32 | }; |
| 33 | |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 34 | /* DSA_NOTIFIER_AGEING_TIME */ |
| 35 | struct dsa_notifier_ageing_time_info { |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 36 | unsigned int ageing_time; |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 37 | }; |
| 38 | |
Vivien Didelot | 52c96f9 | 2017-05-19 17:00:51 -0400 | [diff] [blame] | 39 | /* DSA_NOTIFIER_BRIDGE_* */ |
| 40 | struct dsa_notifier_bridge_info { |
| 41 | struct net_device *br; |
Vladimir Oltean | f66a6a6 | 2020-05-10 19:37:41 +0300 | [diff] [blame] | 42 | int tree_index; |
Vivien Didelot | 52c96f9 | 2017-05-19 17:00:51 -0400 | [diff] [blame] | 43 | int sw_index; |
| 44 | int port; |
| 45 | }; |
| 46 | |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 47 | /* DSA_NOTIFIER_FDB_* */ |
| 48 | struct dsa_notifier_fdb_info { |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 49 | int sw_index; |
| 50 | int port; |
Arkadi Sharshevsky | 2acf4e6 | 2017-08-06 16:15:41 +0300 | [diff] [blame] | 51 | const unsigned char *addr; |
| 52 | u16 vid; |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 53 | }; |
| 54 | |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 55 | /* DSA_NOTIFIER_MDB_* */ |
| 56 | struct dsa_notifier_mdb_info { |
| 57 | const struct switchdev_obj_port_mdb *mdb; |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 58 | int sw_index; |
| 59 | int port; |
| 60 | }; |
| 61 | |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 62 | /* DSA_NOTIFIER_LAG_* */ |
| 63 | struct dsa_notifier_lag_info { |
| 64 | struct net_device *lag; |
| 65 | int sw_index; |
| 66 | int port; |
| 67 | |
| 68 | struct netdev_lag_upper_info *info; |
| 69 | }; |
| 70 | |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 71 | /* DSA_NOTIFIER_VLAN_* */ |
| 72 | struct dsa_notifier_vlan_info { |
| 73 | const struct switchdev_obj_port_vlan *vlan; |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 74 | int sw_index; |
| 75 | int port; |
| 76 | }; |
| 77 | |
Vladimir Oltean | bfcb813 | 2020-03-27 21:55:42 +0200 | [diff] [blame] | 78 | /* DSA_NOTIFIER_MTU */ |
| 79 | struct dsa_notifier_mtu_info { |
| 80 | bool propagate_upstream; |
| 81 | int sw_index; |
| 82 | int port; |
| 83 | int mtu; |
| 84 | }; |
| 85 | |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 86 | /* DSA_NOTIFIER_TAG_PROTO_* */ |
| 87 | struct dsa_notifier_tag_proto_info { |
| 88 | const struct dsa_device_ops *tag_ops; |
| 89 | }; |
| 90 | |
Vladimir Oltean | c4bb76a | 2021-01-06 11:51:32 +0200 | [diff] [blame] | 91 | struct dsa_switchdev_event_work { |
| 92 | struct dsa_switch *ds; |
| 93 | int port; |
| 94 | struct work_struct work; |
| 95 | unsigned long event; |
| 96 | /* Specific for SWITCHDEV_FDB_ADD_TO_DEVICE and |
| 97 | * SWITCHDEV_FDB_DEL_TO_DEVICE |
| 98 | */ |
| 99 | unsigned char addr[ETH_ALEN]; |
| 100 | u16 vid; |
| 101 | }; |
| 102 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 103 | struct dsa_slave_priv { |
Vivien Didelot | 1524024 | 2017-09-29 17:19:18 -0400 | [diff] [blame] | 104 | /* Copy of CPU port xmit for faster access in slave transmit hot path */ |
Florian Fainelli | 4ed70ce | 2015-07-31 11:42:56 -0700 | [diff] [blame] | 105 | struct sk_buff * (*xmit)(struct sk_buff *skb, |
Alexander Duyck | 5075314 | 2014-09-15 13:00:19 -0400 | [diff] [blame] | 106 | struct net_device *dev); |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 107 | |
Alexander Lobakin | e131a56 | 2020-04-21 16:41:08 +0300 | [diff] [blame] | 108 | struct gro_cells gcells; |
| 109 | |
Vivien Didelot | afdcf15 | 2017-01-27 15:29:39 -0500 | [diff] [blame] | 110 | /* DSA port data, such as switch, port index, etc. */ |
| 111 | struct dsa_port *dp; |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 112 | |
Florian Fainelli | 04ff53f | 2015-07-31 11:42:57 -0700 | [diff] [blame] | 113 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 114 | struct netpoll *netpoll; |
| 115 | #endif |
Florian Fainelli | f50f212 | 2017-01-30 12:41:40 -0800 | [diff] [blame] | 116 | |
| 117 | /* TC context */ |
| 118 | struct list_head mall_tc_list; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 119 | }; |
| 120 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 121 | /* dsa.c */ |
Andrew Lunn | c39e2a1 | 2019-04-28 19:37:18 +0200 | [diff] [blame] | 122 | const struct dsa_device_ops *dsa_tag_driver_get(int tag_protocol); |
Andrew Lunn | 4dad81e | 2019-04-28 19:37:19 +0200 | [diff] [blame] | 123 | void dsa_tag_driver_put(const struct dsa_device_ops *ops); |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 124 | const struct dsa_device_ops *dsa_find_tagger_by_name(const char *buf); |
Andrew Lunn | c39e2a1 | 2019-04-28 19:37:18 +0200 | [diff] [blame] | 125 | |
Arkadi Sharshevsky | c9eb3e0 | 2017-08-06 16:15:42 +0300 | [diff] [blame] | 126 | bool dsa_schedule_work(struct work_struct *work); |
Florian Fainelli | 98cdb48 | 2018-09-07 11:09:02 -0700 | [diff] [blame] | 127 | const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 128 | |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 129 | /* master.c */ |
Vivien Didelot | 17a22fc | 2017-11-06 16:11:45 -0500 | [diff] [blame] | 130 | int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp); |
| 131 | void dsa_master_teardown(struct net_device *dev); |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 132 | |
Vivien Didelot | 2231c43 | 2017-10-16 11:12:17 -0400 | [diff] [blame] | 133 | static inline struct net_device *dsa_master_find_slave(struct net_device *dev, |
| 134 | int device, int port) |
Vivien Didelot | 3775b1b | 2017-09-29 17:19:15 -0400 | [diff] [blame] | 135 | { |
Vivien Didelot | 2f657a6 | 2017-09-29 17:19:20 -0400 | [diff] [blame] | 136 | struct dsa_port *cpu_dp = dev->dsa_ptr; |
| 137 | struct dsa_switch_tree *dst = cpu_dp->dst; |
Vivien Didelot | 7b9a2f4 | 2019-10-21 16:51:18 -0400 | [diff] [blame] | 138 | struct dsa_port *dp; |
Vivien Didelot | 3775b1b | 2017-09-29 17:19:15 -0400 | [diff] [blame] | 139 | |
Vivien Didelot | 7b9a2f4 | 2019-10-21 16:51:18 -0400 | [diff] [blame] | 140 | list_for_each_entry(dp, &dst->ports, list) |
| 141 | if (dp->ds->index == device && dp->index == port && |
| 142 | dp->type == DSA_PORT_TYPE_USER) |
| 143 | return dp->slave; |
Vivien Didelot | 3775b1b | 2017-09-29 17:19:15 -0400 | [diff] [blame] | 144 | |
Vivien Didelot | 7b9a2f4 | 2019-10-21 16:51:18 -0400 | [diff] [blame] | 145 | return NULL; |
Vivien Didelot | 3775b1b | 2017-09-29 17:19:15 -0400 | [diff] [blame] | 146 | } |
| 147 | |
Vivien Didelot | a40c175 | 2017-05-19 17:00:44 -0400 | [diff] [blame] | 148 | /* port.c */ |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 149 | void dsa_port_set_tag_protocol(struct dsa_port *cpu_dp, |
| 150 | const struct dsa_device_ops *tag_ops); |
Vladimir Oltean | bae33f2 | 2021-01-09 02:01:50 +0200 | [diff] [blame] | 151 | int dsa_port_set_state(struct dsa_port *dp, u8 state); |
Russell King | 8640f8d | 2020-03-03 15:01:46 +0000 | [diff] [blame] | 152 | int dsa_port_enable_rt(struct dsa_port *dp, struct phy_device *phy); |
Vivien Didelot | fb8a6a2 | 2017-09-22 19:01:56 -0400 | [diff] [blame] | 153 | int dsa_port_enable(struct dsa_port *dp, struct phy_device *phy); |
Russell King | 8640f8d | 2020-03-03 15:01:46 +0000 | [diff] [blame] | 154 | void dsa_port_disable_rt(struct dsa_port *dp); |
Andrew Lunn | 75104db | 2019-02-24 20:44:43 +0100 | [diff] [blame] | 155 | void dsa_port_disable(struct dsa_port *dp); |
Vivien Didelot | cfbed32 | 2017-05-19 17:00:45 -0400 | [diff] [blame] | 156 | int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br); |
| 157 | void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br); |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 158 | int dsa_port_lag_change(struct dsa_port *dp, |
| 159 | struct netdev_lag_lower_state_info *linfo); |
| 160 | int dsa_port_lag_join(struct dsa_port *dp, struct net_device *lag_dev, |
| 161 | struct netdev_lag_upper_info *uinfo); |
| 162 | void dsa_port_lag_leave(struct dsa_port *dp, struct net_device *lag_dev); |
Vladimir Oltean | bae33f2 | 2021-01-09 02:01:50 +0200 | [diff] [blame] | 163 | int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering); |
Russell King | 54a0ed0 | 2020-05-12 20:20:25 +0300 | [diff] [blame] | 164 | bool dsa_port_skip_vlan_configuration(struct dsa_port *dp); |
Vladimir Oltean | bae33f2 | 2021-01-09 02:01:50 +0200 | [diff] [blame] | 165 | int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock); |
Vladimir Oltean | bfcb813 | 2020-03-27 21:55:42 +0200 | [diff] [blame] | 166 | int dsa_port_mtu_change(struct dsa_port *dp, int new_mtu, |
| 167 | bool propagate_upstream); |
Arkadi Sharshevsky | 2acf4e6 | 2017-08-06 16:15:41 +0300 | [diff] [blame] | 168 | int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr, |
| 169 | u16 vid); |
| 170 | int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr, |
| 171 | u16 vid); |
Vivien Didelot | de40fc5 | 2017-09-20 19:32:14 -0400 | [diff] [blame] | 172 | int dsa_port_fdb_dump(struct dsa_port *dp, dsa_fdb_dump_cb_t *cb, void *data); |
Andrew Lunn | bb9f60317 | 2017-11-09 23:11:01 +0100 | [diff] [blame] | 173 | int dsa_port_mdb_add(const struct dsa_port *dp, |
Vladimir Oltean | ffb68fc | 2021-01-09 02:01:48 +0200 | [diff] [blame] | 174 | const struct switchdev_obj_port_mdb *mdb); |
Andrew Lunn | bb9f60317 | 2017-11-09 23:11:01 +0100 | [diff] [blame] | 175 | int dsa_port_mdb_del(const struct dsa_port *dp, |
Vivien Didelot | 3a9afea | 2017-05-19 17:00:49 -0400 | [diff] [blame] | 176 | const struct switchdev_obj_port_mdb *mdb); |
Vladimir Oltean | bae33f2 | 2021-01-09 02:01:50 +0200 | [diff] [blame] | 177 | int dsa_port_pre_bridge_flags(const struct dsa_port *dp, unsigned long flags); |
| 178 | int dsa_port_bridge_flags(const struct dsa_port *dp, unsigned long flags); |
| 179 | int dsa_port_mrouter(struct dsa_port *dp, bool mrouter); |
Vivien Didelot | 076e713 | 2017-05-19 17:00:50 -0400 | [diff] [blame] | 180 | int dsa_port_vlan_add(struct dsa_port *dp, |
Vladimir Oltean | ffb68fc | 2021-01-09 02:01:48 +0200 | [diff] [blame] | 181 | const struct switchdev_obj_port_vlan *vlan); |
Vivien Didelot | 076e713 | 2017-05-19 17:00:50 -0400 | [diff] [blame] | 182 | int dsa_port_vlan_del(struct dsa_port *dp, |
| 183 | const struct switchdev_obj_port_vlan *vlan); |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 184 | int dsa_port_link_register_of(struct dsa_port *dp); |
| 185 | void dsa_port_link_unregister_of(struct dsa_port *dp); |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 186 | extern const struct phylink_mac_ops dsa_port_phylink_mac_ops; |
Vivien Didelot | 57ab1ca | 2017-10-26 10:50:07 -0400 | [diff] [blame] | 187 | |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 188 | static inline bool dsa_port_offloads_netdev(struct dsa_port *dp, |
| 189 | struct net_device *dev) |
| 190 | { |
| 191 | /* Switchdev offloading can be configured on: */ |
| 192 | |
| 193 | if (dev == dp->slave) |
Vladimir Oltean | 99b8202 | 2021-02-03 01:31:09 +0200 | [diff] [blame^] | 194 | /* DSA ports directly connected to a bridge, and event |
| 195 | * was emitted for the ports themselves. |
| 196 | */ |
| 197 | return true; |
| 198 | |
| 199 | if (dp->bridge_dev == dev) |
| 200 | /* DSA ports connected to a bridge, and event was emitted |
| 201 | * for the bridge. |
| 202 | */ |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 203 | return true; |
| 204 | |
| 205 | if (dp->lag_dev == dev) |
| 206 | /* DSA ports connected to a bridge via a LAG */ |
| 207 | return true; |
| 208 | |
| 209 | return false; |
| 210 | } |
| 211 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 212 | /* slave.c */ |
Alexander Duyck | 5075314 | 2014-09-15 13:00:19 -0400 | [diff] [blame] | 213 | extern const struct dsa_device_ops notag_netdev_ops; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 214 | void dsa_slave_mii_bus_init(struct dsa_switch *ds); |
Vivien Didelot | 951259aa | 2017-10-27 15:55:19 -0400 | [diff] [blame] | 215 | int dsa_slave_create(struct dsa_port *dp); |
Neil Armstrong | cda5c15 | 2015-12-07 13:57:35 +0100 | [diff] [blame] | 216 | void dsa_slave_destroy(struct net_device *slave_dev); |
Florian Fainelli | 2446254 | 2014-09-18 17:31:22 -0700 | [diff] [blame] | 217 | int dsa_slave_suspend(struct net_device *slave_dev); |
| 218 | int dsa_slave_resume(struct net_device *slave_dev); |
Vivien Didelot | 88e4f0c | 2017-02-03 13:20:16 -0500 | [diff] [blame] | 219 | int dsa_slave_register_notifier(void); |
| 220 | void dsa_slave_unregister_notifier(void); |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 221 | void dsa_slave_setup_tagger(struct net_device *slave); |
| 222 | int dsa_slave_change_mtu(struct net_device *dev, int new_mtu); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 223 | |
Vivien Didelot | d945097 | 2017-10-16 11:12:15 -0400 | [diff] [blame] | 224 | static inline struct dsa_port *dsa_slave_to_port(const struct net_device *dev) |
| 225 | { |
| 226 | struct dsa_slave_priv *p = netdev_priv(dev); |
| 227 | |
| 228 | return p->dp; |
| 229 | } |
| 230 | |
Vivien Didelot | d0006b0 | 2017-10-16 11:12:16 -0400 | [diff] [blame] | 231 | static inline struct net_device * |
| 232 | dsa_slave_to_master(const struct net_device *dev) |
| 233 | { |
| 234 | struct dsa_port *dp = dsa_slave_to_port(dev); |
| 235 | |
Vivien Didelot | f8b8b1c | 2017-10-16 11:12:18 -0400 | [diff] [blame] | 236 | return dp->cpu_dp->master; |
Vivien Didelot | d0006b0 | 2017-10-16 11:12:16 -0400 | [diff] [blame] | 237 | } |
| 238 | |
Vladimir Oltean | 412a152 | 2020-09-23 14:40:37 -0700 | [diff] [blame] | 239 | /* If under a bridge with vlan_filtering=0, make sure to send pvid-tagged |
| 240 | * frames as untagged, since the bridge will not untag them. |
| 241 | */ |
| 242 | static inline struct sk_buff *dsa_untag_bridge_pvid(struct sk_buff *skb) |
| 243 | { |
| 244 | struct dsa_port *dp = dsa_slave_to_port(skb->dev); |
Vladimir Oltean | 412a152 | 2020-09-23 14:40:37 -0700 | [diff] [blame] | 245 | struct net_device *br = dp->bridge_dev; |
| 246 | struct net_device *dev = skb->dev; |
| 247 | struct net_device *upper_dev; |
Vladimir Oltean | 412a152 | 2020-09-23 14:40:37 -0700 | [diff] [blame] | 248 | u16 vid, pvid, proto; |
| 249 | int err; |
| 250 | |
| 251 | if (!br || br_vlan_enabled(br)) |
| 252 | return skb; |
| 253 | |
| 254 | err = br_vlan_get_proto(br, &proto); |
| 255 | if (err) |
| 256 | return skb; |
| 257 | |
| 258 | /* Move VLAN tag from data to hwaccel */ |
Florian Fainelli | a348292 | 2020-10-01 19:42:14 -0700 | [diff] [blame] | 259 | if (!skb_vlan_tag_present(skb) && skb->protocol == htons(proto)) { |
Vladimir Oltean | 412a152 | 2020-09-23 14:40:37 -0700 | [diff] [blame] | 260 | skb = skb_vlan_untag(skb); |
| 261 | if (!skb) |
| 262 | return NULL; |
| 263 | } |
| 264 | |
| 265 | if (!skb_vlan_tag_present(skb)) |
| 266 | return skb; |
| 267 | |
| 268 | vid = skb_vlan_tag_get_id(skb); |
| 269 | |
| 270 | /* We already run under an RCU read-side critical section since |
| 271 | * we are called from netif_receive_skb_list_internal(). |
| 272 | */ |
| 273 | err = br_vlan_get_pvid_rcu(dev, &pvid); |
| 274 | if (err) |
| 275 | return skb; |
| 276 | |
| 277 | if (vid != pvid) |
| 278 | return skb; |
| 279 | |
| 280 | /* The sad part about attempting to untag from DSA is that we |
| 281 | * don't know, unless we check, if the skb will end up in |
| 282 | * the bridge's data path - br_allowed_ingress() - or not. |
| 283 | * For example, there might be an 8021q upper for the |
| 284 | * default_pvid of the bridge, which will steal VLAN-tagged traffic |
| 285 | * from the bridge's data path. This is a configuration that DSA |
| 286 | * supports because vlan_filtering is 0. In that case, we should |
| 287 | * definitely keep the tag, to make sure it keeps working. |
| 288 | */ |
Florian Fainelli | 3a68844 | 2020-10-01 19:42:15 -0700 | [diff] [blame] | 289 | upper_dev = __vlan_find_dev_deep_rcu(br, htons(proto), vid); |
| 290 | if (upper_dev) |
| 291 | return skb; |
Vladimir Oltean | 412a152 | 2020-09-23 14:40:37 -0700 | [diff] [blame] | 292 | |
| 293 | __vlan_hwaccel_clear_tag(skb); |
| 294 | |
| 295 | return skb; |
| 296 | } |
| 297 | |
Vivien Didelot | f515f19 | 2017-02-03 13:20:20 -0500 | [diff] [blame] | 298 | /* switch.c */ |
| 299 | int dsa_switch_register_notifier(struct dsa_switch *ds); |
| 300 | void dsa_switch_unregister_notifier(struct dsa_switch *ds); |
Vladimir Oltean | bff33f7 | 2020-03-27 21:55:43 +0200 | [diff] [blame] | 301 | |
| 302 | /* dsa2.c */ |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 303 | void dsa_lag_map(struct dsa_switch_tree *dst, struct net_device *lag); |
| 304 | void dsa_lag_unmap(struct dsa_switch_tree *dst, struct net_device *lag); |
Vladimir Oltean | 886f8e2 | 2021-01-29 03:00:04 +0200 | [diff] [blame] | 305 | int dsa_tree_notify(struct dsa_switch_tree *dst, unsigned long e, void *v); |
| 306 | int dsa_broadcast(unsigned long e, void *v); |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 307 | int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst, |
| 308 | struct net_device *master, |
| 309 | const struct dsa_device_ops *tag_ops, |
| 310 | const struct dsa_device_ops *old_tag_ops); |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 311 | |
Vladimir Oltean | bff33f7 | 2020-03-27 21:55:43 +0200 | [diff] [blame] | 312 | extern struct list_head dsa_tree_list; |
| 313 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 314 | #endif |