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> |
Jakub Kicinski | b645941 | 2021-12-28 16:49:13 -0800 | [diff] [blame] | 11 | #include <linux/if_vlan.h> |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 12 | #include <linux/phy.h> |
Alexander Duyck | 5075314 | 2014-09-15 13:00:19 -0400 | [diff] [blame] | 13 | #include <linux/netdevice.h> |
Florian Fainelli | 04ff53f | 2015-07-31 11:42:57 -0700 | [diff] [blame] | 14 | #include <linux/netpoll.h> |
Vivien Didelot | ea5dd34 | 2017-05-17 15:46:03 -0400 | [diff] [blame] | 15 | #include <net/dsa.h> |
Alexander Lobakin | e131a56 | 2020-04-21 16:41:08 +0300 | [diff] [blame] | 16 | #include <net/gro_cells.h> |
Alexander Duyck | 5075314 | 2014-09-15 13:00:19 -0400 | [diff] [blame] | 17 | |
Vladimir Oltean | 123abc06 | 2021-07-22 18:55:40 +0300 | [diff] [blame] | 18 | #define DSA_MAX_NUM_OFFLOADING_BRIDGES BITS_PER_LONG |
| 19 | |
Vivien Didelot | 52c96f9 | 2017-05-19 17:00:51 -0400 | [diff] [blame] | 20 | enum { |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 21 | DSA_NOTIFIER_AGEING_TIME, |
Vivien Didelot | 52c96f9 | 2017-05-19 17:00:51 -0400 | [diff] [blame] | 22 | DSA_NOTIFIER_BRIDGE_JOIN, |
| 23 | DSA_NOTIFIER_BRIDGE_LEAVE, |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 24 | DSA_NOTIFIER_FDB_ADD, |
| 25 | DSA_NOTIFIER_FDB_DEL, |
Vladimir Oltean | 3dc80af | 2021-06-29 17:06:51 +0300 | [diff] [blame] | 26 | DSA_NOTIFIER_HOST_FDB_ADD, |
| 27 | DSA_NOTIFIER_HOST_FDB_DEL, |
Vladimir Oltean | e212fa7 | 2022-02-23 16:00:53 +0200 | [diff] [blame] | 28 | DSA_NOTIFIER_LAG_FDB_ADD, |
| 29 | DSA_NOTIFIER_LAG_FDB_DEL, |
Tobias Waldekranz | 058102a6 | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 30 | DSA_NOTIFIER_LAG_CHANGE, |
| 31 | DSA_NOTIFIER_LAG_JOIN, |
| 32 | DSA_NOTIFIER_LAG_LEAVE, |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 33 | DSA_NOTIFIER_MDB_ADD, |
| 34 | DSA_NOTIFIER_MDB_DEL, |
Vladimir Oltean | b8e997c | 2021-06-29 17:06:49 +0300 | [diff] [blame] | 35 | DSA_NOTIFIER_HOST_MDB_ADD, |
| 36 | DSA_NOTIFIER_HOST_MDB_DEL, |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 37 | DSA_NOTIFIER_VLAN_ADD, |
| 38 | DSA_NOTIFIER_VLAN_DEL, |
Vladimir Oltean | 134ef23 | 2022-02-15 19:02:17 +0200 | [diff] [blame] | 39 | DSA_NOTIFIER_HOST_VLAN_ADD, |
| 40 | DSA_NOTIFIER_HOST_VLAN_DEL, |
Vladimir Oltean | bfcb813 | 2020-03-27 21:55:42 +0200 | [diff] [blame] | 41 | DSA_NOTIFIER_MTU, |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 42 | DSA_NOTIFIER_TAG_PROTO, |
Vladimir Oltean | dc452a4 | 2021-12-10 01:34:37 +0200 | [diff] [blame] | 43 | DSA_NOTIFIER_TAG_PROTO_CONNECT, |
Vladimir Oltean | 7f29731 | 2021-12-14 03:45:36 +0200 | [diff] [blame] | 44 | DSA_NOTIFIER_TAG_PROTO_DISCONNECT, |
Vladimir Oltean | c64b9c0 | 2021-07-19 20:14:52 +0300 | [diff] [blame] | 45 | DSA_NOTIFIER_TAG_8021Q_VLAN_ADD, |
| 46 | DSA_NOTIFIER_TAG_8021Q_VLAN_DEL, |
Vladimir Oltean | 295ab96 | 2022-02-02 01:03:20 +0100 | [diff] [blame] | 47 | DSA_NOTIFIER_MASTER_STATE_CHANGE, |
Vivien Didelot | 52c96f9 | 2017-05-19 17:00:51 -0400 | [diff] [blame] | 48 | }; |
| 49 | |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 50 | /* DSA_NOTIFIER_AGEING_TIME */ |
| 51 | struct dsa_notifier_ageing_time_info { |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 52 | unsigned int ageing_time; |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 53 | }; |
| 54 | |
Vivien Didelot | 52c96f9 | 2017-05-19 17:00:51 -0400 | [diff] [blame] | 55 | /* DSA_NOTIFIER_BRIDGE_* */ |
| 56 | struct dsa_notifier_bridge_info { |
Vladimir Oltean | 726816a | 2022-04-15 18:46:22 +0300 | [diff] [blame] | 57 | const struct dsa_port *dp; |
Vladimir Oltean | d3eed0e | 2021-12-06 18:57:56 +0200 | [diff] [blame] | 58 | struct dsa_bridge bridge; |
Vladimir Oltean | b079922 | 2021-12-06 18:57:57 +0200 | [diff] [blame] | 59 | bool tx_fwd_offload; |
Vladimir Oltean | 06b9cce | 2022-02-25 11:22:23 +0200 | [diff] [blame] | 60 | struct netlink_ext_ack *extack; |
Vivien Didelot | 52c96f9 | 2017-05-19 17:00:51 -0400 | [diff] [blame] | 61 | }; |
| 62 | |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 63 | /* DSA_NOTIFIER_FDB_* */ |
| 64 | struct dsa_notifier_fdb_info { |
Vladimir Oltean | 726816a | 2022-04-15 18:46:22 +0300 | [diff] [blame] | 65 | const struct dsa_port *dp; |
Arkadi Sharshevsky | 2acf4e6 | 2017-08-06 16:15:41 +0300 | [diff] [blame] | 66 | const unsigned char *addr; |
| 67 | u16 vid; |
Vladimir Oltean | c269336 | 2022-02-25 11:22:22 +0200 | [diff] [blame] | 68 | struct dsa_db db; |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 69 | }; |
| 70 | |
Vladimir Oltean | e212fa7 | 2022-02-23 16:00:53 +0200 | [diff] [blame] | 71 | /* DSA_NOTIFIER_LAG_FDB_* */ |
| 72 | struct dsa_notifier_lag_fdb_info { |
| 73 | struct dsa_lag *lag; |
| 74 | const unsigned char *addr; |
| 75 | u16 vid; |
Vladimir Oltean | c269336 | 2022-02-25 11:22:22 +0200 | [diff] [blame] | 76 | struct dsa_db db; |
Vladimir Oltean | e212fa7 | 2022-02-23 16:00:53 +0200 | [diff] [blame] | 77 | }; |
| 78 | |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 79 | /* DSA_NOTIFIER_MDB_* */ |
| 80 | struct dsa_notifier_mdb_info { |
Vladimir Oltean | 726816a | 2022-04-15 18:46:22 +0300 | [diff] [blame] | 81 | const struct dsa_port *dp; |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 82 | const struct switchdev_obj_port_mdb *mdb; |
Vladimir Oltean | c269336 | 2022-02-25 11:22:22 +0200 | [diff] [blame] | 83 | struct dsa_db db; |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 84 | }; |
| 85 | |
Tobias Waldekranz | 058102a6 | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 86 | /* DSA_NOTIFIER_LAG_* */ |
| 87 | struct dsa_notifier_lag_info { |
Vladimir Oltean | 726816a | 2022-04-15 18:46:22 +0300 | [diff] [blame] | 88 | const struct dsa_port *dp; |
Vladimir Oltean | dedd6a0 | 2022-02-23 16:00:49 +0200 | [diff] [blame] | 89 | struct dsa_lag lag; |
Tobias Waldekranz | 058102a6 | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 90 | struct netdev_lag_upper_info *info; |
Vladimir Oltean | 2e359b0 | 2022-09-11 04:07:03 +0300 | [diff] [blame] | 91 | struct netlink_ext_ack *extack; |
Tobias Waldekranz | 058102a6 | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 92 | }; |
| 93 | |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 94 | /* DSA_NOTIFIER_VLAN_* */ |
| 95 | struct dsa_notifier_vlan_info { |
Vladimir Oltean | 726816a | 2022-04-15 18:46:22 +0300 | [diff] [blame] | 96 | const struct dsa_port *dp; |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 97 | const struct switchdev_obj_port_vlan *vlan; |
Vladimir Oltean | 31046a5 | 2021-02-13 22:43:18 +0200 | [diff] [blame] | 98 | struct netlink_ext_ack *extack; |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 99 | }; |
| 100 | |
Vladimir Oltean | bfcb813 | 2020-03-27 21:55:42 +0200 | [diff] [blame] | 101 | /* DSA_NOTIFIER_MTU */ |
| 102 | struct dsa_notifier_mtu_info { |
Vladimir Oltean | 726816a | 2022-04-15 18:46:22 +0300 | [diff] [blame] | 103 | const struct dsa_port *dp; |
Vladimir Oltean | bfcb813 | 2020-03-27 21:55:42 +0200 | [diff] [blame] | 104 | int mtu; |
| 105 | }; |
| 106 | |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 107 | /* DSA_NOTIFIER_TAG_PROTO_* */ |
| 108 | struct dsa_notifier_tag_proto_info { |
| 109 | const struct dsa_device_ops *tag_ops; |
| 110 | }; |
| 111 | |
Vladimir Oltean | c64b9c0 | 2021-07-19 20:14:52 +0300 | [diff] [blame] | 112 | /* DSA_NOTIFIER_TAG_8021Q_VLAN_* */ |
| 113 | struct dsa_notifier_tag_8021q_vlan_info { |
Vladimir Oltean | 726816a | 2022-04-15 18:46:22 +0300 | [diff] [blame] | 114 | const struct dsa_port *dp; |
Vladimir Oltean | c64b9c0 | 2021-07-19 20:14:52 +0300 | [diff] [blame] | 115 | u16 vid; |
| 116 | }; |
| 117 | |
Vladimir Oltean | 295ab96 | 2022-02-02 01:03:20 +0100 | [diff] [blame] | 118 | /* DSA_NOTIFIER_MASTER_STATE_CHANGE */ |
| 119 | struct dsa_notifier_master_state_info { |
| 120 | const struct net_device *master; |
| 121 | bool operational; |
| 122 | }; |
| 123 | |
Vladimir Oltean | c4bb76a | 2021-01-06 11:51:32 +0200 | [diff] [blame] | 124 | struct dsa_switchdev_event_work { |
Vladimir Oltean | 4bed397 | 2021-06-29 17:06:57 +0300 | [diff] [blame] | 125 | struct net_device *dev; |
Vladimir Oltean | 93c7982 | 2022-02-23 16:00:52 +0200 | [diff] [blame] | 126 | struct net_device *orig_dev; |
Vladimir Oltean | c4bb76a | 2021-01-06 11:51:32 +0200 | [diff] [blame] | 127 | struct work_struct work; |
| 128 | unsigned long event; |
| 129 | /* Specific for SWITCHDEV_FDB_ADD_TO_DEVICE and |
| 130 | * SWITCHDEV_FDB_DEL_TO_DEVICE |
| 131 | */ |
| 132 | unsigned char addr[ETH_ALEN]; |
| 133 | u16 vid; |
Vladimir Oltean | 3dc80af | 2021-06-29 17:06:51 +0300 | [diff] [blame] | 134 | bool host_addr; |
Vladimir Oltean | c4bb76a | 2021-01-06 11:51:32 +0200 | [diff] [blame] | 135 | }; |
| 136 | |
Vladimir Oltean | 5e8a1e0 | 2022-03-02 21:14:10 +0200 | [diff] [blame] | 137 | enum dsa_standalone_event { |
| 138 | DSA_UC_ADD, |
| 139 | DSA_UC_DEL, |
| 140 | DSA_MC_ADD, |
| 141 | DSA_MC_DEL, |
| 142 | }; |
| 143 | |
| 144 | struct dsa_standalone_event_work { |
| 145 | struct work_struct work; |
| 146 | struct net_device *dev; |
| 147 | enum dsa_standalone_event event; |
| 148 | unsigned char addr[ETH_ALEN]; |
| 149 | u16 vid; |
| 150 | }; |
| 151 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 152 | struct dsa_slave_priv { |
Vivien Didelot | 1524024 | 2017-09-29 17:19:18 -0400 | [diff] [blame] | 153 | /* 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] | 154 | struct sk_buff * (*xmit)(struct sk_buff *skb, |
Alexander Duyck | 5075314 | 2014-09-15 13:00:19 -0400 | [diff] [blame] | 155 | struct net_device *dev); |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 156 | |
Alexander Lobakin | e131a56 | 2020-04-21 16:41:08 +0300 | [diff] [blame] | 157 | struct gro_cells gcells; |
| 158 | |
Vivien Didelot | afdcf15 | 2017-01-27 15:29:39 -0500 | [diff] [blame] | 159 | /* DSA port data, such as switch, port index, etc. */ |
| 160 | struct dsa_port *dp; |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 161 | |
Florian Fainelli | 04ff53f | 2015-07-31 11:42:57 -0700 | [diff] [blame] | 162 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 163 | struct netpoll *netpoll; |
| 164 | #endif |
Florian Fainelli | f50f212 | 2017-01-30 12:41:40 -0800 | [diff] [blame] | 165 | |
| 166 | /* TC context */ |
| 167 | struct list_head mall_tc_list; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 168 | }; |
| 169 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 170 | /* dsa.c */ |
Andrew Lunn | c39e2a1 | 2019-04-28 19:37:18 +0200 | [diff] [blame] | 171 | const struct dsa_device_ops *dsa_tag_driver_get(int tag_protocol); |
Andrew Lunn | 4dad81e | 2019-04-28 19:37:19 +0200 | [diff] [blame] | 172 | void dsa_tag_driver_put(const struct dsa_device_ops *ops); |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 173 | 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] | 174 | |
Vladimir Oltean | 7e58049 | 2022-03-08 11:15:15 +0200 | [diff] [blame] | 175 | bool dsa_db_equal(const struct dsa_db *a, const struct dsa_db *b); |
| 176 | |
Arkadi Sharshevsky | c9eb3e0 | 2017-08-06 16:15:42 +0300 | [diff] [blame] | 177 | bool dsa_schedule_work(struct work_struct *work); |
Florian Fainelli | 98cdb48 | 2018-09-07 11:09:02 -0700 | [diff] [blame] | 178 | 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] | 179 | |
Vladimir Oltean | 4e50025 | 2021-06-11 22:01:24 +0300 | [diff] [blame] | 180 | static inline int dsa_tag_protocol_overhead(const struct dsa_device_ops *ops) |
| 181 | { |
| 182 | return ops->needed_headroom + ops->needed_tailroom; |
| 183 | } |
| 184 | |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 185 | /* master.c */ |
Vivien Didelot | 17a22fc | 2017-11-06 16:11:45 -0500 | [diff] [blame] | 186 | int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp); |
| 187 | void dsa_master_teardown(struct net_device *dev); |
Vladimir Oltean | acc43b7 | 2022-09-11 04:07:04 +0300 | [diff] [blame] | 188 | int dsa_master_lag_setup(struct net_device *lag_dev, struct dsa_port *cpu_dp, |
| 189 | struct netdev_lag_upper_info *uinfo, |
| 190 | struct netlink_ext_ack *extack); |
| 191 | void dsa_master_lag_teardown(struct net_device *lag_dev, |
| 192 | struct dsa_port *cpu_dp); |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 193 | |
Vivien Didelot | 2231c43 | 2017-10-16 11:12:17 -0400 | [diff] [blame] | 194 | static inline struct net_device *dsa_master_find_slave(struct net_device *dev, |
| 195 | int device, int port) |
Vivien Didelot | 3775b1b | 2017-09-29 17:19:15 -0400 | [diff] [blame] | 196 | { |
Vivien Didelot | 2f657a6 | 2017-09-29 17:19:20 -0400 | [diff] [blame] | 197 | struct dsa_port *cpu_dp = dev->dsa_ptr; |
| 198 | struct dsa_switch_tree *dst = cpu_dp->dst; |
Vivien Didelot | 7b9a2f4 | 2019-10-21 16:51:18 -0400 | [diff] [blame] | 199 | struct dsa_port *dp; |
Vivien Didelot | 3775b1b | 2017-09-29 17:19:15 -0400 | [diff] [blame] | 200 | |
Vivien Didelot | 7b9a2f4 | 2019-10-21 16:51:18 -0400 | [diff] [blame] | 201 | list_for_each_entry(dp, &dst->ports, list) |
| 202 | if (dp->ds->index == device && dp->index == port && |
| 203 | dp->type == DSA_PORT_TYPE_USER) |
| 204 | return dp->slave; |
Vivien Didelot | 3775b1b | 2017-09-29 17:19:15 -0400 | [diff] [blame] | 205 | |
Vivien Didelot | 7b9a2f4 | 2019-10-21 16:51:18 -0400 | [diff] [blame] | 206 | return NULL; |
Vivien Didelot | 3775b1b | 2017-09-29 17:19:15 -0400 | [diff] [blame] | 207 | } |
| 208 | |
Vladimir Oltean | 95f510d | 2022-09-11 04:06:59 +0300 | [diff] [blame] | 209 | /* netlink.c */ |
| 210 | extern struct rtnl_link_ops dsa_link_ops __read_mostly; |
| 211 | |
Vivien Didelot | a40c175 | 2017-05-19 17:00:44 -0400 | [diff] [blame] | 212 | /* port.c */ |
Vladimir Oltean | ed1fe1b | 2022-11-11 23:10:20 +0200 | [diff] [blame] | 213 | bool dsa_port_supports_hwtstamp(struct dsa_port *dp, struct ifreq *ifr); |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 214 | void dsa_port_set_tag_protocol(struct dsa_port *cpu_dp, |
| 215 | const struct dsa_device_ops *tag_ops); |
Vladimir Oltean | 39f3210 | 2021-08-08 14:16:37 +0300 | [diff] [blame] | 216 | int dsa_port_set_state(struct dsa_port *dp, u8 state, bool do_fast_age); |
Tobias Waldekranz | 7414af3 | 2022-03-16 16:08:54 +0100 | [diff] [blame] | 217 | int dsa_port_set_mst_state(struct dsa_port *dp, |
| 218 | const struct switchdev_mst_state *state, |
| 219 | struct netlink_ext_ack *extack); |
Russell King | 8640f8d | 2020-03-03 15:01:46 +0000 | [diff] [blame] | 220 | 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] | 221 | int dsa_port_enable(struct dsa_port *dp, struct phy_device *phy); |
Russell King | 8640f8d | 2020-03-03 15:01:46 +0000 | [diff] [blame] | 222 | void dsa_port_disable_rt(struct dsa_port *dp); |
Andrew Lunn | 75104db | 2019-02-24 20:44:43 +0100 | [diff] [blame] | 223 | void dsa_port_disable(struct dsa_port *dp); |
Vladimir Oltean | 2afc526 | 2021-03-23 01:51:48 +0200 | [diff] [blame] | 224 | int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br, |
| 225 | struct netlink_ext_ack *extack); |
Vladimir Oltean | 4e51bf4 | 2021-07-21 19:24:03 +0300 | [diff] [blame] | 226 | void dsa_port_pre_bridge_leave(struct dsa_port *dp, struct net_device *br); |
Vivien Didelot | cfbed32 | 2017-05-19 17:00:45 -0400 | [diff] [blame] | 227 | void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br); |
Tobias Waldekranz | 058102a6 | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 228 | int dsa_port_lag_change(struct dsa_port *dp, |
| 229 | struct netdev_lag_lower_state_info *linfo); |
| 230 | int dsa_port_lag_join(struct dsa_port *dp, struct net_device *lag_dev, |
Vladimir Oltean | 2afc526 | 2021-03-23 01:51:48 +0200 | [diff] [blame] | 231 | struct netdev_lag_upper_info *uinfo, |
| 232 | struct netlink_ext_ack *extack); |
Vladimir Oltean | 4e51bf4 | 2021-07-21 19:24:03 +0300 | [diff] [blame] | 233 | void dsa_port_pre_lag_leave(struct dsa_port *dp, struct net_device *lag_dev); |
Tobias Waldekranz | 058102a6 | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 234 | void dsa_port_lag_leave(struct dsa_port *dp, struct net_device *lag_dev); |
Vladimir Oltean | 89153ed | 2021-02-13 22:43:19 +0200 | [diff] [blame] | 235 | int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering, |
| 236 | struct netlink_ext_ack *extack); |
Russell King | 54a0ed0 | 2020-05-12 20:20:25 +0300 | [diff] [blame] | 237 | bool dsa_port_skip_vlan_configuration(struct dsa_port *dp); |
Vladimir Oltean | bae33f2 | 2021-01-09 02:01:50 +0200 | [diff] [blame] | 238 | int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock); |
Tobias Waldekranz | 332afc4 | 2022-03-16 16:08:52 +0100 | [diff] [blame] | 239 | int dsa_port_mst_enable(struct dsa_port *dp, bool on, |
| 240 | struct netlink_ext_ack *extack); |
Tobias Waldekranz | 8e6598a7 | 2022-03-16 16:08:53 +0100 | [diff] [blame] | 241 | int dsa_port_vlan_msti(struct dsa_port *dp, |
| 242 | const struct switchdev_vlan_msti *msti); |
Vladimir Oltean | be6ff966 | 2022-04-15 18:46:26 +0300 | [diff] [blame] | 243 | int dsa_port_mtu_change(struct dsa_port *dp, int new_mtu); |
Arkadi Sharshevsky | 2acf4e6 | 2017-08-06 16:15:41 +0300 | [diff] [blame] | 244 | int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr, |
| 245 | u16 vid); |
| 246 | int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr, |
| 247 | u16 vid); |
Vladimir Oltean | 5e8a1e0 | 2022-03-02 21:14:10 +0200 | [diff] [blame] | 248 | int dsa_port_standalone_host_fdb_add(struct dsa_port *dp, |
| 249 | const unsigned char *addr, u16 vid); |
| 250 | int dsa_port_standalone_host_fdb_del(struct dsa_port *dp, |
| 251 | const unsigned char *addr, u16 vid); |
Vladimir Oltean | 68d6d71 | 2022-03-02 21:14:09 +0200 | [diff] [blame] | 252 | int dsa_port_bridge_host_fdb_add(struct dsa_port *dp, const unsigned char *addr, |
| 253 | u16 vid); |
| 254 | int dsa_port_bridge_host_fdb_del(struct dsa_port *dp, const unsigned char *addr, |
| 255 | u16 vid); |
Vladimir Oltean | e212fa7 | 2022-02-23 16:00:53 +0200 | [diff] [blame] | 256 | int dsa_port_lag_fdb_add(struct dsa_port *dp, const unsigned char *addr, |
| 257 | u16 vid); |
| 258 | int dsa_port_lag_fdb_del(struct dsa_port *dp, const unsigned char *addr, |
| 259 | u16 vid); |
Vivien Didelot | de40fc5 | 2017-09-20 19:32:14 -0400 | [diff] [blame] | 260 | 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] | 261 | int dsa_port_mdb_add(const struct dsa_port *dp, |
Vladimir Oltean | ffb68fc | 2021-01-09 02:01:48 +0200 | [diff] [blame] | 262 | const struct switchdev_obj_port_mdb *mdb); |
Andrew Lunn | bb9f60317 | 2017-11-09 23:11:01 +0100 | [diff] [blame] | 263 | int dsa_port_mdb_del(const struct dsa_port *dp, |
Vivien Didelot | 3a9afea | 2017-05-19 17:00:49 -0400 | [diff] [blame] | 264 | const struct switchdev_obj_port_mdb *mdb); |
Vladimir Oltean | 5e8a1e0 | 2022-03-02 21:14:10 +0200 | [diff] [blame] | 265 | int dsa_port_standalone_host_mdb_add(const struct dsa_port *dp, |
| 266 | const struct switchdev_obj_port_mdb *mdb); |
| 267 | int dsa_port_standalone_host_mdb_del(const struct dsa_port *dp, |
| 268 | const struct switchdev_obj_port_mdb *mdb); |
Vladimir Oltean | 68d6d71 | 2022-03-02 21:14:09 +0200 | [diff] [blame] | 269 | int dsa_port_bridge_host_mdb_add(const struct dsa_port *dp, |
| 270 | const struct switchdev_obj_port_mdb *mdb); |
| 271 | int dsa_port_bridge_host_mdb_del(const struct dsa_port *dp, |
| 272 | const struct switchdev_obj_port_mdb *mdb); |
Vladimir Oltean | e18f4c1 | 2021-02-12 17:15:55 +0200 | [diff] [blame] | 273 | int dsa_port_pre_bridge_flags(const struct dsa_port *dp, |
Vladimir Oltean | a8b659e | 2021-02-12 17:15:56 +0200 | [diff] [blame] | 274 | struct switchdev_brport_flags flags, |
| 275 | struct netlink_ext_ack *extack); |
Vladimir Oltean | 045c45d | 2021-08-08 17:35:23 +0300 | [diff] [blame] | 276 | int dsa_port_bridge_flags(struct dsa_port *dp, |
Vladimir Oltean | a8b659e | 2021-02-12 17:15:56 +0200 | [diff] [blame] | 277 | struct switchdev_brport_flags flags, |
| 278 | struct netlink_ext_ack *extack); |
Vivien Didelot | 076e713 | 2017-05-19 17:00:50 -0400 | [diff] [blame] | 279 | int dsa_port_vlan_add(struct dsa_port *dp, |
Vladimir Oltean | 31046a5 | 2021-02-13 22:43:18 +0200 | [diff] [blame] | 280 | const struct switchdev_obj_port_vlan *vlan, |
| 281 | struct netlink_ext_ack *extack); |
Vivien Didelot | 076e713 | 2017-05-19 17:00:50 -0400 | [diff] [blame] | 282 | int dsa_port_vlan_del(struct dsa_port *dp, |
| 283 | const struct switchdev_obj_port_vlan *vlan); |
Vladimir Oltean | 134ef23 | 2022-02-15 19:02:17 +0200 | [diff] [blame] | 284 | int dsa_port_host_vlan_add(struct dsa_port *dp, |
| 285 | const struct switchdev_obj_port_vlan *vlan, |
| 286 | struct netlink_ext_ack *extack); |
| 287 | int dsa_port_host_vlan_del(struct dsa_port *dp, |
| 288 | const struct switchdev_obj_port_vlan *vlan); |
Horatiu Vultur | c595c43 | 2021-02-16 22:42:04 +0100 | [diff] [blame] | 289 | int dsa_port_mrp_add(const struct dsa_port *dp, |
| 290 | const struct switchdev_obj_mrp *mrp); |
| 291 | int dsa_port_mrp_del(const struct dsa_port *dp, |
| 292 | const struct switchdev_obj_mrp *mrp); |
| 293 | int dsa_port_mrp_add_ring_role(const struct dsa_port *dp, |
| 294 | const struct switchdev_obj_ring_role_mrp *mrp); |
| 295 | int dsa_port_mrp_del_ring_role(const struct dsa_port *dp, |
| 296 | const struct switchdev_obj_ring_role_mrp *mrp); |
Russell King (Oracle) | 21bd64b | 2021-11-30 13:09:55 +0000 | [diff] [blame] | 297 | int dsa_port_phylink_create(struct dsa_port *dp); |
Vladimir Oltean | cf5ca4d | 2022-09-29 09:29:00 +0200 | [diff] [blame] | 298 | void dsa_port_phylink_destroy(struct dsa_port *dp); |
Vladimir Oltean | 770375f | 2022-08-18 14:54:59 +0300 | [diff] [blame] | 299 | int dsa_shared_port_link_register_of(struct dsa_port *dp); |
| 300 | void dsa_shared_port_link_unregister_of(struct dsa_port *dp); |
George McCollister | 18596f5 | 2021-02-09 19:02:12 -0600 | [diff] [blame] | 301 | int dsa_port_hsr_join(struct dsa_port *dp, struct net_device *hsr); |
| 302 | void dsa_port_hsr_leave(struct dsa_port *dp, struct net_device *hsr); |
Vladimir Oltean | 724395f | 2021-08-11 16:46:06 +0300 | [diff] [blame] | 303 | int dsa_port_tag_8021q_vlan_add(struct dsa_port *dp, u16 vid, bool broadcast); |
| 304 | void dsa_port_tag_8021q_vlan_del(struct dsa_port *dp, u16 vid, bool broadcast); |
Vladimir Oltean | 72c3b0c | 2022-05-11 12:50:17 +0300 | [diff] [blame] | 305 | void dsa_port_set_host_flood(struct dsa_port *dp, bool uc, bool mc); |
Vladimir Oltean | 95f510d | 2022-09-11 04:06:59 +0300 | [diff] [blame] | 306 | int dsa_port_change_master(struct dsa_port *dp, struct net_device *master, |
| 307 | struct netlink_ext_ack *extack); |
Vivien Didelot | 57ab1ca | 2017-10-26 10:50:07 -0400 | [diff] [blame] | 308 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 309 | /* slave.c */ |
Alexander Duyck | 5075314 | 2014-09-15 13:00:19 -0400 | [diff] [blame] | 310 | extern const struct dsa_device_ops notag_netdev_ops; |
Vladimir Oltean | 010e269 | 2021-03-23 01:51:50 +0200 | [diff] [blame] | 311 | extern struct notifier_block dsa_slave_switchdev_notifier; |
| 312 | extern struct notifier_block dsa_slave_switchdev_blocking_notifier; |
| 313 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 314 | void dsa_slave_mii_bus_init(struct dsa_switch *ds); |
Vivien Didelot | 951259aa | 2017-10-27 15:55:19 -0400 | [diff] [blame] | 315 | int dsa_slave_create(struct dsa_port *dp); |
Neil Armstrong | cda5c15 | 2015-12-07 13:57:35 +0100 | [diff] [blame] | 316 | void dsa_slave_destroy(struct net_device *slave_dev); |
Florian Fainelli | 2446254 | 2014-09-18 17:31:22 -0700 | [diff] [blame] | 317 | int dsa_slave_suspend(struct net_device *slave_dev); |
| 318 | int dsa_slave_resume(struct net_device *slave_dev); |
Vivien Didelot | 88e4f0c | 2017-02-03 13:20:16 -0500 | [diff] [blame] | 319 | int dsa_slave_register_notifier(void); |
| 320 | void dsa_slave_unregister_notifier(void); |
Vladimir Oltean | 95f510d | 2022-09-11 04:06:59 +0300 | [diff] [blame] | 321 | void dsa_slave_sync_ha(struct net_device *dev); |
| 322 | void dsa_slave_unsync_ha(struct net_device *dev); |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 323 | void dsa_slave_setup_tagger(struct net_device *slave); |
| 324 | int dsa_slave_change_mtu(struct net_device *dev, int new_mtu); |
Vladimir Oltean | 95f510d | 2022-09-11 04:06:59 +0300 | [diff] [blame] | 325 | int dsa_slave_change_master(struct net_device *dev, struct net_device *master, |
| 326 | struct netlink_ext_ack *extack); |
Vladimir Oltean | 06cfb2d | 2021-08-24 00:22:57 +0300 | [diff] [blame] | 327 | int dsa_slave_manage_vlan_filtering(struct net_device *dev, |
| 328 | bool vlan_filtering); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 329 | |
Vivien Didelot | d945097 | 2017-10-16 11:12:15 -0400 | [diff] [blame] | 330 | static inline struct dsa_port *dsa_slave_to_port(const struct net_device *dev) |
| 331 | { |
| 332 | struct dsa_slave_priv *p = netdev_priv(dev); |
| 333 | |
| 334 | return p->dp; |
| 335 | } |
| 336 | |
Vivien Didelot | d0006b0 | 2017-10-16 11:12:16 -0400 | [diff] [blame] | 337 | static inline struct net_device * |
| 338 | dsa_slave_to_master(const struct net_device *dev) |
| 339 | { |
| 340 | struct dsa_port *dp = dsa_slave_to_port(dev); |
| 341 | |
Vladimir Oltean | 8f6a19c | 2022-09-11 04:06:58 +0300 | [diff] [blame] | 342 | return dsa_port_to_master(dp); |
Vivien Didelot | d0006b0 | 2017-10-16 11:12:16 -0400 | [diff] [blame] | 343 | } |
| 344 | |
Vladimir Oltean | 412a152 | 2020-09-23 14:40:37 -0700 | [diff] [blame] | 345 | /* If under a bridge with vlan_filtering=0, make sure to send pvid-tagged |
| 346 | * frames as untagged, since the bridge will not untag them. |
| 347 | */ |
| 348 | static inline struct sk_buff *dsa_untag_bridge_pvid(struct sk_buff *skb) |
| 349 | { |
| 350 | struct dsa_port *dp = dsa_slave_to_port(skb->dev); |
Vladimir Oltean | 36cbf39 | 2021-12-06 18:57:52 +0200 | [diff] [blame] | 351 | struct net_device *br = dsa_port_bridge_dev_get(dp); |
Vladimir Oltean | 412a152 | 2020-09-23 14:40:37 -0700 | [diff] [blame] | 352 | struct net_device *dev = skb->dev; |
| 353 | struct net_device *upper_dev; |
Vladimir Oltean | 412a152 | 2020-09-23 14:40:37 -0700 | [diff] [blame] | 354 | u16 vid, pvid, proto; |
| 355 | int err; |
| 356 | |
| 357 | if (!br || br_vlan_enabled(br)) |
| 358 | return skb; |
| 359 | |
| 360 | err = br_vlan_get_proto(br, &proto); |
| 361 | if (err) |
| 362 | return skb; |
| 363 | |
| 364 | /* Move VLAN tag from data to hwaccel */ |
Florian Fainelli | a348292 | 2020-10-01 19:42:14 -0700 | [diff] [blame] | 365 | if (!skb_vlan_tag_present(skb) && skb->protocol == htons(proto)) { |
Vladimir Oltean | 412a152 | 2020-09-23 14:40:37 -0700 | [diff] [blame] | 366 | skb = skb_vlan_untag(skb); |
| 367 | if (!skb) |
| 368 | return NULL; |
| 369 | } |
| 370 | |
| 371 | if (!skb_vlan_tag_present(skb)) |
| 372 | return skb; |
| 373 | |
| 374 | vid = skb_vlan_tag_get_id(skb); |
| 375 | |
| 376 | /* We already run under an RCU read-side critical section since |
| 377 | * we are called from netif_receive_skb_list_internal(). |
| 378 | */ |
| 379 | err = br_vlan_get_pvid_rcu(dev, &pvid); |
| 380 | if (err) |
| 381 | return skb; |
| 382 | |
| 383 | if (vid != pvid) |
| 384 | return skb; |
| 385 | |
| 386 | /* The sad part about attempting to untag from DSA is that we |
| 387 | * don't know, unless we check, if the skb will end up in |
| 388 | * the bridge's data path - br_allowed_ingress() - or not. |
| 389 | * For example, there might be an 8021q upper for the |
| 390 | * default_pvid of the bridge, which will steal VLAN-tagged traffic |
| 391 | * from the bridge's data path. This is a configuration that DSA |
| 392 | * supports because vlan_filtering is 0. In that case, we should |
| 393 | * definitely keep the tag, to make sure it keeps working. |
| 394 | */ |
Florian Fainelli | 3a68844 | 2020-10-01 19:42:15 -0700 | [diff] [blame] | 395 | upper_dev = __vlan_find_dev_deep_rcu(br, htons(proto), vid); |
| 396 | if (upper_dev) |
| 397 | return skb; |
Vladimir Oltean | 412a152 | 2020-09-23 14:40:37 -0700 | [diff] [blame] | 398 | |
| 399 | __vlan_hwaccel_clear_tag(skb); |
| 400 | |
| 401 | return skb; |
| 402 | } |
| 403 | |
Vladimir Oltean | 884be12 | 2021-07-26 19:55:34 +0300 | [diff] [blame] | 404 | /* For switches without hardware support for DSA tagging to be able |
| 405 | * to support termination through the bridge. |
| 406 | */ |
| 407 | static inline struct net_device * |
| 408 | dsa_find_designated_bridge_port_by_vid(struct net_device *master, u16 vid) |
| 409 | { |
| 410 | struct dsa_port *cpu_dp = master->dsa_ptr; |
| 411 | struct dsa_switch_tree *dst = cpu_dp->dst; |
| 412 | struct bridge_vlan_info vinfo; |
| 413 | struct net_device *slave; |
| 414 | struct dsa_port *dp; |
| 415 | int err; |
| 416 | |
| 417 | list_for_each_entry(dp, &dst->ports, list) { |
| 418 | if (dp->type != DSA_PORT_TYPE_USER) |
| 419 | continue; |
| 420 | |
Vladimir Oltean | d3eed0e | 2021-12-06 18:57:56 +0200 | [diff] [blame] | 421 | if (!dp->bridge) |
Vladimir Oltean | 884be12 | 2021-07-26 19:55:34 +0300 | [diff] [blame] | 422 | continue; |
| 423 | |
| 424 | if (dp->stp_state != BR_STATE_LEARNING && |
| 425 | dp->stp_state != BR_STATE_FORWARDING) |
| 426 | continue; |
| 427 | |
| 428 | /* Since the bridge might learn this packet, keep the CPU port |
| 429 | * affinity with the port that will be used for the reply on |
| 430 | * xmit. |
| 431 | */ |
| 432 | if (dp->cpu_dp != cpu_dp) |
| 433 | continue; |
| 434 | |
| 435 | slave = dp->slave; |
| 436 | |
| 437 | err = br_vlan_get_info_rcu(slave, vid, &vinfo); |
| 438 | if (err) |
| 439 | continue; |
| 440 | |
| 441 | return slave; |
| 442 | } |
| 443 | |
| 444 | return NULL; |
| 445 | } |
| 446 | |
Vladimir Oltean | bea7907 | 2021-07-29 17:56:00 +0300 | [diff] [blame] | 447 | /* If the ingress port offloads the bridge, we mark the frame as autonomously |
| 448 | * forwarded by hardware, so the software bridge doesn't forward in twice, back |
| 449 | * to us, because we already did. However, if we're in fallback mode and we do |
Vladimir Oltean | d3eed0e | 2021-12-06 18:57:56 +0200 | [diff] [blame] | 450 | * software bridging, we are not offloading it, therefore the dp->bridge |
Vladimir Oltean | bea7907 | 2021-07-29 17:56:00 +0300 | [diff] [blame] | 451 | * pointer is not populated, and flooding needs to be done by software (we are |
| 452 | * effectively operating in standalone ports mode). |
| 453 | */ |
| 454 | static inline void dsa_default_offload_fwd_mark(struct sk_buff *skb) |
| 455 | { |
| 456 | struct dsa_port *dp = dsa_slave_to_port(skb->dev); |
| 457 | |
Vladimir Oltean | d3eed0e | 2021-12-06 18:57:56 +0200 | [diff] [blame] | 458 | skb->offload_fwd_mark = !!(dp->bridge); |
Vladimir Oltean | bea7907 | 2021-07-29 17:56:00 +0300 | [diff] [blame] | 459 | } |
| 460 | |
Vladimir Oltean | f1dacd7 | 2021-08-10 16:13:53 +0300 | [diff] [blame] | 461 | /* Helper for removing DSA header tags from packets in the RX path. |
| 462 | * Must not be called before skb_pull(len). |
| 463 | * skb->data |
| 464 | * | |
| 465 | * v |
| 466 | * | | | | | | | | | | | | | | | | | | | |
| 467 | * +-----------------------+-----------------------+---------------+-------+ |
| 468 | * | Destination MAC | Source MAC | DSA header | EType | |
| 469 | * +-----------------------+-----------------------+---------------+-------+ |
| 470 | * | | |
| 471 | * <----- len -----> <----- len -----> |
| 472 | * | |
| 473 | * >>>>>>> v |
| 474 | * >>>>>>> | | | | | | | | | | | | | | | |
| 475 | * >>>>>>> +-----------------------+-----------------------+-------+ |
| 476 | * >>>>>>> | Destination MAC | Source MAC | EType | |
| 477 | * +-----------------------+-----------------------+-------+ |
| 478 | * ^ |
| 479 | * | |
| 480 | * skb->data |
| 481 | */ |
| 482 | static inline void dsa_strip_etype_header(struct sk_buff *skb, int len) |
| 483 | { |
| 484 | memmove(skb->data - ETH_HLEN, skb->data - ETH_HLEN - len, 2 * ETH_ALEN); |
| 485 | } |
| 486 | |
Vladimir Oltean | 6bef794 | 2021-08-10 16:13:54 +0300 | [diff] [blame] | 487 | /* Helper for creating space for DSA header tags in TX path packets. |
| 488 | * Must not be called before skb_push(len). |
| 489 | * |
| 490 | * Before: |
| 491 | * |
| 492 | * <<<<<<< | | | | | | | | | | | | | | | |
| 493 | * ^ <<<<<<< +-----------------------+-----------------------+-------+ |
| 494 | * | <<<<<<< | Destination MAC | Source MAC | EType | |
| 495 | * | +-----------------------+-----------------------+-------+ |
| 496 | * <----- len -----> |
| 497 | * | |
| 498 | * | |
| 499 | * skb->data |
| 500 | * |
| 501 | * After: |
| 502 | * |
| 503 | * | | | | | | | | | | | | | | | | | | | |
| 504 | * +-----------------------+-----------------------+---------------+-------+ |
| 505 | * | Destination MAC | Source MAC | DSA header | EType | |
| 506 | * +-----------------------+-----------------------+---------------+-------+ |
| 507 | * ^ | | |
| 508 | * | <----- len -----> |
| 509 | * skb->data |
| 510 | */ |
| 511 | static inline void dsa_alloc_etype_header(struct sk_buff *skb, int len) |
| 512 | { |
| 513 | memmove(skb->data, skb->data + len, 2 * ETH_ALEN); |
| 514 | } |
| 515 | |
Vladimir Oltean | 5d928ff | 2021-08-10 16:13:55 +0300 | [diff] [blame] | 516 | /* On RX, eth_type_trans() on the DSA master pulls ETH_HLEN bytes starting from |
| 517 | * skb_mac_header(skb), which leaves skb->data pointing at the first byte after |
| 518 | * what the DSA master perceives as the EtherType (the beginning of the L3 |
| 519 | * protocol). Since DSA EtherType header taggers treat the EtherType as part of |
| 520 | * the DSA tag itself, and the EtherType is 2 bytes in length, the DSA header |
| 521 | * is located 2 bytes behind skb->data. Note that EtherType in this context |
| 522 | * means the first 2 bytes of the DSA header, not the encapsulated EtherType |
| 523 | * that will become visible after the DSA header is stripped. |
| 524 | */ |
| 525 | static inline void *dsa_etype_header_pos_rx(struct sk_buff *skb) |
| 526 | { |
| 527 | return skb->data - 2; |
| 528 | } |
| 529 | |
Vladimir Oltean | a72808b | 2021-08-10 16:13:56 +0300 | [diff] [blame] | 530 | /* On TX, skb->data points to skb_mac_header(skb), which means that EtherType |
| 531 | * header taggers start exactly where the EtherType is (the EtherType is |
| 532 | * treated as part of the DSA header). |
| 533 | */ |
| 534 | static inline void *dsa_etype_header_pos_tx(struct sk_buff *skb) |
| 535 | { |
| 536 | return skb->data + 2 * ETH_ALEN; |
| 537 | } |
| 538 | |
Vivien Didelot | f515f19 | 2017-02-03 13:20:20 -0500 | [diff] [blame] | 539 | /* switch.c */ |
| 540 | int dsa_switch_register_notifier(struct dsa_switch *ds); |
| 541 | void dsa_switch_unregister_notifier(struct dsa_switch *ds); |
Vladimir Oltean | bff33f7 | 2020-03-27 21:55:43 +0200 | [diff] [blame] | 542 | |
Vladimir Oltean | 5e8a1e0 | 2022-03-02 21:14:10 +0200 | [diff] [blame] | 543 | static inline bool dsa_switch_supports_uc_filtering(struct dsa_switch *ds) |
| 544 | { |
| 545 | return ds->ops->port_fdb_add && ds->ops->port_fdb_del && |
| 546 | ds->fdb_isolation && !ds->vlan_filtering_is_global && |
| 547 | !ds->needs_standalone_vlan_filtering; |
| 548 | } |
| 549 | |
| 550 | static inline bool dsa_switch_supports_mc_filtering(struct dsa_switch *ds) |
| 551 | { |
| 552 | return ds->ops->port_mdb_add && ds->ops->port_mdb_del && |
| 553 | ds->fdb_isolation && !ds->vlan_filtering_is_global && |
| 554 | !ds->needs_standalone_vlan_filtering; |
| 555 | } |
| 556 | |
Vladimir Oltean | bff33f7 | 2020-03-27 21:55:43 +0200 | [diff] [blame] | 557 | /* dsa2.c */ |
Vladimir Oltean | dedd6a0 | 2022-02-23 16:00:49 +0200 | [diff] [blame] | 558 | void dsa_lag_map(struct dsa_switch_tree *dst, struct dsa_lag *lag); |
| 559 | void dsa_lag_unmap(struct dsa_switch_tree *dst, struct dsa_lag *lag); |
| 560 | struct dsa_lag *dsa_tree_lag_find(struct dsa_switch_tree *dst, |
| 561 | const struct net_device *lag_dev); |
Vladimir Oltean | 95f510d | 2022-09-11 04:06:59 +0300 | [diff] [blame] | 562 | struct net_device *dsa_tree_find_first_master(struct dsa_switch_tree *dst); |
Vladimir Oltean | 886f8e2 | 2021-01-29 03:00:04 +0200 | [diff] [blame] | 563 | int dsa_tree_notify(struct dsa_switch_tree *dst, unsigned long e, void *v); |
| 564 | int dsa_broadcast(unsigned long e, void *v); |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 565 | int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst, |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 566 | const struct dsa_device_ops *tag_ops, |
| 567 | const struct dsa_device_ops *old_tag_ops); |
Vladimir Oltean | 295ab96 | 2022-02-02 01:03:20 +0100 | [diff] [blame] | 568 | void dsa_tree_master_admin_state_change(struct dsa_switch_tree *dst, |
| 569 | struct net_device *master, |
| 570 | bool up); |
| 571 | void dsa_tree_master_oper_state_change(struct dsa_switch_tree *dst, |
| 572 | struct net_device *master, |
| 573 | bool up); |
Vladimir Oltean | 3f9bb03 | 2021-12-06 18:57:47 +0200 | [diff] [blame] | 574 | unsigned int dsa_bridge_num_get(const struct net_device *bridge_dev, int max); |
| 575 | void dsa_bridge_num_put(const struct net_device *bridge_dev, |
| 576 | unsigned int bridge_num); |
Vladimir Oltean | d3eed0e | 2021-12-06 18:57:56 +0200 | [diff] [blame] | 577 | struct dsa_bridge *dsa_tree_bridge_find(struct dsa_switch_tree *dst, |
| 578 | const struct net_device *br); |
Tobias Waldekranz | 058102a6 | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 579 | |
Vladimir Oltean | e19cc13 | 2021-07-19 20:14:51 +0300 | [diff] [blame] | 580 | /* tag_8021q.c */ |
Vladimir Oltean | c64b9c0 | 2021-07-19 20:14:52 +0300 | [diff] [blame] | 581 | int dsa_switch_tag_8021q_vlan_add(struct dsa_switch *ds, |
| 582 | struct dsa_notifier_tag_8021q_vlan_info *info); |
| 583 | int dsa_switch_tag_8021q_vlan_del(struct dsa_switch *ds, |
| 584 | struct dsa_notifier_tag_8021q_vlan_info *info); |
Vladimir Oltean | e19cc13 | 2021-07-19 20:14:51 +0300 | [diff] [blame] | 585 | |
Vladimir Oltean | bff33f7 | 2020-03-27 21:55:43 +0200 | [diff] [blame] | 586 | extern struct list_head dsa_tree_list; |
| 587 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 588 | #endif |