Merge tag 'cxl-for-5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/cxl/cxl
[linux-2.6-block.git] / net / dsa / dsa_priv.h
CommitLineData
2874c5fd 1/* SPDX-License-Identifier: GPL-2.0-or-later */
91da11f8
LB
2/*
3 * net/dsa/dsa_priv.h - Hardware switch handling
e84665c9 4 * Copyright (c) 2008-2009 Marvell Semiconductor
91da11f8
LB
5 */
6
7#ifndef __DSA_PRIV_H
8#define __DSA_PRIV_H
9
412a1526 10#include <linux/if_bridge.h>
b6459415 11#include <linux/if_vlan.h>
91da11f8 12#include <linux/phy.h>
5075314e 13#include <linux/netdevice.h>
04ff53f9 14#include <linux/netpoll.h>
ea5dd34b 15#include <net/dsa.h>
e131a563 16#include <net/gro_cells.h>
5075314e 17
123abc06
VO
18#define DSA_MAX_NUM_OFFLOADING_BRIDGES BITS_PER_LONG
19
52c96f9d 20enum {
1faabf74 21 DSA_NOTIFIER_AGEING_TIME,
52c96f9d
VD
22 DSA_NOTIFIER_BRIDGE_JOIN,
23 DSA_NOTIFIER_BRIDGE_LEAVE,
685fb6a4
VD
24 DSA_NOTIFIER_FDB_ADD,
25 DSA_NOTIFIER_FDB_DEL,
3dc80afc
VO
26 DSA_NOTIFIER_HOST_FDB_ADD,
27 DSA_NOTIFIER_HOST_FDB_DEL,
e212fa7c
VO
28 DSA_NOTIFIER_LAG_FDB_ADD,
29 DSA_NOTIFIER_LAG_FDB_DEL,
058102a6
TW
30 DSA_NOTIFIER_LAG_CHANGE,
31 DSA_NOTIFIER_LAG_JOIN,
32 DSA_NOTIFIER_LAG_LEAVE,
8ae5bcdc
VD
33 DSA_NOTIFIER_MDB_ADD,
34 DSA_NOTIFIER_MDB_DEL,
b8e997c4
VO
35 DSA_NOTIFIER_HOST_MDB_ADD,
36 DSA_NOTIFIER_HOST_MDB_DEL,
d0c627b8
VD
37 DSA_NOTIFIER_VLAN_ADD,
38 DSA_NOTIFIER_VLAN_DEL,
134ef238
VO
39 DSA_NOTIFIER_HOST_VLAN_ADD,
40 DSA_NOTIFIER_HOST_VLAN_DEL,
bfcb8132 41 DSA_NOTIFIER_MTU,
53da0eba 42 DSA_NOTIFIER_TAG_PROTO,
dc452a47 43 DSA_NOTIFIER_TAG_PROTO_CONNECT,
7f297314 44 DSA_NOTIFIER_TAG_PROTO_DISCONNECT,
c64b9c05
VO
45 DSA_NOTIFIER_TAG_8021Q_VLAN_ADD,
46 DSA_NOTIFIER_TAG_8021Q_VLAN_DEL,
295ab96f 47 DSA_NOTIFIER_MASTER_STATE_CHANGE,
52c96f9d
VD
48};
49
1faabf74
VD
50/* DSA_NOTIFIER_AGEING_TIME */
51struct dsa_notifier_ageing_time_info {
1faabf74 52 unsigned int ageing_time;
1faabf74
VD
53};
54
52c96f9d
VD
55/* DSA_NOTIFIER_BRIDGE_* */
56struct dsa_notifier_bridge_info {
726816a1 57 const struct dsa_port *dp;
d3eed0e5 58 struct dsa_bridge bridge;
b079922b 59 bool tx_fwd_offload;
06b9cce4 60 struct netlink_ext_ack *extack;
52c96f9d
VD
61};
62
685fb6a4
VD
63/* DSA_NOTIFIER_FDB_* */
64struct dsa_notifier_fdb_info {
726816a1 65 const struct dsa_port *dp;
2acf4e6a
AS
66 const unsigned char *addr;
67 u16 vid;
c2693363 68 struct dsa_db db;
685fb6a4
VD
69};
70
e212fa7c
VO
71/* DSA_NOTIFIER_LAG_FDB_* */
72struct dsa_notifier_lag_fdb_info {
73 struct dsa_lag *lag;
74 const unsigned char *addr;
75 u16 vid;
c2693363 76 struct dsa_db db;
e212fa7c
VO
77};
78
8ae5bcdc
VD
79/* DSA_NOTIFIER_MDB_* */
80struct dsa_notifier_mdb_info {
726816a1 81 const struct dsa_port *dp;
8ae5bcdc 82 const struct switchdev_obj_port_mdb *mdb;
c2693363 83 struct dsa_db db;
8ae5bcdc
VD
84};
85
058102a6
TW
86/* DSA_NOTIFIER_LAG_* */
87struct dsa_notifier_lag_info {
726816a1 88 const struct dsa_port *dp;
dedd6a00 89 struct dsa_lag lag;
058102a6
TW
90 struct netdev_lag_upper_info *info;
91};
92
d0c627b8
VD
93/* DSA_NOTIFIER_VLAN_* */
94struct dsa_notifier_vlan_info {
726816a1 95 const struct dsa_port *dp;
d0c627b8 96 const struct switchdev_obj_port_vlan *vlan;
31046a5f 97 struct netlink_ext_ack *extack;
d0c627b8
VD
98};
99
bfcb8132
VO
100/* DSA_NOTIFIER_MTU */
101struct dsa_notifier_mtu_info {
726816a1 102 const struct dsa_port *dp;
bfcb8132
VO
103 int mtu;
104};
105
53da0eba
VO
106/* DSA_NOTIFIER_TAG_PROTO_* */
107struct dsa_notifier_tag_proto_info {
108 const struct dsa_device_ops *tag_ops;
109};
110
c64b9c05
VO
111/* DSA_NOTIFIER_TAG_8021Q_VLAN_* */
112struct dsa_notifier_tag_8021q_vlan_info {
726816a1 113 const struct dsa_port *dp;
c64b9c05
VO
114 u16 vid;
115};
116
295ab96f
VO
117/* DSA_NOTIFIER_MASTER_STATE_CHANGE */
118struct dsa_notifier_master_state_info {
119 const struct net_device *master;
120 bool operational;
121};
122
c4bb76a9 123struct dsa_switchdev_event_work {
4bed397c 124 struct net_device *dev;
93c79823 125 struct net_device *orig_dev;
c4bb76a9
VO
126 struct work_struct work;
127 unsigned long event;
128 /* Specific for SWITCHDEV_FDB_ADD_TO_DEVICE and
129 * SWITCHDEV_FDB_DEL_TO_DEVICE
130 */
131 unsigned char addr[ETH_ALEN];
132 u16 vid;
3dc80afc 133 bool host_addr;
c4bb76a9
VO
134};
135
5e8a1e03
VO
136enum dsa_standalone_event {
137 DSA_UC_ADD,
138 DSA_UC_DEL,
139 DSA_MC_ADD,
140 DSA_MC_DEL,
141};
142
143struct dsa_standalone_event_work {
144 struct work_struct work;
145 struct net_device *dev;
146 enum dsa_standalone_event event;
147 unsigned char addr[ETH_ALEN];
148 u16 vid;
149};
150
91da11f8 151struct dsa_slave_priv {
15240248 152 /* Copy of CPU port xmit for faster access in slave transmit hot path */
4ed70ce9 153 struct sk_buff * (*xmit)(struct sk_buff *skb,
5075314e 154 struct net_device *dev);
e84665c9 155
e131a563
AL
156 struct gro_cells gcells;
157
afdcf151
VD
158 /* DSA port data, such as switch, port index, etc. */
159 struct dsa_port *dp;
e84665c9 160
04ff53f9
FF
161#ifdef CONFIG_NET_POLL_CONTROLLER
162 struct netpoll *netpoll;
163#endif
f50f2127
FF
164
165 /* TC context */
166 struct list_head mall_tc_list;
91da11f8
LB
167};
168
91da11f8 169/* dsa.c */
c39e2a1d 170const struct dsa_device_ops *dsa_tag_driver_get(int tag_protocol);
4dad81ee 171void dsa_tag_driver_put(const struct dsa_device_ops *ops);
53da0eba 172const struct dsa_device_ops *dsa_find_tagger_by_name(const char *buf);
c39e2a1d 173
7e580490
VO
174bool dsa_db_equal(const struct dsa_db *a, const struct dsa_db *b);
175
c9eb3e0f 176bool dsa_schedule_work(struct work_struct *work);
98cdb480 177const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops);
91da11f8 178
4e500251
VO
179static inline int dsa_tag_protocol_overhead(const struct dsa_device_ops *ops)
180{
181 return ops->needed_headroom + ops->needed_tailroom;
182}
183
f2f23566 184/* master.c */
17a22fcf
VD
185int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp);
186void dsa_master_teardown(struct net_device *dev);
f2f23566 187
2231c43b
VD
188static inline struct net_device *dsa_master_find_slave(struct net_device *dev,
189 int device, int port)
3775b1b7 190{
2f657a60
VD
191 struct dsa_port *cpu_dp = dev->dsa_ptr;
192 struct dsa_switch_tree *dst = cpu_dp->dst;
7b9a2f4b 193 struct dsa_port *dp;
3775b1b7 194
7b9a2f4b
VD
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;
3775b1b7 199
7b9a2f4b 200 return NULL;
3775b1b7
VD
201}
202
a40c175b 203/* port.c */
53da0eba
VO
204void dsa_port_set_tag_protocol(struct dsa_port *cpu_dp,
205 const struct dsa_device_ops *tag_ops);
39f32101 206int dsa_port_set_state(struct dsa_port *dp, u8 state, bool do_fast_age);
7414af30
TW
207int dsa_port_set_mst_state(struct dsa_port *dp,
208 const struct switchdev_mst_state *state,
209 struct netlink_ext_ack *extack);
8640f8dc 210int dsa_port_enable_rt(struct dsa_port *dp, struct phy_device *phy);
fb8a6a2b 211int dsa_port_enable(struct dsa_port *dp, struct phy_device *phy);
8640f8dc 212void dsa_port_disable_rt(struct dsa_port *dp);
75104db0 213void dsa_port_disable(struct dsa_port *dp);
2afc526a
VO
214int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br,
215 struct netlink_ext_ack *extack);
4e51bf44 216void dsa_port_pre_bridge_leave(struct dsa_port *dp, struct net_device *br);
cfbed329 217void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br);
058102a6
TW
218int dsa_port_lag_change(struct dsa_port *dp,
219 struct netdev_lag_lower_state_info *linfo);
220int dsa_port_lag_join(struct dsa_port *dp, struct net_device *lag_dev,
2afc526a
VO
221 struct netdev_lag_upper_info *uinfo,
222 struct netlink_ext_ack *extack);
4e51bf44 223void dsa_port_pre_lag_leave(struct dsa_port *dp, struct net_device *lag_dev);
058102a6 224void dsa_port_lag_leave(struct dsa_port *dp, struct net_device *lag_dev);
89153ed6
VO
225int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering,
226 struct netlink_ext_ack *extack);
54a0ed0d 227bool dsa_port_skip_vlan_configuration(struct dsa_port *dp);
bae33f2b 228int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock);
332afc4c
TW
229int dsa_port_mst_enable(struct dsa_port *dp, bool on,
230 struct netlink_ext_ack *extack);
8e6598a7
TW
231int dsa_port_vlan_msti(struct dsa_port *dp,
232 const struct switchdev_vlan_msti *msti);
be6ff966 233int dsa_port_mtu_change(struct dsa_port *dp, int new_mtu);
2acf4e6a
AS
234int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr,
235 u16 vid);
236int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr,
237 u16 vid);
5e8a1e03
VO
238int dsa_port_standalone_host_fdb_add(struct dsa_port *dp,
239 const unsigned char *addr, u16 vid);
240int dsa_port_standalone_host_fdb_del(struct dsa_port *dp,
241 const unsigned char *addr, u16 vid);
68d6d71e
VO
242int dsa_port_bridge_host_fdb_add(struct dsa_port *dp, const unsigned char *addr,
243 u16 vid);
244int dsa_port_bridge_host_fdb_del(struct dsa_port *dp, const unsigned char *addr,
245 u16 vid);
e212fa7c
VO
246int dsa_port_lag_fdb_add(struct dsa_port *dp, const unsigned char *addr,
247 u16 vid);
248int dsa_port_lag_fdb_del(struct dsa_port *dp, const unsigned char *addr,
249 u16 vid);
de40fc5d 250int dsa_port_fdb_dump(struct dsa_port *dp, dsa_fdb_dump_cb_t *cb, void *data);
bb9f6031 251int dsa_port_mdb_add(const struct dsa_port *dp,
ffb68fc5 252 const struct switchdev_obj_port_mdb *mdb);
bb9f6031 253int dsa_port_mdb_del(const struct dsa_port *dp,
3a9afea3 254 const struct switchdev_obj_port_mdb *mdb);
5e8a1e03
VO
255int dsa_port_standalone_host_mdb_add(const struct dsa_port *dp,
256 const struct switchdev_obj_port_mdb *mdb);
257int dsa_port_standalone_host_mdb_del(const struct dsa_port *dp,
258 const struct switchdev_obj_port_mdb *mdb);
68d6d71e
VO
259int dsa_port_bridge_host_mdb_add(const struct dsa_port *dp,
260 const struct switchdev_obj_port_mdb *mdb);
261int dsa_port_bridge_host_mdb_del(const struct dsa_port *dp,
262 const struct switchdev_obj_port_mdb *mdb);
e18f4c18 263int dsa_port_pre_bridge_flags(const struct dsa_port *dp,
a8b659e7
VO
264 struct switchdev_brport_flags flags,
265 struct netlink_ext_ack *extack);
045c45d1 266int dsa_port_bridge_flags(struct dsa_port *dp,
a8b659e7
VO
267 struct switchdev_brport_flags flags,
268 struct netlink_ext_ack *extack);
076e7133 269int dsa_port_vlan_add(struct dsa_port *dp,
31046a5f
VO
270 const struct switchdev_obj_port_vlan *vlan,
271 struct netlink_ext_ack *extack);
076e7133
VD
272int dsa_port_vlan_del(struct dsa_port *dp,
273 const struct switchdev_obj_port_vlan *vlan);
134ef238
VO
274int dsa_port_host_vlan_add(struct dsa_port *dp,
275 const struct switchdev_obj_port_vlan *vlan,
276 struct netlink_ext_ack *extack);
277int dsa_port_host_vlan_del(struct dsa_port *dp,
278 const struct switchdev_obj_port_vlan *vlan);
c595c433
HV
279int dsa_port_mrp_add(const struct dsa_port *dp,
280 const struct switchdev_obj_mrp *mrp);
281int dsa_port_mrp_del(const struct dsa_port *dp,
282 const struct switchdev_obj_mrp *mrp);
283int dsa_port_mrp_add_ring_role(const struct dsa_port *dp,
284 const struct switchdev_obj_ring_role_mrp *mrp);
285int dsa_port_mrp_del_ring_role(const struct dsa_port *dp,
286 const struct switchdev_obj_ring_role_mrp *mrp);
21bd64bd 287int dsa_port_phylink_create(struct dsa_port *dp);
33615367
SR
288int dsa_port_link_register_of(struct dsa_port *dp);
289void dsa_port_link_unregister_of(struct dsa_port *dp);
18596f50
GM
290int dsa_port_hsr_join(struct dsa_port *dp, struct net_device *hsr);
291void dsa_port_hsr_leave(struct dsa_port *dp, struct net_device *hsr);
724395f4
VO
292int dsa_port_tag_8021q_vlan_add(struct dsa_port *dp, u16 vid, bool broadcast);
293void dsa_port_tag_8021q_vlan_del(struct dsa_port *dp, u16 vid, bool broadcast);
72c3b0c7 294void dsa_port_set_host_flood(struct dsa_port *dp, bool uc, bool mc);
57ab1ca2 295
91da11f8 296/* slave.c */
5075314e 297extern const struct dsa_device_ops notag_netdev_ops;
010e269f
VO
298extern struct notifier_block dsa_slave_switchdev_notifier;
299extern struct notifier_block dsa_slave_switchdev_blocking_notifier;
300
91da11f8 301void dsa_slave_mii_bus_init(struct dsa_switch *ds);
951259aa 302int dsa_slave_create(struct dsa_port *dp);
cda5c15b 303void dsa_slave_destroy(struct net_device *slave_dev);
24462549
FF
304int dsa_slave_suspend(struct net_device *slave_dev);
305int dsa_slave_resume(struct net_device *slave_dev);
88e4f0ca
VD
306int dsa_slave_register_notifier(void);
307void dsa_slave_unregister_notifier(void);
53da0eba
VO
308void dsa_slave_setup_tagger(struct net_device *slave);
309int dsa_slave_change_mtu(struct net_device *dev, int new_mtu);
06cfb2df
VO
310int dsa_slave_manage_vlan_filtering(struct net_device *dev,
311 bool vlan_filtering);
91da11f8 312
d945097b
VD
313static inline struct dsa_port *dsa_slave_to_port(const struct net_device *dev)
314{
315 struct dsa_slave_priv *p = netdev_priv(dev);
316
317 return p->dp;
318}
319
d0006b00
VD
320static inline struct net_device *
321dsa_slave_to_master(const struct net_device *dev)
322{
323 struct dsa_port *dp = dsa_slave_to_port(dev);
324
f8b8b1cd 325 return dp->cpu_dp->master;
d0006b00
VD
326}
327
412a1526
VO
328/* If under a bridge with vlan_filtering=0, make sure to send pvid-tagged
329 * frames as untagged, since the bridge will not untag them.
330 */
331static inline struct sk_buff *dsa_untag_bridge_pvid(struct sk_buff *skb)
332{
333 struct dsa_port *dp = dsa_slave_to_port(skb->dev);
36cbf39b 334 struct net_device *br = dsa_port_bridge_dev_get(dp);
412a1526
VO
335 struct net_device *dev = skb->dev;
336 struct net_device *upper_dev;
412a1526
VO
337 u16 vid, pvid, proto;
338 int err;
339
340 if (!br || br_vlan_enabled(br))
341 return skb;
342
343 err = br_vlan_get_proto(br, &proto);
344 if (err)
345 return skb;
346
347 /* Move VLAN tag from data to hwaccel */
a348292b 348 if (!skb_vlan_tag_present(skb) && skb->protocol == htons(proto)) {
412a1526
VO
349 skb = skb_vlan_untag(skb);
350 if (!skb)
351 return NULL;
352 }
353
354 if (!skb_vlan_tag_present(skb))
355 return skb;
356
357 vid = skb_vlan_tag_get_id(skb);
358
359 /* We already run under an RCU read-side critical section since
360 * we are called from netif_receive_skb_list_internal().
361 */
362 err = br_vlan_get_pvid_rcu(dev, &pvid);
363 if (err)
364 return skb;
365
366 if (vid != pvid)
367 return skb;
368
369 /* The sad part about attempting to untag from DSA is that we
370 * don't know, unless we check, if the skb will end up in
371 * the bridge's data path - br_allowed_ingress() - or not.
372 * For example, there might be an 8021q upper for the
373 * default_pvid of the bridge, which will steal VLAN-tagged traffic
374 * from the bridge's data path. This is a configuration that DSA
375 * supports because vlan_filtering is 0. In that case, we should
376 * definitely keep the tag, to make sure it keeps working.
377 */
3a68844d
FF
378 upper_dev = __vlan_find_dev_deep_rcu(br, htons(proto), vid);
379 if (upper_dev)
380 return skb;
412a1526
VO
381
382 __vlan_hwaccel_clear_tag(skb);
383
384 return skb;
385}
386
884be12f
VO
387/* For switches without hardware support for DSA tagging to be able
388 * to support termination through the bridge.
389 */
390static inline struct net_device *
391dsa_find_designated_bridge_port_by_vid(struct net_device *master, u16 vid)
392{
393 struct dsa_port *cpu_dp = master->dsa_ptr;
394 struct dsa_switch_tree *dst = cpu_dp->dst;
395 struct bridge_vlan_info vinfo;
396 struct net_device *slave;
397 struct dsa_port *dp;
398 int err;
399
400 list_for_each_entry(dp, &dst->ports, list) {
401 if (dp->type != DSA_PORT_TYPE_USER)
402 continue;
403
d3eed0e5 404 if (!dp->bridge)
884be12f
VO
405 continue;
406
407 if (dp->stp_state != BR_STATE_LEARNING &&
408 dp->stp_state != BR_STATE_FORWARDING)
409 continue;
410
411 /* Since the bridge might learn this packet, keep the CPU port
412 * affinity with the port that will be used for the reply on
413 * xmit.
414 */
415 if (dp->cpu_dp != cpu_dp)
416 continue;
417
418 slave = dp->slave;
419
420 err = br_vlan_get_info_rcu(slave, vid, &vinfo);
421 if (err)
422 continue;
423
424 return slave;
425 }
426
427 return NULL;
428}
429
bea79078
VO
430/* If the ingress port offloads the bridge, we mark the frame as autonomously
431 * forwarded by hardware, so the software bridge doesn't forward in twice, back
432 * to us, because we already did. However, if we're in fallback mode and we do
d3eed0e5 433 * software bridging, we are not offloading it, therefore the dp->bridge
bea79078
VO
434 * pointer is not populated, and flooding needs to be done by software (we are
435 * effectively operating in standalone ports mode).
436 */
437static inline void dsa_default_offload_fwd_mark(struct sk_buff *skb)
438{
439 struct dsa_port *dp = dsa_slave_to_port(skb->dev);
440
d3eed0e5 441 skb->offload_fwd_mark = !!(dp->bridge);
bea79078
VO
442}
443
f1dacd7a
VO
444/* Helper for removing DSA header tags from packets in the RX path.
445 * Must not be called before skb_pull(len).
446 * skb->data
447 * |
448 * v
449 * | | | | | | | | | | | | | | | | | | |
450 * +-----------------------+-----------------------+---------------+-------+
451 * | Destination MAC | Source MAC | DSA header | EType |
452 * +-----------------------+-----------------------+---------------+-------+
453 * | |
454 * <----- len -----> <----- len ----->
455 * |
456 * >>>>>>> v
457 * >>>>>>> | | | | | | | | | | | | | | |
458 * >>>>>>> +-----------------------+-----------------------+-------+
459 * >>>>>>> | Destination MAC | Source MAC | EType |
460 * +-----------------------+-----------------------+-------+
461 * ^
462 * |
463 * skb->data
464 */
465static inline void dsa_strip_etype_header(struct sk_buff *skb, int len)
466{
467 memmove(skb->data - ETH_HLEN, skb->data - ETH_HLEN - len, 2 * ETH_ALEN);
468}
469
6bef794d
VO
470/* Helper for creating space for DSA header tags in TX path packets.
471 * Must not be called before skb_push(len).
472 *
473 * Before:
474 *
475 * <<<<<<< | | | | | | | | | | | | | | |
476 * ^ <<<<<<< +-----------------------+-----------------------+-------+
477 * | <<<<<<< | Destination MAC | Source MAC | EType |
478 * | +-----------------------+-----------------------+-------+
479 * <----- len ----->
480 * |
481 * |
482 * skb->data
483 *
484 * After:
485 *
486 * | | | | | | | | | | | | | | | | | | |
487 * +-----------------------+-----------------------+---------------+-------+
488 * | Destination MAC | Source MAC | DSA header | EType |
489 * +-----------------------+-----------------------+---------------+-------+
490 * ^ | |
491 * | <----- len ----->
492 * skb->data
493 */
494static inline void dsa_alloc_etype_header(struct sk_buff *skb, int len)
495{
496 memmove(skb->data, skb->data + len, 2 * ETH_ALEN);
497}
498
5d928ff4
VO
499/* On RX, eth_type_trans() on the DSA master pulls ETH_HLEN bytes starting from
500 * skb_mac_header(skb), which leaves skb->data pointing at the first byte after
501 * what the DSA master perceives as the EtherType (the beginning of the L3
502 * protocol). Since DSA EtherType header taggers treat the EtherType as part of
503 * the DSA tag itself, and the EtherType is 2 bytes in length, the DSA header
504 * is located 2 bytes behind skb->data. Note that EtherType in this context
505 * means the first 2 bytes of the DSA header, not the encapsulated EtherType
506 * that will become visible after the DSA header is stripped.
507 */
508static inline void *dsa_etype_header_pos_rx(struct sk_buff *skb)
509{
510 return skb->data - 2;
511}
512
a72808b6
VO
513/* On TX, skb->data points to skb_mac_header(skb), which means that EtherType
514 * header taggers start exactly where the EtherType is (the EtherType is
515 * treated as part of the DSA header).
516 */
517static inline void *dsa_etype_header_pos_tx(struct sk_buff *skb)
518{
519 return skb->data + 2 * ETH_ALEN;
520}
521
f515f192
VD
522/* switch.c */
523int dsa_switch_register_notifier(struct dsa_switch *ds);
524void dsa_switch_unregister_notifier(struct dsa_switch *ds);
bff33f7e 525
5e8a1e03
VO
526static inline bool dsa_switch_supports_uc_filtering(struct dsa_switch *ds)
527{
528 return ds->ops->port_fdb_add && ds->ops->port_fdb_del &&
529 ds->fdb_isolation && !ds->vlan_filtering_is_global &&
530 !ds->needs_standalone_vlan_filtering;
531}
532
533static inline bool dsa_switch_supports_mc_filtering(struct dsa_switch *ds)
534{
535 return ds->ops->port_mdb_add && ds->ops->port_mdb_del &&
536 ds->fdb_isolation && !ds->vlan_filtering_is_global &&
537 !ds->needs_standalone_vlan_filtering;
538}
539
bff33f7e 540/* dsa2.c */
dedd6a00
VO
541void dsa_lag_map(struct dsa_switch_tree *dst, struct dsa_lag *lag);
542void dsa_lag_unmap(struct dsa_switch_tree *dst, struct dsa_lag *lag);
543struct dsa_lag *dsa_tree_lag_find(struct dsa_switch_tree *dst,
544 const struct net_device *lag_dev);
886f8e26
VO
545int dsa_tree_notify(struct dsa_switch_tree *dst, unsigned long e, void *v);
546int dsa_broadcast(unsigned long e, void *v);
53da0eba
VO
547int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst,
548 struct net_device *master,
549 const struct dsa_device_ops *tag_ops,
550 const struct dsa_device_ops *old_tag_ops);
295ab96f
VO
551void dsa_tree_master_admin_state_change(struct dsa_switch_tree *dst,
552 struct net_device *master,
553 bool up);
554void dsa_tree_master_oper_state_change(struct dsa_switch_tree *dst,
555 struct net_device *master,
556 bool up);
3f9bb030
VO
557unsigned int dsa_bridge_num_get(const struct net_device *bridge_dev, int max);
558void dsa_bridge_num_put(const struct net_device *bridge_dev,
559 unsigned int bridge_num);
d3eed0e5
VO
560struct dsa_bridge *dsa_tree_bridge_find(struct dsa_switch_tree *dst,
561 const struct net_device *br);
058102a6 562
e19cc13c 563/* tag_8021q.c */
c64b9c05
VO
564int dsa_switch_tag_8021q_vlan_add(struct dsa_switch *ds,
565 struct dsa_notifier_tag_8021q_vlan_info *info);
566int dsa_switch_tag_8021q_vlan_del(struct dsa_switch *ds,
567 struct dsa_notifier_tag_8021q_vlan_info *info);
e19cc13c 568
bff33f7e
VO
569extern struct list_head dsa_tree_list;
570
91da11f8 571#endif