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