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