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