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