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 | |
Vladimir Oltean | 123abc06 | 2021-07-22 18:55:40 +0300 | [diff] [blame] | 17 | #define DSA_MAX_NUM_OFFLOADING_BRIDGES BITS_PER_LONG |
| 18 | |
Vivien Didelot | 52c96f9 | 2017-05-19 17:00:51 -0400 | [diff] [blame] | 19 | enum { |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 20 | DSA_NOTIFIER_AGEING_TIME, |
Vivien Didelot | 52c96f9 | 2017-05-19 17:00:51 -0400 | [diff] [blame] | 21 | DSA_NOTIFIER_BRIDGE_JOIN, |
| 22 | DSA_NOTIFIER_BRIDGE_LEAVE, |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 23 | DSA_NOTIFIER_FDB_ADD, |
| 24 | DSA_NOTIFIER_FDB_DEL, |
Vladimir Oltean | 3dc80af | 2021-06-29 17:06:51 +0300 | [diff] [blame] | 25 | DSA_NOTIFIER_HOST_FDB_ADD, |
| 26 | DSA_NOTIFIER_HOST_FDB_DEL, |
George McCollister | 18596f5 | 2021-02-09 19:02:12 -0600 | [diff] [blame] | 27 | DSA_NOTIFIER_HSR_JOIN, |
| 28 | DSA_NOTIFIER_HSR_LEAVE, |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 29 | DSA_NOTIFIER_LAG_CHANGE, |
| 30 | DSA_NOTIFIER_LAG_JOIN, |
| 31 | DSA_NOTIFIER_LAG_LEAVE, |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 32 | DSA_NOTIFIER_MDB_ADD, |
| 33 | DSA_NOTIFIER_MDB_DEL, |
Vladimir Oltean | b8e997c | 2021-06-29 17:06:49 +0300 | [diff] [blame] | 34 | DSA_NOTIFIER_HOST_MDB_ADD, |
| 35 | DSA_NOTIFIER_HOST_MDB_DEL, |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 36 | DSA_NOTIFIER_VLAN_ADD, |
| 37 | DSA_NOTIFIER_VLAN_DEL, |
Vladimir Oltean | bfcb813 | 2020-03-27 21:55:42 +0200 | [diff] [blame] | 38 | DSA_NOTIFIER_MTU, |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 39 | DSA_NOTIFIER_TAG_PROTO, |
Horatiu Vultur | c595c43 | 2021-02-16 22:42:04 +0100 | [diff] [blame] | 40 | DSA_NOTIFIER_MRP_ADD, |
| 41 | DSA_NOTIFIER_MRP_DEL, |
| 42 | DSA_NOTIFIER_MRP_ADD_RING_ROLE, |
| 43 | DSA_NOTIFIER_MRP_DEL_RING_ROLE, |
Vladimir Oltean | c64b9c0 | 2021-07-19 20:14:52 +0300 | [diff] [blame] | 44 | DSA_NOTIFIER_TAG_8021Q_VLAN_ADD, |
| 45 | DSA_NOTIFIER_TAG_8021Q_VLAN_DEL, |
Vivien Didelot | 52c96f9 | 2017-05-19 17:00:51 -0400 | [diff] [blame] | 46 | }; |
| 47 | |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 48 | /* DSA_NOTIFIER_AGEING_TIME */ |
| 49 | struct dsa_notifier_ageing_time_info { |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 50 | unsigned int ageing_time; |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 51 | }; |
| 52 | |
Vivien Didelot | 52c96f9 | 2017-05-19 17:00:51 -0400 | [diff] [blame] | 53 | /* DSA_NOTIFIER_BRIDGE_* */ |
| 54 | struct dsa_notifier_bridge_info { |
| 55 | struct net_device *br; |
Vladimir Oltean | f66a6a6 | 2020-05-10 19:37:41 +0300 | [diff] [blame] | 56 | int tree_index; |
Vivien Didelot | 52c96f9 | 2017-05-19 17:00:51 -0400 | [diff] [blame] | 57 | int sw_index; |
| 58 | int port; |
| 59 | }; |
| 60 | |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 61 | /* DSA_NOTIFIER_FDB_* */ |
| 62 | struct dsa_notifier_fdb_info { |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 63 | int sw_index; |
| 64 | int port; |
Arkadi Sharshevsky | 2acf4e6 | 2017-08-06 16:15:41 +0300 | [diff] [blame] | 65 | const unsigned char *addr; |
| 66 | u16 vid; |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 67 | }; |
| 68 | |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 69 | /* DSA_NOTIFIER_MDB_* */ |
| 70 | struct dsa_notifier_mdb_info { |
| 71 | const struct switchdev_obj_port_mdb *mdb; |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 72 | int sw_index; |
| 73 | int port; |
| 74 | }; |
| 75 | |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 76 | /* DSA_NOTIFIER_LAG_* */ |
| 77 | struct dsa_notifier_lag_info { |
| 78 | struct net_device *lag; |
| 79 | int sw_index; |
| 80 | int port; |
| 81 | |
| 82 | struct netdev_lag_upper_info *info; |
| 83 | }; |
| 84 | |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 85 | /* DSA_NOTIFIER_VLAN_* */ |
| 86 | struct dsa_notifier_vlan_info { |
| 87 | const struct switchdev_obj_port_vlan *vlan; |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 88 | int sw_index; |
| 89 | int port; |
Vladimir Oltean | 31046a5 | 2021-02-13 22:43:18 +0200 | [diff] [blame] | 90 | struct netlink_ext_ack *extack; |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 91 | }; |
| 92 | |
Vladimir Oltean | bfcb813 | 2020-03-27 21:55:42 +0200 | [diff] [blame] | 93 | /* DSA_NOTIFIER_MTU */ |
| 94 | struct dsa_notifier_mtu_info { |
Vladimir Oltean | 88faba2 | 2021-06-21 19:42:18 +0300 | [diff] [blame] | 95 | bool targeted_match; |
Vladimir Oltean | bfcb813 | 2020-03-27 21:55:42 +0200 | [diff] [blame] | 96 | int sw_index; |
| 97 | int port; |
| 98 | int mtu; |
| 99 | }; |
| 100 | |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 101 | /* DSA_NOTIFIER_TAG_PROTO_* */ |
| 102 | struct dsa_notifier_tag_proto_info { |
| 103 | const struct dsa_device_ops *tag_ops; |
| 104 | }; |
| 105 | |
Horatiu Vultur | c595c43 | 2021-02-16 22:42:04 +0100 | [diff] [blame] | 106 | /* DSA_NOTIFIER_MRP_* */ |
| 107 | struct dsa_notifier_mrp_info { |
| 108 | const struct switchdev_obj_mrp *mrp; |
| 109 | int sw_index; |
| 110 | int port; |
| 111 | }; |
| 112 | |
| 113 | /* DSA_NOTIFIER_MRP_* */ |
| 114 | struct dsa_notifier_mrp_ring_role_info { |
| 115 | const struct switchdev_obj_ring_role_mrp *mrp; |
| 116 | int sw_index; |
| 117 | int port; |
| 118 | }; |
| 119 | |
Vladimir Oltean | c64b9c0 | 2021-07-19 20:14:52 +0300 | [diff] [blame] | 120 | /* DSA_NOTIFIER_TAG_8021Q_VLAN_* */ |
| 121 | struct dsa_notifier_tag_8021q_vlan_info { |
| 122 | int tree_index; |
| 123 | int sw_index; |
| 124 | int port; |
| 125 | u16 vid; |
| 126 | }; |
| 127 | |
Vladimir Oltean | c4bb76a | 2021-01-06 11:51:32 +0200 | [diff] [blame] | 128 | struct dsa_switchdev_event_work { |
| 129 | struct dsa_switch *ds; |
| 130 | int port; |
Vladimir Oltean | 4bed397 | 2021-06-29 17:06:57 +0300 | [diff] [blame] | 131 | struct net_device *dev; |
Vladimir Oltean | c4bb76a | 2021-01-06 11:51:32 +0200 | [diff] [blame] | 132 | struct work_struct work; |
| 133 | unsigned long event; |
| 134 | /* Specific for SWITCHDEV_FDB_ADD_TO_DEVICE and |
| 135 | * SWITCHDEV_FDB_DEL_TO_DEVICE |
| 136 | */ |
| 137 | unsigned char addr[ETH_ALEN]; |
| 138 | u16 vid; |
Vladimir Oltean | 3dc80af | 2021-06-29 17:06:51 +0300 | [diff] [blame] | 139 | bool host_addr; |
Vladimir Oltean | c4bb76a | 2021-01-06 11:51:32 +0200 | [diff] [blame] | 140 | }; |
| 141 | |
George McCollister | 18596f5 | 2021-02-09 19:02:12 -0600 | [diff] [blame] | 142 | /* DSA_NOTIFIER_HSR_* */ |
| 143 | struct dsa_notifier_hsr_info { |
| 144 | struct net_device *hsr; |
| 145 | int sw_index; |
| 146 | int port; |
| 147 | }; |
| 148 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 149 | struct dsa_slave_priv { |
Vivien Didelot | 1524024 | 2017-09-29 17:19:18 -0400 | [diff] [blame] | 150 | /* 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] | 151 | struct sk_buff * (*xmit)(struct sk_buff *skb, |
Alexander Duyck | 5075314 | 2014-09-15 13:00:19 -0400 | [diff] [blame] | 152 | struct net_device *dev); |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 153 | |
Alexander Lobakin | e131a56 | 2020-04-21 16:41:08 +0300 | [diff] [blame] | 154 | struct gro_cells gcells; |
| 155 | |
Vivien Didelot | afdcf15 | 2017-01-27 15:29:39 -0500 | [diff] [blame] | 156 | /* DSA port data, such as switch, port index, etc. */ |
| 157 | struct dsa_port *dp; |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 158 | |
Florian Fainelli | 04ff53f | 2015-07-31 11:42:57 -0700 | [diff] [blame] | 159 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 160 | struct netpoll *netpoll; |
| 161 | #endif |
Florian Fainelli | f50f212 | 2017-01-30 12:41:40 -0800 | [diff] [blame] | 162 | |
| 163 | /* TC context */ |
| 164 | struct list_head mall_tc_list; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 165 | }; |
| 166 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 167 | /* dsa.c */ |
Andrew Lunn | c39e2a1 | 2019-04-28 19:37:18 +0200 | [diff] [blame] | 168 | const struct dsa_device_ops *dsa_tag_driver_get(int tag_protocol); |
Andrew Lunn | 4dad81e | 2019-04-28 19:37:19 +0200 | [diff] [blame] | 169 | void dsa_tag_driver_put(const struct dsa_device_ops *ops); |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 170 | 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] | 171 | |
Arkadi Sharshevsky | c9eb3e0 | 2017-08-06 16:15:42 +0300 | [diff] [blame] | 172 | bool dsa_schedule_work(struct work_struct *work); |
Florian Fainelli | 98cdb48 | 2018-09-07 11:09:02 -0700 | [diff] [blame] | 173 | 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] | 174 | |
Vladimir Oltean | 4e50025 | 2021-06-11 22:01:24 +0300 | [diff] [blame] | 175 | static inline int dsa_tag_protocol_overhead(const struct dsa_device_ops *ops) |
| 176 | { |
| 177 | return ops->needed_headroom + ops->needed_tailroom; |
| 178 | } |
| 179 | |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 180 | /* master.c */ |
Vivien Didelot | 17a22fc | 2017-11-06 16:11:45 -0500 | [diff] [blame] | 181 | int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp); |
| 182 | void dsa_master_teardown(struct net_device *dev); |
Vivien Didelot | f2f2356 | 2017-09-19 11:57:00 -0400 | [diff] [blame] | 183 | |
Vivien Didelot | 2231c43 | 2017-10-16 11:12:17 -0400 | [diff] [blame] | 184 | static inline struct net_device *dsa_master_find_slave(struct net_device *dev, |
| 185 | int device, int port) |
Vivien Didelot | 3775b1b | 2017-09-29 17:19:15 -0400 | [diff] [blame] | 186 | { |
Vivien Didelot | 2f657a6 | 2017-09-29 17:19:20 -0400 | [diff] [blame] | 187 | struct dsa_port *cpu_dp = dev->dsa_ptr; |
| 188 | struct dsa_switch_tree *dst = cpu_dp->dst; |
Vivien Didelot | 7b9a2f4 | 2019-10-21 16:51:18 -0400 | [diff] [blame] | 189 | struct dsa_port *dp; |
Vivien Didelot | 3775b1b | 2017-09-29 17:19:15 -0400 | [diff] [blame] | 190 | |
Vivien Didelot | 7b9a2f4 | 2019-10-21 16:51:18 -0400 | [diff] [blame] | 191 | list_for_each_entry(dp, &dst->ports, list) |
| 192 | if (dp->ds->index == device && dp->index == port && |
| 193 | dp->type == DSA_PORT_TYPE_USER) |
| 194 | return dp->slave; |
Vivien Didelot | 3775b1b | 2017-09-29 17:19:15 -0400 | [diff] [blame] | 195 | |
Vivien Didelot | 7b9a2f4 | 2019-10-21 16:51:18 -0400 | [diff] [blame] | 196 | return NULL; |
Vivien Didelot | 3775b1b | 2017-09-29 17:19:15 -0400 | [diff] [blame] | 197 | } |
| 198 | |
Vivien Didelot | a40c175 | 2017-05-19 17:00:44 -0400 | [diff] [blame] | 199 | /* port.c */ |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 200 | void dsa_port_set_tag_protocol(struct dsa_port *cpu_dp, |
| 201 | const struct dsa_device_ops *tag_ops); |
Vladimir Oltean | 39f3210 | 2021-08-08 14:16:37 +0300 | [diff] [blame] | 202 | int dsa_port_set_state(struct dsa_port *dp, u8 state, bool do_fast_age); |
Russell King | 8640f8d | 2020-03-03 15:01:46 +0000 | [diff] [blame] | 203 | 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] | 204 | int dsa_port_enable(struct dsa_port *dp, struct phy_device *phy); |
Russell King | 8640f8d | 2020-03-03 15:01:46 +0000 | [diff] [blame] | 205 | void dsa_port_disable_rt(struct dsa_port *dp); |
Andrew Lunn | 75104db | 2019-02-24 20:44:43 +0100 | [diff] [blame] | 206 | void dsa_port_disable(struct dsa_port *dp); |
Vladimir Oltean | 2afc526 | 2021-03-23 01:51:48 +0200 | [diff] [blame] | 207 | int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br, |
| 208 | struct netlink_ext_ack *extack); |
Vladimir Oltean | 4e51bf4 | 2021-07-21 19:24:03 +0300 | [diff] [blame] | 209 | 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] | 210 | 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] | 211 | int dsa_port_lag_change(struct dsa_port *dp, |
| 212 | struct netdev_lag_lower_state_info *linfo); |
| 213 | 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] | 214 | struct netdev_lag_upper_info *uinfo, |
| 215 | struct netlink_ext_ack *extack); |
Vladimir Oltean | 4e51bf4 | 2021-07-21 19:24:03 +0300 | [diff] [blame] | 216 | void dsa_port_pre_lag_leave(struct dsa_port *dp, struct net_device *lag_dev); |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 217 | 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] | 218 | int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering, |
| 219 | struct netlink_ext_ack *extack); |
Russell King | 54a0ed0 | 2020-05-12 20:20:25 +0300 | [diff] [blame] | 220 | bool dsa_port_skip_vlan_configuration(struct dsa_port *dp); |
Vladimir Oltean | bae33f2 | 2021-01-09 02:01:50 +0200 | [diff] [blame] | 221 | 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] | 222 | int dsa_port_mtu_change(struct dsa_port *dp, int new_mtu, |
Vladimir Oltean | 88faba2 | 2021-06-21 19:42:18 +0300 | [diff] [blame] | 223 | bool targeted_match); |
Arkadi Sharshevsky | 2acf4e6 | 2017-08-06 16:15:41 +0300 | [diff] [blame] | 224 | int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr, |
| 225 | u16 vid); |
| 226 | int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr, |
| 227 | u16 vid); |
Vladimir Oltean | 3dc80af | 2021-06-29 17:06:51 +0300 | [diff] [blame] | 228 | int dsa_port_host_fdb_add(struct dsa_port *dp, const unsigned char *addr, |
| 229 | u16 vid); |
| 230 | int dsa_port_host_fdb_del(struct dsa_port *dp, const unsigned char *addr, |
| 231 | u16 vid); |
Vivien Didelot | de40fc5 | 2017-09-20 19:32:14 -0400 | [diff] [blame] | 232 | 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] | 233 | int dsa_port_mdb_add(const struct dsa_port *dp, |
Vladimir Oltean | ffb68fc | 2021-01-09 02:01:48 +0200 | [diff] [blame] | 234 | const struct switchdev_obj_port_mdb *mdb); |
Andrew Lunn | bb9f60317 | 2017-11-09 23:11:01 +0100 | [diff] [blame] | 235 | int dsa_port_mdb_del(const struct dsa_port *dp, |
Vivien Didelot | 3a9afea | 2017-05-19 17:00:49 -0400 | [diff] [blame] | 236 | const struct switchdev_obj_port_mdb *mdb); |
Vladimir Oltean | b8e997c | 2021-06-29 17:06:49 +0300 | [diff] [blame] | 237 | int dsa_port_host_mdb_add(const struct dsa_port *dp, |
| 238 | const struct switchdev_obj_port_mdb *mdb); |
| 239 | int dsa_port_host_mdb_del(const struct dsa_port *dp, |
| 240 | const struct switchdev_obj_port_mdb *mdb); |
Vladimir Oltean | e18f4c1 | 2021-02-12 17:15:55 +0200 | [diff] [blame] | 241 | int dsa_port_pre_bridge_flags(const struct dsa_port *dp, |
Vladimir Oltean | a8b659e | 2021-02-12 17:15:56 +0200 | [diff] [blame] | 242 | struct switchdev_brport_flags flags, |
| 243 | struct netlink_ext_ack *extack); |
Vladimir Oltean | 045c45d | 2021-08-08 17:35:23 +0300 | [diff] [blame] | 244 | int dsa_port_bridge_flags(struct dsa_port *dp, |
Vladimir Oltean | a8b659e | 2021-02-12 17:15:56 +0200 | [diff] [blame] | 245 | struct switchdev_brport_flags flags, |
| 246 | struct netlink_ext_ack *extack); |
Vivien Didelot | 076e713 | 2017-05-19 17:00:50 -0400 | [diff] [blame] | 247 | int dsa_port_vlan_add(struct dsa_port *dp, |
Vladimir Oltean | 31046a5 | 2021-02-13 22:43:18 +0200 | [diff] [blame] | 248 | const struct switchdev_obj_port_vlan *vlan, |
| 249 | struct netlink_ext_ack *extack); |
Vivien Didelot | 076e713 | 2017-05-19 17:00:50 -0400 | [diff] [blame] | 250 | int dsa_port_vlan_del(struct dsa_port *dp, |
| 251 | const struct switchdev_obj_port_vlan *vlan); |
Horatiu Vultur | c595c43 | 2021-02-16 22:42:04 +0100 | [diff] [blame] | 252 | int dsa_port_mrp_add(const struct dsa_port *dp, |
| 253 | const struct switchdev_obj_mrp *mrp); |
| 254 | int dsa_port_mrp_del(const struct dsa_port *dp, |
| 255 | const struct switchdev_obj_mrp *mrp); |
| 256 | int dsa_port_mrp_add_ring_role(const struct dsa_port *dp, |
| 257 | const struct switchdev_obj_ring_role_mrp *mrp); |
| 258 | int dsa_port_mrp_del_ring_role(const struct dsa_port *dp, |
| 259 | const struct switchdev_obj_ring_role_mrp *mrp); |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 260 | int dsa_port_link_register_of(struct dsa_port *dp); |
| 261 | void dsa_port_link_unregister_of(struct dsa_port *dp); |
George McCollister | 18596f5 | 2021-02-09 19:02:12 -0600 | [diff] [blame] | 262 | int dsa_port_hsr_join(struct dsa_port *dp, struct net_device *hsr); |
| 263 | void dsa_port_hsr_leave(struct dsa_port *dp, struct net_device *hsr); |
Vladimir Oltean | c64b9c0 | 2021-07-19 20:14:52 +0300 | [diff] [blame] | 264 | int dsa_port_tag_8021q_vlan_add(struct dsa_port *dp, u16 vid); |
| 265 | void dsa_port_tag_8021q_vlan_del(struct dsa_port *dp, u16 vid); |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 266 | extern const struct phylink_mac_ops dsa_port_phylink_mac_ops; |
Vivien Didelot | 57ab1ca | 2017-10-26 10:50:07 -0400 | [diff] [blame] | 267 | |
Vladimir Oltean | 03cbb87 | 2021-03-07 12:21:56 +0200 | [diff] [blame] | 268 | static inline bool dsa_port_offloads_bridge_port(struct dsa_port *dp, |
Vladimir Oltean | b94dc99 | 2021-07-19 16:51:40 +0300 | [diff] [blame] | 269 | const struct net_device *dev) |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 270 | { |
Tobias Waldekranz | cc76ce9 | 2021-03-18 20:25:33 +0100 | [diff] [blame] | 271 | return dsa_port_to_bridge_port(dp) == dev; |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 272 | } |
| 273 | |
Vladimir Oltean | 03cbb87 | 2021-03-07 12:21:56 +0200 | [diff] [blame] | 274 | static inline bool dsa_port_offloads_bridge(struct dsa_port *dp, |
Vladimir Oltean | b94dc99 | 2021-07-19 16:51:40 +0300 | [diff] [blame] | 275 | const struct net_device *bridge_dev) |
Vladimir Oltean | 03cbb87 | 2021-03-07 12:21:56 +0200 | [diff] [blame] | 276 | { |
| 277 | /* DSA ports connected to a bridge, and event was emitted |
| 278 | * for the bridge. |
| 279 | */ |
| 280 | return dp->bridge_dev == bridge_dev; |
| 281 | } |
| 282 | |
Vladimir Oltean | a324d3d | 2021-02-06 00:02:20 +0200 | [diff] [blame] | 283 | /* Returns true if any port of this tree offloads the given net_device */ |
Vladimir Oltean | 03cbb87 | 2021-03-07 12:21:56 +0200 | [diff] [blame] | 284 | static inline bool dsa_tree_offloads_bridge_port(struct dsa_switch_tree *dst, |
Vladimir Oltean | b94dc99 | 2021-07-19 16:51:40 +0300 | [diff] [blame] | 285 | const struct net_device *dev) |
Vladimir Oltean | a324d3d | 2021-02-06 00:02:20 +0200 | [diff] [blame] | 286 | { |
| 287 | struct dsa_port *dp; |
| 288 | |
| 289 | list_for_each_entry(dp, &dst->ports, list) |
Vladimir Oltean | 03cbb87 | 2021-03-07 12:21:56 +0200 | [diff] [blame] | 290 | if (dsa_port_offloads_bridge_port(dp, dev)) |
Vladimir Oltean | a324d3d | 2021-02-06 00:02:20 +0200 | [diff] [blame] | 291 | return true; |
| 292 | |
| 293 | return false; |
| 294 | } |
| 295 | |
Vladimir Oltean | b94dc99 | 2021-07-19 16:51:40 +0300 | [diff] [blame] | 296 | /* Returns true if any port of this tree offloads the given bridge */ |
| 297 | static inline bool dsa_tree_offloads_bridge(struct dsa_switch_tree *dst, |
| 298 | const struct net_device *bridge_dev) |
| 299 | { |
| 300 | struct dsa_port *dp; |
| 301 | |
| 302 | list_for_each_entry(dp, &dst->ports, list) |
| 303 | if (dsa_port_offloads_bridge(dp, bridge_dev)) |
| 304 | return true; |
| 305 | |
| 306 | return false; |
| 307 | } |
| 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 | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 321 | void dsa_slave_setup_tagger(struct net_device *slave); |
| 322 | int dsa_slave_change_mtu(struct net_device *dev, int new_mtu); |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 323 | |
Vivien Didelot | d945097 | 2017-10-16 11:12:15 -0400 | [diff] [blame] | 324 | static inline struct dsa_port *dsa_slave_to_port(const struct net_device *dev) |
| 325 | { |
| 326 | struct dsa_slave_priv *p = netdev_priv(dev); |
| 327 | |
| 328 | return p->dp; |
| 329 | } |
| 330 | |
Vivien Didelot | d0006b0 | 2017-10-16 11:12:16 -0400 | [diff] [blame] | 331 | static inline struct net_device * |
| 332 | dsa_slave_to_master(const struct net_device *dev) |
| 333 | { |
| 334 | struct dsa_port *dp = dsa_slave_to_port(dev); |
| 335 | |
Vivien Didelot | f8b8b1c | 2017-10-16 11:12:18 -0400 | [diff] [blame] | 336 | return dp->cpu_dp->master; |
Vivien Didelot | d0006b0 | 2017-10-16 11:12:16 -0400 | [diff] [blame] | 337 | } |
| 338 | |
Vladimir Oltean | 412a152 | 2020-09-23 14:40:37 -0700 | [diff] [blame] | 339 | /* If under a bridge with vlan_filtering=0, make sure to send pvid-tagged |
| 340 | * frames as untagged, since the bridge will not untag them. |
| 341 | */ |
| 342 | static inline struct sk_buff *dsa_untag_bridge_pvid(struct sk_buff *skb) |
| 343 | { |
| 344 | struct dsa_port *dp = dsa_slave_to_port(skb->dev); |
Vladimir Oltean | 412a152 | 2020-09-23 14:40:37 -0700 | [diff] [blame] | 345 | struct net_device *br = dp->bridge_dev; |
| 346 | struct net_device *dev = skb->dev; |
| 347 | struct net_device *upper_dev; |
Vladimir Oltean | 412a152 | 2020-09-23 14:40:37 -0700 | [diff] [blame] | 348 | u16 vid, pvid, proto; |
| 349 | int err; |
| 350 | |
| 351 | if (!br || br_vlan_enabled(br)) |
| 352 | return skb; |
| 353 | |
| 354 | err = br_vlan_get_proto(br, &proto); |
| 355 | if (err) |
| 356 | return skb; |
| 357 | |
| 358 | /* Move VLAN tag from data to hwaccel */ |
Florian Fainelli | a348292 | 2020-10-01 19:42:14 -0700 | [diff] [blame] | 359 | if (!skb_vlan_tag_present(skb) && skb->protocol == htons(proto)) { |
Vladimir Oltean | 412a152 | 2020-09-23 14:40:37 -0700 | [diff] [blame] | 360 | skb = skb_vlan_untag(skb); |
| 361 | if (!skb) |
| 362 | return NULL; |
| 363 | } |
| 364 | |
| 365 | if (!skb_vlan_tag_present(skb)) |
| 366 | return skb; |
| 367 | |
| 368 | vid = skb_vlan_tag_get_id(skb); |
| 369 | |
| 370 | /* We already run under an RCU read-side critical section since |
| 371 | * we are called from netif_receive_skb_list_internal(). |
| 372 | */ |
| 373 | err = br_vlan_get_pvid_rcu(dev, &pvid); |
| 374 | if (err) |
| 375 | return skb; |
| 376 | |
| 377 | if (vid != pvid) |
| 378 | return skb; |
| 379 | |
| 380 | /* The sad part about attempting to untag from DSA is that we |
| 381 | * don't know, unless we check, if the skb will end up in |
| 382 | * the bridge's data path - br_allowed_ingress() - or not. |
| 383 | * For example, there might be an 8021q upper for the |
| 384 | * default_pvid of the bridge, which will steal VLAN-tagged traffic |
| 385 | * from the bridge's data path. This is a configuration that DSA |
| 386 | * supports because vlan_filtering is 0. In that case, we should |
| 387 | * definitely keep the tag, to make sure it keeps working. |
| 388 | */ |
Florian Fainelli | 3a68844 | 2020-10-01 19:42:15 -0700 | [diff] [blame] | 389 | upper_dev = __vlan_find_dev_deep_rcu(br, htons(proto), vid); |
| 390 | if (upper_dev) |
| 391 | return skb; |
Vladimir Oltean | 412a152 | 2020-09-23 14:40:37 -0700 | [diff] [blame] | 392 | |
| 393 | __vlan_hwaccel_clear_tag(skb); |
| 394 | |
| 395 | return skb; |
| 396 | } |
| 397 | |
Vladimir Oltean | 884be12 | 2021-07-26 19:55:34 +0300 | [diff] [blame] | 398 | /* For switches without hardware support for DSA tagging to be able |
| 399 | * to support termination through the bridge. |
| 400 | */ |
| 401 | static inline struct net_device * |
| 402 | dsa_find_designated_bridge_port_by_vid(struct net_device *master, u16 vid) |
| 403 | { |
| 404 | struct dsa_port *cpu_dp = master->dsa_ptr; |
| 405 | struct dsa_switch_tree *dst = cpu_dp->dst; |
| 406 | struct bridge_vlan_info vinfo; |
| 407 | struct net_device *slave; |
| 408 | struct dsa_port *dp; |
| 409 | int err; |
| 410 | |
| 411 | list_for_each_entry(dp, &dst->ports, list) { |
| 412 | if (dp->type != DSA_PORT_TYPE_USER) |
| 413 | continue; |
| 414 | |
| 415 | if (!dp->bridge_dev) |
| 416 | continue; |
| 417 | |
| 418 | if (dp->stp_state != BR_STATE_LEARNING && |
| 419 | dp->stp_state != BR_STATE_FORWARDING) |
| 420 | continue; |
| 421 | |
| 422 | /* Since the bridge might learn this packet, keep the CPU port |
| 423 | * affinity with the port that will be used for the reply on |
| 424 | * xmit. |
| 425 | */ |
| 426 | if (dp->cpu_dp != cpu_dp) |
| 427 | continue; |
| 428 | |
| 429 | slave = dp->slave; |
| 430 | |
| 431 | err = br_vlan_get_info_rcu(slave, vid, &vinfo); |
| 432 | if (err) |
| 433 | continue; |
| 434 | |
| 435 | return slave; |
| 436 | } |
| 437 | |
| 438 | return NULL; |
| 439 | } |
| 440 | |
Vladimir Oltean | bea7907 | 2021-07-29 17:56:00 +0300 | [diff] [blame] | 441 | /* If the ingress port offloads the bridge, we mark the frame as autonomously |
| 442 | * forwarded by hardware, so the software bridge doesn't forward in twice, back |
| 443 | * to us, because we already did. However, if we're in fallback mode and we do |
| 444 | * software bridging, we are not offloading it, therefore the dp->bridge_dev |
| 445 | * pointer is not populated, and flooding needs to be done by software (we are |
| 446 | * effectively operating in standalone ports mode). |
| 447 | */ |
| 448 | static inline void dsa_default_offload_fwd_mark(struct sk_buff *skb) |
| 449 | { |
| 450 | struct dsa_port *dp = dsa_slave_to_port(skb->dev); |
| 451 | |
| 452 | skb->offload_fwd_mark = !!(dp->bridge_dev); |
| 453 | } |
| 454 | |
Vladimir Oltean | f1dacd7 | 2021-08-10 16:13:53 +0300 | [diff] [blame] | 455 | /* Helper for removing DSA header tags from packets in the RX path. |
| 456 | * Must not be called before skb_pull(len). |
| 457 | * skb->data |
| 458 | * | |
| 459 | * v |
| 460 | * | | | | | | | | | | | | | | | | | | | |
| 461 | * +-----------------------+-----------------------+---------------+-------+ |
| 462 | * | Destination MAC | Source MAC | DSA header | EType | |
| 463 | * +-----------------------+-----------------------+---------------+-------+ |
| 464 | * | | |
| 465 | * <----- len -----> <----- len -----> |
| 466 | * | |
| 467 | * >>>>>>> v |
| 468 | * >>>>>>> | | | | | | | | | | | | | | | |
| 469 | * >>>>>>> +-----------------------+-----------------------+-------+ |
| 470 | * >>>>>>> | Destination MAC | Source MAC | EType | |
| 471 | * +-----------------------+-----------------------+-------+ |
| 472 | * ^ |
| 473 | * | |
| 474 | * skb->data |
| 475 | */ |
| 476 | static inline void dsa_strip_etype_header(struct sk_buff *skb, int len) |
| 477 | { |
| 478 | memmove(skb->data - ETH_HLEN, skb->data - ETH_HLEN - len, 2 * ETH_ALEN); |
| 479 | } |
| 480 | |
Vladimir Oltean | 6bef794 | 2021-08-10 16:13:54 +0300 | [diff] [blame^] | 481 | /* Helper for creating space for DSA header tags in TX path packets. |
| 482 | * Must not be called before skb_push(len). |
| 483 | * |
| 484 | * Before: |
| 485 | * |
| 486 | * <<<<<<< | | | | | | | | | | | | | | | |
| 487 | * ^ <<<<<<< +-----------------------+-----------------------+-------+ |
| 488 | * | <<<<<<< | Destination MAC | Source MAC | EType | |
| 489 | * | +-----------------------+-----------------------+-------+ |
| 490 | * <----- len -----> |
| 491 | * | |
| 492 | * | |
| 493 | * skb->data |
| 494 | * |
| 495 | * After: |
| 496 | * |
| 497 | * | | | | | | | | | | | | | | | | | | | |
| 498 | * +-----------------------+-----------------------+---------------+-------+ |
| 499 | * | Destination MAC | Source MAC | DSA header | EType | |
| 500 | * +-----------------------+-----------------------+---------------+-------+ |
| 501 | * ^ | | |
| 502 | * | <----- len -----> |
| 503 | * skb->data |
| 504 | */ |
| 505 | static inline void dsa_alloc_etype_header(struct sk_buff *skb, int len) |
| 506 | { |
| 507 | memmove(skb->data, skb->data + len, 2 * ETH_ALEN); |
| 508 | } |
| 509 | |
Vivien Didelot | f515f19 | 2017-02-03 13:20:20 -0500 | [diff] [blame] | 510 | /* switch.c */ |
| 511 | int dsa_switch_register_notifier(struct dsa_switch *ds); |
| 512 | void dsa_switch_unregister_notifier(struct dsa_switch *ds); |
Vladimir Oltean | bff33f7 | 2020-03-27 21:55:43 +0200 | [diff] [blame] | 513 | |
| 514 | /* dsa2.c */ |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 515 | void dsa_lag_map(struct dsa_switch_tree *dst, struct net_device *lag); |
| 516 | 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] | 517 | int dsa_tree_notify(struct dsa_switch_tree *dst, unsigned long e, void *v); |
| 518 | int dsa_broadcast(unsigned long e, void *v); |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 519 | int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst, |
| 520 | struct net_device *master, |
| 521 | const struct dsa_device_ops *tag_ops, |
| 522 | const struct dsa_device_ops *old_tag_ops); |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 523 | |
Vladimir Oltean | e19cc13 | 2021-07-19 20:14:51 +0300 | [diff] [blame] | 524 | /* tag_8021q.c */ |
| 525 | int dsa_tag_8021q_bridge_join(struct dsa_switch *ds, |
| 526 | struct dsa_notifier_bridge_info *info); |
| 527 | int dsa_tag_8021q_bridge_leave(struct dsa_switch *ds, |
| 528 | struct dsa_notifier_bridge_info *info); |
Vladimir Oltean | c64b9c0 | 2021-07-19 20:14:52 +0300 | [diff] [blame] | 529 | int dsa_switch_tag_8021q_vlan_add(struct dsa_switch *ds, |
| 530 | struct dsa_notifier_tag_8021q_vlan_info *info); |
| 531 | int dsa_switch_tag_8021q_vlan_del(struct dsa_switch *ds, |
| 532 | struct dsa_notifier_tag_8021q_vlan_info *info); |
Vladimir Oltean | e19cc13 | 2021-07-19 20:14:51 +0300 | [diff] [blame] | 533 | |
Vladimir Oltean | bff33f7 | 2020-03-27 21:55:43 +0200 | [diff] [blame] | 534 | extern struct list_head dsa_tree_list; |
| 535 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 536 | #endif |