Commit | Line | Data |
---|---|---|
2874c5fd | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
91da11f8 LB |
2 | /* |
3 | * include/net/dsa.h - Driver for Distributed Switch Architecture switch chips | |
e84665c9 | 4 | * Copyright (c) 2008-2009 Marvell Semiconductor |
91da11f8 LB |
5 | */ |
6 | ||
7 | #ifndef __LINUX_NET_DSA_H | |
8 | #define __LINUX_NET_DSA_H | |
9 | ||
4d56a29f | 10 | #include <linux/if.h> |
ea1f51be | 11 | #include <linux/if_ether.h> |
c8f0b869 | 12 | #include <linux/list.h> |
f515f192 | 13 | #include <linux/notifier.h> |
cf50dcc2 BH |
14 | #include <linux/timer.h> |
15 | #include <linux/workqueue.h> | |
fa981d9a | 16 | #include <linux/of.h> |
a2820543 | 17 | #include <linux/ethtool.h> |
0336369d | 18 | #include <linux/net_tstamp.h> |
11d8f3dd | 19 | #include <linux/phy.h> |
ecfc9372 | 20 | #include <linux/platform_data/dsa.h> |
44cc27e4 | 21 | #include <linux/phylink.h> |
96567d5d | 22 | #include <net/devlink.h> |
f0c24ccf | 23 | #include <net/switchdev.h> |
cf50dcc2 | 24 | |
19d05ea7 | 25 | struct dsa_8021q_context; |
f50f2127 | 26 | struct tc_action; |
4d56a29f RK |
27 | struct phy_device; |
28 | struct fixed_phy_status; | |
11d8f3dd | 29 | struct phylink_link_state; |
f50f2127 | 30 | |
0b42f033 AL |
31 | #define DSA_TAG_PROTO_NONE_VALUE 0 |
32 | #define DSA_TAG_PROTO_BRCM_VALUE 1 | |
33 | #define DSA_TAG_PROTO_BRCM_PREPEND_VALUE 2 | |
34 | #define DSA_TAG_PROTO_DSA_VALUE 3 | |
35 | #define DSA_TAG_PROTO_EDSA_VALUE 4 | |
36 | #define DSA_TAG_PROTO_GSWIP_VALUE 5 | |
37 | #define DSA_TAG_PROTO_KSZ9477_VALUE 6 | |
38 | #define DSA_TAG_PROTO_KSZ9893_VALUE 7 | |
39 | #define DSA_TAG_PROTO_LAN9303_VALUE 8 | |
40 | #define DSA_TAG_PROTO_MTK_VALUE 9 | |
41 | #define DSA_TAG_PROTO_QCA_VALUE 10 | |
42 | #define DSA_TAG_PROTO_TRAILER_VALUE 11 | |
f9bbe447 | 43 | #define DSA_TAG_PROTO_8021Q_VALUE 12 |
227d07a0 | 44 | #define DSA_TAG_PROTO_SJA1105_VALUE 13 |
016e43a2 | 45 | #define DSA_TAG_PROTO_KSZ8795_VALUE 14 |
8dce89aa | 46 | #define DSA_TAG_PROTO_OCELOT_VALUE 15 |
48fda74f | 47 | #define DSA_TAG_PROTO_AR9331_VALUE 16 |
efd7fe68 | 48 | #define DSA_TAG_PROTO_RTL4_A_VALUE 17 |
01ef09ca | 49 | #define DSA_TAG_PROTO_HELLCREEK_VALUE 18 |
54a52823 | 50 | #define DSA_TAG_PROTO_XRS700X_VALUE 19 |
7c83a7c5 | 51 | #define DSA_TAG_PROTO_OCELOT_8021Q_VALUE 20 |
7c4bb540 | 52 | #define DSA_TAG_PROTO_SEVILLE_VALUE 21 |
964dbf18 | 53 | #define DSA_TAG_PROTO_BRCM_LEGACY_VALUE 22 |
4913b8eb | 54 | #define DSA_TAG_PROTO_SJA1110_VALUE 23 |
1521d5ad | 55 | #define DSA_TAG_PROTO_RTL8_4_VALUE 24 |
cd87fecd | 56 | #define DSA_TAG_PROTO_RTL8_4T_VALUE 25 |
a08d6a6d | 57 | #define DSA_TAG_PROTO_RZN1_A5PSW_VALUE 26 |
092f8751 | 58 | #define DSA_TAG_PROTO_LAN937X_VALUE 27 |
0b42f033 | 59 | |
ac7a04c3 | 60 | enum dsa_tag_protocol { |
0b42f033 AL |
61 | DSA_TAG_PROTO_NONE = DSA_TAG_PROTO_NONE_VALUE, |
62 | DSA_TAG_PROTO_BRCM = DSA_TAG_PROTO_BRCM_VALUE, | |
964dbf18 | 63 | DSA_TAG_PROTO_BRCM_LEGACY = DSA_TAG_PROTO_BRCM_LEGACY_VALUE, |
0b42f033 AL |
64 | DSA_TAG_PROTO_BRCM_PREPEND = DSA_TAG_PROTO_BRCM_PREPEND_VALUE, |
65 | DSA_TAG_PROTO_DSA = DSA_TAG_PROTO_DSA_VALUE, | |
66 | DSA_TAG_PROTO_EDSA = DSA_TAG_PROTO_EDSA_VALUE, | |
67 | DSA_TAG_PROTO_GSWIP = DSA_TAG_PROTO_GSWIP_VALUE, | |
68 | DSA_TAG_PROTO_KSZ9477 = DSA_TAG_PROTO_KSZ9477_VALUE, | |
69 | DSA_TAG_PROTO_KSZ9893 = DSA_TAG_PROTO_KSZ9893_VALUE, | |
70 | DSA_TAG_PROTO_LAN9303 = DSA_TAG_PROTO_LAN9303_VALUE, | |
71 | DSA_TAG_PROTO_MTK = DSA_TAG_PROTO_MTK_VALUE, | |
72 | DSA_TAG_PROTO_QCA = DSA_TAG_PROTO_QCA_VALUE, | |
73 | DSA_TAG_PROTO_TRAILER = DSA_TAG_PROTO_TRAILER_VALUE, | |
f9bbe447 | 74 | DSA_TAG_PROTO_8021Q = DSA_TAG_PROTO_8021Q_VALUE, |
227d07a0 | 75 | DSA_TAG_PROTO_SJA1105 = DSA_TAG_PROTO_SJA1105_VALUE, |
016e43a2 | 76 | DSA_TAG_PROTO_KSZ8795 = DSA_TAG_PROTO_KSZ8795_VALUE, |
8dce89aa | 77 | DSA_TAG_PROTO_OCELOT = DSA_TAG_PROTO_OCELOT_VALUE, |
48fda74f | 78 | DSA_TAG_PROTO_AR9331 = DSA_TAG_PROTO_AR9331_VALUE, |
efd7fe68 | 79 | DSA_TAG_PROTO_RTL4_A = DSA_TAG_PROTO_RTL4_A_VALUE, |
01ef09ca | 80 | DSA_TAG_PROTO_HELLCREEK = DSA_TAG_PROTO_HELLCREEK_VALUE, |
54a52823 | 81 | DSA_TAG_PROTO_XRS700X = DSA_TAG_PROTO_XRS700X_VALUE, |
7c83a7c5 | 82 | DSA_TAG_PROTO_OCELOT_8021Q = DSA_TAG_PROTO_OCELOT_8021Q_VALUE, |
7c4bb540 | 83 | DSA_TAG_PROTO_SEVILLE = DSA_TAG_PROTO_SEVILLE_VALUE, |
4913b8eb | 84 | DSA_TAG_PROTO_SJA1110 = DSA_TAG_PROTO_SJA1110_VALUE, |
1521d5ad | 85 | DSA_TAG_PROTO_RTL8_4 = DSA_TAG_PROTO_RTL8_4_VALUE, |
cd87fecd | 86 | DSA_TAG_PROTO_RTL8_4T = DSA_TAG_PROTO_RTL8_4T_VALUE, |
a08d6a6d | 87 | DSA_TAG_PROTO_RZN1_A5PSW = DSA_TAG_PROTO_RZN1_A5PSW_VALUE, |
092f8751 | 88 | DSA_TAG_PROTO_LAN937X = DSA_TAG_PROTO_LAN937X_VALUE, |
ac7a04c3 | 89 | }; |
5037d532 | 90 | |
90af1059 | 91 | struct dsa_switch; |
3e8a72d1 | 92 | |
68277a2c JC |
93 | struct dsa_device_ops { |
94 | struct sk_buff *(*xmit)(struct sk_buff *skb, struct net_device *dev); | |
29a097b7 | 95 | struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev); |
2e8cb1b3 VO |
96 | void (*flow_dissect)(const struct sk_buff *skb, __be16 *proto, |
97 | int *offset); | |
7f297314 VO |
98 | int (*connect)(struct dsa_switch *ds); |
99 | void (*disconnect)(struct dsa_switch *ds); | |
4e500251 VO |
100 | unsigned int needed_headroom; |
101 | unsigned int needed_tailroom; | |
875138f8 | 102 | const char *name; |
056eed2f | 103 | enum dsa_tag_protocol proto; |
c3975400 VO |
104 | /* Some tagging protocols either mangle or shift the destination MAC |
105 | * address, in which case the DSA master would drop packets on ingress | |
106 | * if what it understands out of the destination MAC address is not in | |
107 | * its RX filter. | |
108 | */ | |
109 | bool promisc_on_master; | |
68277a2c JC |
110 | }; |
111 | ||
dedd6a00 VO |
112 | struct dsa_lag { |
113 | struct net_device *dev; | |
114 | unsigned int id; | |
e212fa7c VO |
115 | struct mutex fdb_lock; |
116 | struct list_head fdbs; | |
dedd6a00 VO |
117 | refcount_t refcount; |
118 | }; | |
119 | ||
cf50dcc2 | 120 | struct dsa_switch_tree { |
83c0afae AL |
121 | struct list_head list; |
122 | ||
b035c88c VO |
123 | /* List of switch ports */ |
124 | struct list_head ports; | |
125 | ||
f515f192 VD |
126 | /* Notifier chain for switch-wide events */ |
127 | struct raw_notifier_head nh; | |
128 | ||
83c0afae | 129 | /* Tree identifier */ |
49463b7f | 130 | unsigned int index; |
83c0afae AL |
131 | |
132 | /* Number of switches attached to this tree */ | |
133 | struct kref refcount; | |
134 | ||
b035c88c VO |
135 | /* Maps offloaded LAG netdevs to a zero-based linear ID for |
136 | * drivers that need it. | |
137 | */ | |
dedd6a00 | 138 | struct dsa_lag **lags; |
b035c88c | 139 | |
357f203b VO |
140 | /* Tagging protocol operations */ |
141 | const struct dsa_device_ops *tag_ops; | |
142 | ||
deff7107 TW |
143 | /* Default tagging protocol preferred by the switches in this |
144 | * tree. | |
145 | */ | |
146 | enum dsa_tag_protocol default_proto; | |
147 | ||
4b026e82 VO |
148 | /* Has this tree been applied to the hardware? */ |
149 | bool setup; | |
150 | ||
cf50dcc2 BH |
151 | /* |
152 | * Configuration data for the platform device that owns | |
153 | * this dsa switch tree instance. | |
154 | */ | |
155 | struct dsa_platform_data *pd; | |
156 | ||
c5f51765 VD |
157 | /* List of DSA links composing the routing table */ |
158 | struct list_head rtable; | |
058102a6 | 159 | |
b035c88c | 160 | /* Length of "lags" array */ |
058102a6 | 161 | unsigned int lags_len; |
5b22d366 VO |
162 | |
163 | /* Track the largest switch index within a tree */ | |
164 | unsigned int last_switch; | |
cf50dcc2 BH |
165 | }; |
166 | ||
3d4a0a2a | 167 | /* LAG IDs are one-based, the dst->lags array is zero-based */ |
058102a6 | 168 | #define dsa_lags_foreach_id(_id, _dst) \ |
3d4a0a2a VO |
169 | for ((_id) = 1; (_id) <= (_dst)->lags_len; (_id)++) \ |
170 | if ((_dst)->lags[(_id) - 1]) | |
058102a6 TW |
171 | |
172 | #define dsa_lag_foreach_port(_dp, _dst, _lag) \ | |
173 | list_for_each_entry((_dp), &(_dst)->ports, list) \ | |
dedd6a00 | 174 | if (dsa_port_offloads_lag((_dp), (_lag))) |
058102a6 | 175 | |
18596f50 GM |
176 | #define dsa_hsr_foreach_port(_dp, _ds, _hsr) \ |
177 | list_for_each_entry((_dp), &(_ds)->dst->ports, list) \ | |
178 | if ((_dp)->ds == (_ds) && (_dp)->hsr_dev == (_hsr)) | |
179 | ||
dedd6a00 VO |
180 | static inline struct dsa_lag *dsa_lag_by_id(struct dsa_switch_tree *dst, |
181 | unsigned int id) | |
058102a6 | 182 | { |
3d4a0a2a VO |
183 | /* DSA LAG IDs are one-based, dst->lags is zero-based */ |
184 | return dst->lags[id - 1]; | |
058102a6 TW |
185 | } |
186 | ||
187 | static inline int dsa_lag_id(struct dsa_switch_tree *dst, | |
46a76724 | 188 | struct net_device *lag_dev) |
058102a6 TW |
189 | { |
190 | unsigned int id; | |
191 | ||
192 | dsa_lags_foreach_id(id, dst) { | |
dedd6a00 VO |
193 | struct dsa_lag *lag = dsa_lag_by_id(dst, id); |
194 | ||
195 | if (lag->dev == lag_dev) | |
196 | return lag->id; | |
058102a6 TW |
197 | } |
198 | ||
199 | return -ENODEV; | |
200 | } | |
201 | ||
34297176 | 202 | /* TC matchall action types */ |
f50f2127 FF |
203 | enum dsa_port_mall_action_type { |
204 | DSA_PORT_MALL_MIRROR, | |
34297176 | 205 | DSA_PORT_MALL_POLICER, |
f50f2127 FF |
206 | }; |
207 | ||
208 | /* TC mirroring entry */ | |
209 | struct dsa_mall_mirror_tc_entry { | |
210 | u8 to_local_port; | |
211 | bool ingress; | |
212 | }; | |
213 | ||
34297176 VO |
214 | /* TC port policer entry */ |
215 | struct dsa_mall_policer_tc_entry { | |
5f035af7 | 216 | u32 burst; |
34297176 VO |
217 | u64 rate_bytes_per_sec; |
218 | }; | |
219 | ||
f50f2127 FF |
220 | /* TC matchall entry */ |
221 | struct dsa_mall_tc_entry { | |
222 | struct list_head list; | |
223 | unsigned long cookie; | |
224 | enum dsa_port_mall_action_type type; | |
225 | union { | |
226 | struct dsa_mall_mirror_tc_entry mirror; | |
34297176 | 227 | struct dsa_mall_policer_tc_entry policer; |
f50f2127 FF |
228 | }; |
229 | }; | |
230 | ||
d3eed0e5 VO |
231 | struct dsa_bridge { |
232 | struct net_device *dev; | |
233 | unsigned int num; | |
857fdd74 | 234 | bool tx_fwd_offload; |
d3eed0e5 VO |
235 | refcount_t refcount; |
236 | }; | |
f50f2127 | 237 | |
c8b09808 | 238 | struct dsa_port { |
f8b8b1cd VD |
239 | /* A CPU port is physically connected to a master device. |
240 | * A user port exposed to userspace has a slave device. | |
241 | */ | |
242 | union { | |
243 | struct net_device *master; | |
244 | struct net_device *slave; | |
245 | }; | |
246 | ||
357f203b VO |
247 | /* Copy of the tagging protocol operations, for quicker access |
248 | * in the data path. Valid only for the CPU ports. | |
249 | */ | |
15240248 VD |
250 | const struct dsa_device_ops *tag_ops; |
251 | ||
3e41f93b VD |
252 | /* Copies for faster access in master receive hot path */ |
253 | struct dsa_switch_tree *dst; | |
29a097b7 | 254 | struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev); |
3e41f93b | 255 | |
06251258 VO |
256 | struct dsa_switch *ds; |
257 | ||
258 | unsigned int index; | |
259 | ||
057cad2c VD |
260 | enum { |
261 | DSA_PORT_TYPE_UNUSED = 0, | |
262 | DSA_PORT_TYPE_CPU, | |
263 | DSA_PORT_TYPE_DSA, | |
264 | DSA_PORT_TYPE_USER, | |
265 | } type; | |
266 | ||
71e0bbde | 267 | const char *name; |
68b2d4a8 | 268 | struct dsa_port *cpu_dp; |
83216e39 | 269 | u8 mac[ETH_ALEN]; |
b08db33d VO |
270 | |
271 | u8 stp_state; | |
272 | ||
1b26d364 VO |
273 | /* Warning: the following bit fields are not atomic, and updating them |
274 | * can only be done from code paths where concurrency is not possible | |
275 | * (probe time or under rtnl_lock). | |
276 | */ | |
63cfc657 VO |
277 | u8 vlan_filtering:1; |
278 | ||
279 | /* Managed by DSA on user ports and by drivers on CPU and DSA ports */ | |
280 | u8 learning:1; | |
281 | ||
282 | u8 lag_tx_enabled:1; | |
283 | ||
295ab96f VO |
284 | /* Master state bits, valid only on CPU ports */ |
285 | u8 master_admin_up:1; | |
286 | u8 master_oper_up:1; | |
287 | ||
acc43b7b VO |
288 | /* Valid only on user ports */ |
289 | u8 cpu_port_in_lag:1; | |
290 | ||
63cfc657 | 291 | u8 setup:1; |
bde82f38 | 292 | |
189b0d93 | 293 | struct device_node *dn; |
34a79f63 | 294 | unsigned int ageing_time; |
bde82f38 | 295 | |
d3eed0e5 | 296 | struct dsa_bridge *bridge; |
96567d5d | 297 | struct devlink_port devlink_port; |
aab9c406 | 298 | struct phylink *pl; |
44cc27e4 | 299 | struct phylink_config pl_config; |
dedd6a00 | 300 | struct dsa_lag *lag; |
18596f50 | 301 | struct net_device *hsr_dev; |
97a69a0d | 302 | |
ab8ccae1 VD |
303 | struct list_head list; |
304 | ||
67dbb9d4 FF |
305 | /* |
306 | * Original copy of the master netdev ethtool_ops | |
307 | */ | |
67dbb9d4 | 308 | const struct ethtool_ops *orig_ethtool_ops; |
da7b9e9b | 309 | |
161ca59d VO |
310 | /* List of MAC addresses that must be forwarded on this port. |
311 | * These are only valid on CPU ports and DSA links. | |
312 | */ | |
338a3a47 | 313 | struct mutex addr_lists_lock; |
3f6e32f9 | 314 | struct list_head fdbs; |
161ca59d | 315 | struct list_head mdbs; |
134ef238 VO |
316 | |
317 | /* List of VLANs that CPU and DSA ports are members of. */ | |
318 | struct mutex vlans_lock; | |
319 | struct list_head vlans; | |
c8b09808 AL |
320 | }; |
321 | ||
c5f51765 VD |
322 | /* TODO: ideally DSA ports would have a single dp->link_dp member, |
323 | * and no dst->rtable nor this struct dsa_link would be needed, | |
324 | * but this would require some more complex tree walking, | |
325 | * so keep it stupid at the moment and list them all. | |
326 | */ | |
327 | struct dsa_link { | |
328 | struct dsa_port *dp; | |
329 | struct dsa_port *link_dp; | |
330 | struct list_head list; | |
331 | }; | |
332 | ||
c2693363 VO |
333 | enum dsa_db_type { |
334 | DSA_DB_PORT, | |
335 | DSA_DB_LAG, | |
336 | DSA_DB_BRIDGE, | |
337 | }; | |
338 | ||
339 | struct dsa_db { | |
340 | enum dsa_db_type type; | |
341 | ||
342 | union { | |
343 | const struct dsa_port *dp; | |
344 | struct dsa_lag lag; | |
345 | struct dsa_bridge bridge; | |
346 | }; | |
347 | }; | |
348 | ||
161ca59d VO |
349 | struct dsa_mac_addr { |
350 | unsigned char addr[ETH_ALEN]; | |
351 | u16 vid; | |
352 | refcount_t refcount; | |
353 | struct list_head list; | |
c2693363 | 354 | struct dsa_db db; |
161ca59d VO |
355 | }; |
356 | ||
134ef238 VO |
357 | struct dsa_vlan { |
358 | u16 vid; | |
359 | refcount_t refcount; | |
360 | struct list_head list; | |
361 | }; | |
362 | ||
c8f0b869 | 363 | struct dsa_switch { |
c33063d6 AL |
364 | struct device *dev; |
365 | ||
c8f0b869 BH |
366 | /* |
367 | * Parent switch tree, and switch index. | |
368 | */ | |
369 | struct dsa_switch_tree *dst; | |
99feaafc | 370 | unsigned int index; |
c8f0b869 | 371 | |
1b26d364 VO |
372 | /* Warning: the following bit fields are not atomic, and updating them |
373 | * can only be done from code paths where concurrency is not possible | |
374 | * (probe time or under rtnl_lock). | |
375 | */ | |
63cfc657 VO |
376 | u32 setup:1; |
377 | ||
378 | /* Disallow bridge core from requesting different VLAN awareness | |
379 | * settings on ports if not hardware-supported | |
380 | */ | |
381 | u32 vlan_filtering_is_global:1; | |
382 | ||
383 | /* Keep VLAN filtering enabled on ports not offloading any upper */ | |
384 | u32 needs_standalone_vlan_filtering:1; | |
385 | ||
386 | /* Pass .port_vlan_add and .port_vlan_del to drivers even for bridges | |
387 | * that have vlan_filtering=0. All drivers should ideally set this (and | |
388 | * then the option would get removed), but it is unknown whether this | |
389 | * would break things or not. | |
390 | */ | |
391 | u32 configure_vlan_while_not_filtering:1; | |
392 | ||
393 | /* If the switch driver always programs the CPU port as egress tagged | |
394 | * despite the VLAN configuration indicating otherwise, then setting | |
395 | * @untag_bridge_pvid will force the DSA receive path to pop the | |
396 | * bridge's default_pvid VLAN tagged frames to offer a consistent | |
397 | * behavior between a vlan_filtering=0 and vlan_filtering=1 bridge | |
398 | * device. | |
399 | */ | |
400 | u32 untag_bridge_pvid:1; | |
401 | ||
402 | /* Let DSA manage the FDB entries towards the | |
403 | * CPU, based on the software bridge database. | |
404 | */ | |
405 | u32 assisted_learning_on_cpu_port:1; | |
406 | ||
407 | /* In case vlan_filtering_is_global is set, the VLAN awareness state | |
408 | * should be retrieved from here and not from the per-port settings. | |
409 | */ | |
410 | u32 vlan_filtering:1; | |
411 | ||
63cfc657 VO |
412 | /* For switches that only have the MRU configurable. To ensure the |
413 | * configured MTU is not exceeded, normalization of MRU on all bridged | |
414 | * interfaces is needed. | |
415 | */ | |
416 | u32 mtu_enforcement_ingress:1; | |
7787ff77 | 417 | |
c2693363 VO |
418 | /* Drivers that isolate the FDBs of multiple bridges must set this |
419 | * to true to receive the bridge as an argument in .port_fdb_{add,del} | |
420 | * and .port_mdb_{add,del}. Otherwise, the bridge.num will always be | |
421 | * passed as zero. | |
422 | */ | |
423 | u32 fdb_isolation:1; | |
424 | ||
f515f192 VD |
425 | /* Listener for switch fabric events */ |
426 | struct notifier_block nb; | |
427 | ||
7543a6d5 AL |
428 | /* |
429 | * Give the switch driver somewhere to hang its private data | |
430 | * structure. | |
431 | */ | |
432 | void *priv; | |
433 | ||
dc452a47 VO |
434 | void *tagger_data; |
435 | ||
c8f0b869 BH |
436 | /* |
437 | * Configuration data for this switch. | |
438 | */ | |
ff04955c | 439 | struct dsa_chip_data *cd; |
c8f0b869 BH |
440 | |
441 | /* | |
9d490b4e | 442 | * The switch operations. |
c8f0b869 | 443 | */ |
a82f67af | 444 | const struct dsa_switch_ops *ops; |
c8f0b869 | 445 | |
c8f0b869 BH |
446 | /* |
447 | * Slave mii_bus and devices for the individual ports. | |
448 | */ | |
0d8bcdd3 | 449 | u32 phys_mii_mask; |
c8f0b869 | 450 | struct mii_bus *slave_mii_bus; |
a0c02161 | 451 | |
0f3da6af VD |
452 | /* Ageing Time limits in msecs */ |
453 | unsigned int ageing_time_min; | |
454 | unsigned int ageing_time_max; | |
455 | ||
d7b1fd52 VO |
456 | /* Storage for drivers using tag_8021q */ |
457 | struct dsa_8021q_context *tag_8021q_ctx; | |
458 | ||
96567d5d AL |
459 | /* devlink used to represent this switch device */ |
460 | struct devlink *devlink; | |
461 | ||
55199df6 FF |
462 | /* Number of switch port queues */ |
463 | unsigned int num_tx_queues; | |
464 | ||
058102a6 TW |
465 | /* Drivers that benefit from having an ID associated with each |
466 | * offloaded LAG should set this to the maximum number of | |
467 | * supported IDs. DSA will then maintain a mapping of _at | |
468 | * least_ these many IDs, accessible to drivers via | |
469 | * dsa_lag_id(). | |
470 | */ | |
471 | unsigned int num_lag_ids; | |
472 | ||
947c8746 VO |
473 | /* Drivers that support bridge forwarding offload or FDB isolation |
474 | * should set this to the maximum number of bridges spanning the same | |
475 | * switch tree (or all trees, in the case of cross-tree bridging | |
476 | * support) that can be offloaded. | |
123abc06 | 477 | */ |
947c8746 | 478 | unsigned int max_num_bridges; |
123abc06 | 479 | |
258030ac | 480 | unsigned int num_ports; |
c8f0b869 BH |
481 | }; |
482 | ||
68bb8ea8 | 483 | static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p) |
bff7b688 | 484 | { |
b96ddf25 | 485 | struct dsa_switch_tree *dst = ds->dst; |
d607525b | 486 | struct dsa_port *dp; |
b96ddf25 VD |
487 | |
488 | list_for_each_entry(dp, &dst->ports, list) | |
489 | if (dp->ds == ds && dp->index == p) | |
d607525b | 490 | return dp; |
b96ddf25 | 491 | |
d607525b | 492 | return NULL; |
c38c5a66 | 493 | } |
bff7b688 | 494 | |
a8986681 VO |
495 | static inline bool dsa_port_is_dsa(struct dsa_port *port) |
496 | { | |
497 | return port->type == DSA_PORT_TYPE_DSA; | |
498 | } | |
499 | ||
500 | static inline bool dsa_port_is_cpu(struct dsa_port *port) | |
501 | { | |
502 | return port->type == DSA_PORT_TYPE_CPU; | |
503 | } | |
504 | ||
505 | static inline bool dsa_port_is_user(struct dsa_port *dp) | |
506 | { | |
507 | return dp->type == DSA_PORT_TYPE_USER; | |
508 | } | |
509 | ||
a57d8c21 VO |
510 | static inline bool dsa_port_is_unused(struct dsa_port *dp) |
511 | { | |
512 | return dp->type == DSA_PORT_TYPE_UNUSED; | |
513 | } | |
514 | ||
295ab96f VO |
515 | static inline bool dsa_port_master_is_operational(struct dsa_port *dp) |
516 | { | |
517 | return dsa_port_is_cpu(dp) && dp->master_admin_up && | |
518 | dp->master_oper_up; | |
519 | } | |
520 | ||
c38c5a66 VD |
521 | static inline bool dsa_is_unused_port(struct dsa_switch *ds, int p) |
522 | { | |
523 | return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_UNUSED; | |
bff7b688 VD |
524 | } |
525 | ||
c8f0b869 BH |
526 | static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p) |
527 | { | |
c38c5a66 | 528 | return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_CPU; |
c8f0b869 BH |
529 | } |
530 | ||
60045cbf AL |
531 | static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p) |
532 | { | |
c38c5a66 | 533 | return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_DSA; |
60045cbf AL |
534 | } |
535 | ||
2b3e9891 | 536 | static inline bool dsa_is_user_port(struct dsa_switch *ds, int p) |
6cd456f3 | 537 | { |
c38c5a66 | 538 | return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_USER; |
6cd456f3 VD |
539 | } |
540 | ||
82b31898 VO |
541 | #define dsa_tree_for_each_user_port(_dp, _dst) \ |
542 | list_for_each_entry((_dp), &(_dst)->ports, list) \ | |
543 | if (dsa_port_is_user((_dp))) | |
544 | ||
95f510d0 VO |
545 | #define dsa_tree_for_each_user_port_continue_reverse(_dp, _dst) \ |
546 | list_for_each_entry_continue_reverse((_dp), &(_dst)->ports, list) \ | |
547 | if (dsa_port_is_user((_dp))) | |
548 | ||
5dc760d1 VO |
549 | #define dsa_tree_for_each_cpu_port(_dp, _dst) \ |
550 | list_for_each_entry((_dp), &(_dst)->ports, list) \ | |
551 | if (dsa_port_is_cpu((_dp))) | |
552 | ||
82b31898 VO |
553 | #define dsa_switch_for_each_port(_dp, _ds) \ |
554 | list_for_each_entry((_dp), &(_ds)->dst->ports, list) \ | |
555 | if ((_dp)->ds == (_ds)) | |
556 | ||
557 | #define dsa_switch_for_each_port_safe(_dp, _next, _ds) \ | |
558 | list_for_each_entry_safe((_dp), (_next), &(_ds)->dst->ports, list) \ | |
559 | if ((_dp)->ds == (_ds)) | |
560 | ||
561 | #define dsa_switch_for_each_port_continue_reverse(_dp, _ds) \ | |
562 | list_for_each_entry_continue_reverse((_dp), &(_ds)->dst->ports, list) \ | |
563 | if ((_dp)->ds == (_ds)) | |
564 | ||
565 | #define dsa_switch_for_each_available_port(_dp, _ds) \ | |
566 | dsa_switch_for_each_port((_dp), (_ds)) \ | |
567 | if (!dsa_port_is_unused((_dp))) | |
568 | ||
569 | #define dsa_switch_for_each_user_port(_dp, _ds) \ | |
570 | dsa_switch_for_each_port((_dp), (_ds)) \ | |
571 | if (dsa_port_is_user((_dp))) | |
572 | ||
573 | #define dsa_switch_for_each_cpu_port(_dp, _ds) \ | |
574 | dsa_switch_for_each_port((_dp), (_ds)) \ | |
575 | if (dsa_port_is_cpu((_dp))) | |
576 | ||
bacf93b0 VO |
577 | #define dsa_switch_for_each_cpu_port_continue_reverse(_dp, _ds) \ |
578 | dsa_switch_for_each_port_continue_reverse((_dp), (_ds)) \ | |
579 | if (dsa_port_is_cpu((_dp))) | |
580 | ||
02bc6e54 VD |
581 | static inline u32 dsa_user_ports(struct dsa_switch *ds) |
582 | { | |
d0004a02 | 583 | struct dsa_port *dp; |
c38c5a66 | 584 | u32 mask = 0; |
02bc6e54 | 585 | |
d0004a02 VO |
586 | dsa_switch_for_each_user_port(dp, ds) |
587 | mask |= BIT(dp->index); | |
c38c5a66 VD |
588 | |
589 | return mask; | |
c8652c83 VD |
590 | } |
591 | ||
465c3de4 VO |
592 | static inline u32 dsa_cpu_ports(struct dsa_switch *ds) |
593 | { | |
594 | struct dsa_port *cpu_dp; | |
595 | u32 mask = 0; | |
596 | ||
597 | dsa_switch_for_each_cpu_port(cpu_dp, ds) | |
598 | mask |= BIT(cpu_dp->index); | |
599 | ||
600 | return mask; | |
601 | } | |
602 | ||
c5f51765 VD |
603 | /* Return the local port used to reach an arbitrary switch device */ |
604 | static inline unsigned int dsa_routing_port(struct dsa_switch *ds, int device) | |
605 | { | |
606 | struct dsa_switch_tree *dst = ds->dst; | |
607 | struct dsa_link *dl; | |
608 | ||
609 | list_for_each_entry(dl, &dst->rtable, list) | |
610 | if (dl->dp->ds == ds && dl->link_dp->ds->index == device) | |
611 | return dl->dp->index; | |
612 | ||
613 | return ds->num_ports; | |
614 | } | |
615 | ||
3b8fac5d VD |
616 | /* Return the local port used to reach an arbitrary switch port */ |
617 | static inline unsigned int dsa_towards_port(struct dsa_switch *ds, int device, | |
618 | int port) | |
619 | { | |
620 | if (device == ds->index) | |
621 | return port; | |
622 | else | |
c5f51765 | 623 | return dsa_routing_port(ds, device); |
3b8fac5d VD |
624 | } |
625 | ||
626 | /* Return the local port used to reach the dedicated CPU port */ | |
07073c79 | 627 | static inline unsigned int dsa_upstream_port(struct dsa_switch *ds, int port) |
c8f0b869 | 628 | { |
07073c79 VD |
629 | const struct dsa_port *dp = dsa_to_port(ds, port); |
630 | const struct dsa_port *cpu_dp = dp->cpu_dp; | |
631 | ||
632 | if (!cpu_dp) | |
633 | return port; | |
c8f0b869 | 634 | |
3b8fac5d | 635 | return dsa_towards_port(ds, cpu_dp->ds->index, cpu_dp->index); |
c8f0b869 BH |
636 | } |
637 | ||
63609c8f VO |
638 | /* Return true if this is the local port used to reach the CPU port */ |
639 | static inline bool dsa_is_upstream_port(struct dsa_switch *ds, int port) | |
640 | { | |
641 | if (dsa_is_unused_port(ds, port)) | |
642 | return false; | |
643 | ||
644 | return port == dsa_upstream_port(ds, port); | |
645 | } | |
646 | ||
d352b20f TW |
647 | /* Return true if this is a DSA port leading away from the CPU */ |
648 | static inline bool dsa_is_downstream_port(struct dsa_switch *ds, int port) | |
649 | { | |
650 | return dsa_is_dsa_port(ds, port) && !dsa_is_upstream_port(ds, port); | |
651 | } | |
652 | ||
7af4a361 TW |
653 | /* Return the local port used to reach the CPU port */ |
654 | static inline unsigned int dsa_switch_upstream_port(struct dsa_switch *ds) | |
655 | { | |
656 | struct dsa_port *dp; | |
657 | ||
658 | dsa_switch_for_each_available_port(dp, ds) { | |
659 | return dsa_upstream_port(ds, dp->index); | |
660 | } | |
661 | ||
662 | return ds->num_ports; | |
663 | } | |
664 | ||
63609c8f VO |
665 | /* Return true if @upstream_ds is an upstream switch of @downstream_ds, meaning |
666 | * that the routing port from @downstream_ds to @upstream_ds is also the port | |
667 | * which @downstream_ds uses to reach its dedicated CPU. | |
668 | */ | |
669 | static inline bool dsa_switch_is_upstream_of(struct dsa_switch *upstream_ds, | |
670 | struct dsa_switch *downstream_ds) | |
671 | { | |
672 | int routing_port; | |
673 | ||
674 | if (upstream_ds == downstream_ds) | |
675 | return true; | |
676 | ||
677 | routing_port = dsa_routing_port(downstream_ds, upstream_ds->index); | |
678 | ||
679 | return dsa_is_upstream_port(downstream_ds, routing_port); | |
680 | } | |
681 | ||
cf2d45f5 VO |
682 | static inline bool dsa_port_is_vlan_filtering(const struct dsa_port *dp) |
683 | { | |
684 | const struct dsa_switch *ds = dp->ds; | |
685 | ||
686 | if (ds->vlan_filtering_is_global) | |
687 | return ds->vlan_filtering; | |
688 | else | |
689 | return dp->vlan_filtering; | |
690 | } | |
691 | ||
dedd6a00 VO |
692 | static inline unsigned int dsa_port_lag_id_get(struct dsa_port *dp) |
693 | { | |
694 | return dp->lag ? dp->lag->id : 0; | |
695 | } | |
696 | ||
697 | static inline struct net_device *dsa_port_lag_dev_get(struct dsa_port *dp) | |
698 | { | |
699 | return dp->lag ? dp->lag->dev : NULL; | |
700 | } | |
701 | ||
702 | static inline bool dsa_port_offloads_lag(struct dsa_port *dp, | |
703 | const struct dsa_lag *lag) | |
704 | { | |
705 | return dsa_port_lag_dev_get(dp) == lag->dev; | |
706 | } | |
707 | ||
8f6a19c0 VO |
708 | static inline struct net_device *dsa_port_to_master(const struct dsa_port *dp) |
709 | { | |
acc43b7b VO |
710 | if (dp->cpu_port_in_lag) |
711 | return dsa_port_lag_dev_get(dp->cpu_dp); | |
712 | ||
8f6a19c0 VO |
713 | return dp->cpu_dp->master; |
714 | } | |
715 | ||
cc76ce9e TW |
716 | static inline |
717 | struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp) | |
718 | { | |
d3eed0e5 | 719 | if (!dp->bridge) |
cc76ce9e TW |
720 | return NULL; |
721 | ||
dedd6a00 VO |
722 | if (dp->lag) |
723 | return dp->lag->dev; | |
cc76ce9e TW |
724 | else if (dp->hsr_dev) |
725 | return dp->hsr_dev; | |
726 | ||
727 | return dp->slave; | |
728 | } | |
729 | ||
36cbf39b VO |
730 | static inline struct net_device * |
731 | dsa_port_bridge_dev_get(const struct dsa_port *dp) | |
732 | { | |
d3eed0e5 | 733 | return dp->bridge ? dp->bridge->dev : NULL; |
36cbf39b VO |
734 | } |
735 | ||
736 | static inline unsigned int dsa_port_bridge_num_get(struct dsa_port *dp) | |
737 | { | |
d3eed0e5 | 738 | return dp->bridge ? dp->bridge->num : 0; |
36cbf39b VO |
739 | } |
740 | ||
741 | static inline bool dsa_port_bridge_same(const struct dsa_port *a, | |
742 | const struct dsa_port *b) | |
743 | { | |
744 | struct net_device *br_a = dsa_port_bridge_dev_get(a); | |
745 | struct net_device *br_b = dsa_port_bridge_dev_get(b); | |
746 | ||
747 | /* Standalone ports are not in the same bridge with one another */ | |
748 | return (!br_a || !br_b) ? false : (br_a == br_b); | |
749 | } | |
750 | ||
6a43cba3 VO |
751 | static inline bool dsa_port_offloads_bridge_port(struct dsa_port *dp, |
752 | const struct net_device *dev) | |
753 | { | |
754 | return dsa_port_to_bridge_port(dp) == dev; | |
755 | } | |
756 | ||
757 | static inline bool | |
758 | dsa_port_offloads_bridge_dev(struct dsa_port *dp, | |
759 | const struct net_device *bridge_dev) | |
760 | { | |
761 | /* DSA ports connected to a bridge, and event was emitted | |
762 | * for the bridge. | |
763 | */ | |
764 | return dsa_port_bridge_dev_get(dp) == bridge_dev; | |
765 | } | |
766 | ||
d3eed0e5 VO |
767 | static inline bool dsa_port_offloads_bridge(struct dsa_port *dp, |
768 | const struct dsa_bridge *bridge) | |
769 | { | |
770 | return dsa_port_bridge_dev_get(dp) == bridge->dev; | |
771 | } | |
772 | ||
6a43cba3 VO |
773 | /* Returns true if any port of this tree offloads the given net_device */ |
774 | static inline bool dsa_tree_offloads_bridge_port(struct dsa_switch_tree *dst, | |
775 | const struct net_device *dev) | |
776 | { | |
777 | struct dsa_port *dp; | |
778 | ||
779 | list_for_each_entry(dp, &dst->ports, list) | |
780 | if (dsa_port_offloads_bridge_port(dp, dev)) | |
781 | return true; | |
782 | ||
783 | return false; | |
784 | } | |
785 | ||
786 | /* Returns true if any port of this tree offloads the given bridge */ | |
787 | static inline bool | |
788 | dsa_tree_offloads_bridge_dev(struct dsa_switch_tree *dst, | |
789 | const struct net_device *bridge_dev) | |
790 | { | |
791 | struct dsa_port *dp; | |
792 | ||
793 | list_for_each_entry(dp, &dst->ports, list) | |
794 | if (dsa_port_offloads_bridge_dev(dp, bridge_dev)) | |
795 | return true; | |
796 | ||
797 | return false; | |
798 | } | |
799 | ||
acc43b7b VO |
800 | static inline bool dsa_port_tree_same(const struct dsa_port *a, |
801 | const struct dsa_port *b) | |
802 | { | |
803 | return a->ds->dst == b->ds->dst; | |
804 | } | |
805 | ||
2bedde1a AS |
806 | typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid, |
807 | bool is_static, void *data); | |
9d490b4e | 808 | struct dsa_switch_ops { |
53da0eba VO |
809 | /* |
810 | * Tagging protocol helpers called for the CPU ports and DSA links. | |
811 | * @get_tag_protocol retrieves the initial tagging protocol and is | |
812 | * mandatory. Switches which can operate using multiple tagging | |
813 | * protocols should implement @change_tag_protocol and report in | |
814 | * @get_tag_protocol the tagger in current use. | |
815 | */ | |
5ed4e3eb | 816 | enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds, |
4d776482 FF |
817 | int port, |
818 | enum dsa_tag_protocol mprot); | |
bacf93b0 | 819 | int (*change_tag_protocol)(struct dsa_switch *ds, |
53da0eba | 820 | enum dsa_tag_protocol proto); |
dc452a47 VO |
821 | /* |
822 | * Method for switch drivers to connect to the tagging protocol driver | |
823 | * in current use. The switch driver can provide handlers for certain | |
824 | * types of packets for switch management. | |
825 | */ | |
826 | int (*connect_tag_protocol)(struct dsa_switch *ds, | |
827 | enum dsa_tag_protocol proto); | |
7b314362 | 828 | |
95f510d0 VO |
829 | int (*port_change_master)(struct dsa_switch *ds, int port, |
830 | struct net_device *master, | |
831 | struct netlink_ext_ack *extack); | |
832 | ||
fd292c18 | 833 | /* Optional switch-wide initialization and destruction methods */ |
c8f0b869 | 834 | int (*setup)(struct dsa_switch *ds); |
5e3f847a | 835 | void (*teardown)(struct dsa_switch *ds); |
fd292c18 VO |
836 | |
837 | /* Per-port initialization and destruction methods. Mandatory if the | |
838 | * driver registers devlink port regions, optional otherwise. | |
839 | */ | |
840 | int (*port_setup)(struct dsa_switch *ds, int port); | |
841 | void (*port_teardown)(struct dsa_switch *ds, int port); | |
842 | ||
6819563e | 843 | u32 (*get_phy_flags)(struct dsa_switch *ds, int port); |
c8f0b869 BH |
844 | |
845 | /* | |
846 | * Access to the switch's PHY registers. | |
847 | */ | |
848 | int (*phy_read)(struct dsa_switch *ds, int port, int regnum); | |
849 | int (*phy_write)(struct dsa_switch *ds, int port, | |
850 | int regnum, u16 val); | |
851 | ||
ec9436ba FF |
852 | /* |
853 | * Link state adjustment (called from libphy) | |
854 | */ | |
855 | void (*adjust_link)(struct dsa_switch *ds, int port, | |
856 | struct phy_device *phydev); | |
ce31b31c FF |
857 | void (*fixed_link_update)(struct dsa_switch *ds, int port, |
858 | struct fixed_phy_status *st); | |
ec9436ba | 859 | |
11d8f3dd FF |
860 | /* |
861 | * PHYLINK integration | |
862 | */ | |
072eea6c RKO |
863 | void (*phylink_get_caps)(struct dsa_switch *ds, int port, |
864 | struct phylink_config *config); | |
bde01822 RKO |
865 | struct phylink_pcs *(*phylink_mac_select_pcs)(struct dsa_switch *ds, |
866 | int port, | |
867 | phy_interface_t iface); | |
11d8f3dd FF |
868 | int (*phylink_mac_link_state)(struct dsa_switch *ds, int port, |
869 | struct phylink_link_state *state); | |
870 | void (*phylink_mac_config)(struct dsa_switch *ds, int port, | |
871 | unsigned int mode, | |
872 | const struct phylink_link_state *state); | |
873 | void (*phylink_mac_an_restart)(struct dsa_switch *ds, int port); | |
874 | void (*phylink_mac_link_down)(struct dsa_switch *ds, int port, | |
875 | unsigned int mode, | |
876 | phy_interface_t interface); | |
877 | void (*phylink_mac_link_up)(struct dsa_switch *ds, int port, | |
878 | unsigned int mode, | |
879 | phy_interface_t interface, | |
5b502a7b RK |
880 | struct phy_device *phydev, |
881 | int speed, int duplex, | |
882 | bool tx_pause, bool rx_pause); | |
11d8f3dd FF |
883 | void (*phylink_fixed_state)(struct dsa_switch *ds, int port, |
884 | struct phylink_link_state *state); | |
c8f0b869 | 885 | /* |
c2ec5f2e | 886 | * Port statistics counters. |
c8f0b869 | 887 | */ |
89f09048 FF |
888 | void (*get_strings)(struct dsa_switch *ds, int port, |
889 | u32 stringset, uint8_t *data); | |
c8f0b869 BH |
890 | void (*get_ethtool_stats)(struct dsa_switch *ds, |
891 | int port, uint64_t *data); | |
89f09048 | 892 | int (*get_sset_count)(struct dsa_switch *ds, int port, int sset); |
cf963573 FF |
893 | void (*get_ethtool_phy_stats)(struct dsa_switch *ds, |
894 | int port, uint64_t *data); | |
487d3855 AŠ |
895 | void (*get_eth_phy_stats)(struct dsa_switch *ds, int port, |
896 | struct ethtool_eth_phy_stats *phy_stats); | |
897 | void (*get_eth_mac_stats)(struct dsa_switch *ds, int port, | |
898 | struct ethtool_eth_mac_stats *mac_stats); | |
899 | void (*get_eth_ctrl_stats)(struct dsa_switch *ds, int port, | |
900 | struct ethtool_eth_ctrl_stats *ctrl_stats); | |
67f38b1c CL |
901 | void (*get_rmon_stats)(struct dsa_switch *ds, int port, |
902 | struct ethtool_rmon_stats *rmon_stats, | |
903 | const struct ethtool_rmon_hist_range **ranges); | |
c2ec5f2e OR |
904 | void (*get_stats64)(struct dsa_switch *ds, int port, |
905 | struct rtnl_link_stats64 *s); | |
3d410403 OR |
906 | void (*get_pause_stats)(struct dsa_switch *ds, int port, |
907 | struct ethtool_pause_stats *pause_stats); | |
a71acad9 OR |
908 | void (*self_test)(struct dsa_switch *ds, int port, |
909 | struct ethtool_test *etest, u64 *data); | |
24462549 | 910 | |
19e57c4e FF |
911 | /* |
912 | * ethtool Wake-on-LAN | |
913 | */ | |
914 | void (*get_wol)(struct dsa_switch *ds, int port, | |
915 | struct ethtool_wolinfo *w); | |
916 | int (*set_wol)(struct dsa_switch *ds, int port, | |
917 | struct ethtool_wolinfo *w); | |
918 | ||
0336369d BS |
919 | /* |
920 | * ethtool timestamp info | |
921 | */ | |
922 | int (*get_ts_info)(struct dsa_switch *ds, int port, | |
923 | struct ethtool_ts_info *ts); | |
924 | ||
5f6c2d49 VO |
925 | /* |
926 | * ethtool MAC merge layer | |
927 | */ | |
928 | int (*get_mm)(struct dsa_switch *ds, int port, | |
929 | struct ethtool_mm_state *state); | |
930 | int (*set_mm)(struct dsa_switch *ds, int port, | |
931 | struct ethtool_mm_cfg *cfg, | |
932 | struct netlink_ext_ack *extack); | |
933 | void (*get_mm_stats)(struct dsa_switch *ds, int port, | |
934 | struct ethtool_mm_stats *stats); | |
935 | ||
d538eca8 VO |
936 | /* |
937 | * DCB ops | |
938 | */ | |
939 | int (*port_get_default_prio)(struct dsa_switch *ds, int port); | |
940 | int (*port_set_default_prio)(struct dsa_switch *ds, int port, | |
941 | u8 prio); | |
47d75f78 VO |
942 | int (*port_get_dscp_prio)(struct dsa_switch *ds, int port, u8 dscp); |
943 | int (*port_add_dscp_prio)(struct dsa_switch *ds, int port, u8 dscp, | |
944 | u8 prio); | |
945 | int (*port_del_dscp_prio)(struct dsa_switch *ds, int port, u8 dscp, | |
946 | u8 prio); | |
d538eca8 | 947 | |
24462549 FF |
948 | /* |
949 | * Suspend and resume | |
950 | */ | |
951 | int (*suspend)(struct dsa_switch *ds); | |
952 | int (*resume)(struct dsa_switch *ds); | |
b2f2af21 FF |
953 | |
954 | /* | |
955 | * Port enable/disable | |
956 | */ | |
957 | int (*port_enable)(struct dsa_switch *ds, int port, | |
958 | struct phy_device *phy); | |
75104db0 | 959 | void (*port_disable)(struct dsa_switch *ds, int port); |
7905288f FF |
960 | |
961 | /* | |
08f50061 | 962 | * Port's MAC EEE settings |
7905288f | 963 | */ |
08f50061 VD |
964 | int (*set_mac_eee)(struct dsa_switch *ds, int port, |
965 | struct ethtool_eee *e); | |
966 | int (*get_mac_eee)(struct dsa_switch *ds, int port, | |
967 | struct ethtool_eee *e); | |
51579c3f | 968 | |
6793abb4 GR |
969 | /* EEPROM access */ |
970 | int (*get_eeprom_len)(struct dsa_switch *ds); | |
971 | int (*get_eeprom)(struct dsa_switch *ds, | |
972 | struct ethtool_eeprom *eeprom, u8 *data); | |
973 | int (*set_eeprom)(struct dsa_switch *ds, | |
974 | struct ethtool_eeprom *eeprom, u8 *data); | |
3d762a0f GR |
975 | |
976 | /* | |
977 | * Register access. | |
978 | */ | |
979 | int (*get_regs_len)(struct dsa_switch *ds, int port); | |
980 | void (*get_regs)(struct dsa_switch *ds, int port, | |
981 | struct ethtool_regs *regs, void *p); | |
b73adef6 | 982 | |
e358bef7 VO |
983 | /* |
984 | * Upper device tracking. | |
985 | */ | |
986 | int (*port_prechangeupper)(struct dsa_switch *ds, int port, | |
987 | struct netdev_notifier_changeupper_info *info); | |
988 | ||
b73adef6 FF |
989 | /* |
990 | * Bridge integration | |
991 | */ | |
34a79f63 | 992 | int (*set_ageing_time)(struct dsa_switch *ds, unsigned int msecs); |
71327a4e | 993 | int (*port_bridge_join)(struct dsa_switch *ds, int port, |
b079922b | 994 | struct dsa_bridge bridge, |
06b9cce4 VO |
995 | bool *tx_fwd_offload, |
996 | struct netlink_ext_ack *extack); | |
f123f2fb | 997 | void (*port_bridge_leave)(struct dsa_switch *ds, int port, |
d3eed0e5 | 998 | struct dsa_bridge bridge); |
43c44a9f VD |
999 | void (*port_stp_state_set)(struct dsa_switch *ds, int port, |
1000 | u8 state); | |
7414af30 TW |
1001 | int (*port_mst_state_set)(struct dsa_switch *ds, int port, |
1002 | const struct switchdev_mst_state *state); | |
732f794c | 1003 | void (*port_fast_age)(struct dsa_switch *ds, int port); |
7414af30 | 1004 | int (*port_vlan_fast_age)(struct dsa_switch *ds, int port, u16 vid); |
a8b659e7 VO |
1005 | int (*port_pre_bridge_flags)(struct dsa_switch *ds, int port, |
1006 | struct switchdev_brport_flags flags, | |
1007 | struct netlink_ext_ack *extack); | |
1008 | int (*port_bridge_flags)(struct dsa_switch *ds, int port, | |
1009 | struct switchdev_brport_flags flags, | |
1010 | struct netlink_ext_ack *extack); | |
72c3b0c7 VO |
1011 | void (*port_set_host_flood)(struct dsa_switch *ds, int port, |
1012 | bool uc, bool mc); | |
2a778e1b | 1013 | |
11149536 VD |
1014 | /* |
1015 | * VLAN support | |
1016 | */ | |
fb2dabad | 1017 | int (*port_vlan_filtering)(struct dsa_switch *ds, int port, |
89153ed6 VO |
1018 | bool vlan_filtering, |
1019 | struct netlink_ext_ack *extack); | |
1958d581 | 1020 | int (*port_vlan_add)(struct dsa_switch *ds, int port, |
31046a5f VO |
1021 | const struct switchdev_obj_port_vlan *vlan, |
1022 | struct netlink_ext_ack *extack); | |
76e398a6 VD |
1023 | int (*port_vlan_del)(struct dsa_switch *ds, int port, |
1024 | const struct switchdev_obj_port_vlan *vlan); | |
8e6598a7 TW |
1025 | int (*vlan_msti_set)(struct dsa_switch *ds, struct dsa_bridge bridge, |
1026 | const struct switchdev_vlan_msti *msti); | |
1027 | ||
2a778e1b VD |
1028 | /* |
1029 | * Forwarding database | |
1030 | */ | |
1b6dd556 | 1031 | int (*port_fdb_add)(struct dsa_switch *ds, int port, |
c2693363 VO |
1032 | const unsigned char *addr, u16 vid, |
1033 | struct dsa_db db); | |
2a778e1b | 1034 | int (*port_fdb_del)(struct dsa_switch *ds, int port, |
c2693363 VO |
1035 | const unsigned char *addr, u16 vid, |
1036 | struct dsa_db db); | |
ea70ba98 | 1037 | int (*port_fdb_dump)(struct dsa_switch *ds, int port, |
2bedde1a | 1038 | dsa_fdb_dump_cb_t *cb, void *data); |
e212fa7c | 1039 | int (*lag_fdb_add)(struct dsa_switch *ds, struct dsa_lag lag, |
c2693363 VO |
1040 | const unsigned char *addr, u16 vid, |
1041 | struct dsa_db db); | |
e212fa7c | 1042 | int (*lag_fdb_del)(struct dsa_switch *ds, struct dsa_lag lag, |
c2693363 VO |
1043 | const unsigned char *addr, u16 vid, |
1044 | struct dsa_db db); | |
8df30255 VD |
1045 | |
1046 | /* | |
1047 | * Multicast database | |
1048 | */ | |
a52b2da7 | 1049 | int (*port_mdb_add)(struct dsa_switch *ds, int port, |
c2693363 VO |
1050 | const struct switchdev_obj_port_mdb *mdb, |
1051 | struct dsa_db db); | |
8df30255 | 1052 | int (*port_mdb_del)(struct dsa_switch *ds, int port, |
c2693363 VO |
1053 | const struct switchdev_obj_port_mdb *mdb, |
1054 | struct dsa_db db); | |
bf9f2648 FF |
1055 | /* |
1056 | * RXNFC | |
1057 | */ | |
1058 | int (*get_rxnfc)(struct dsa_switch *ds, int port, | |
1059 | struct ethtool_rxnfc *nfc, u32 *rule_locs); | |
1060 | int (*set_rxnfc)(struct dsa_switch *ds, int port, | |
1061 | struct ethtool_rxnfc *nfc); | |
f50f2127 FF |
1062 | |
1063 | /* | |
1064 | * TC integration | |
1065 | */ | |
ed11bb1f VO |
1066 | int (*cls_flower_add)(struct dsa_switch *ds, int port, |
1067 | struct flow_cls_offload *cls, bool ingress); | |
1068 | int (*cls_flower_del)(struct dsa_switch *ds, int port, | |
1069 | struct flow_cls_offload *cls, bool ingress); | |
1070 | int (*cls_flower_stats)(struct dsa_switch *ds, int port, | |
1071 | struct flow_cls_offload *cls, bool ingress); | |
f50f2127 FF |
1072 | int (*port_mirror_add)(struct dsa_switch *ds, int port, |
1073 | struct dsa_mall_mirror_tc_entry *mirror, | |
0148bb50 | 1074 | bool ingress, struct netlink_ext_ack *extack); |
f50f2127 FF |
1075 | void (*port_mirror_del)(struct dsa_switch *ds, int port, |
1076 | struct dsa_mall_mirror_tc_entry *mirror); | |
34297176 VO |
1077 | int (*port_policer_add)(struct dsa_switch *ds, int port, |
1078 | struct dsa_mall_policer_tc_entry *policer); | |
1079 | void (*port_policer_del)(struct dsa_switch *ds, int port); | |
47d23af2 VO |
1080 | int (*port_setup_tc)(struct dsa_switch *ds, int port, |
1081 | enum tc_setup_type type, void *type_data); | |
40ef2c93 VD |
1082 | |
1083 | /* | |
1084 | * Cross-chip operations | |
1085 | */ | |
f66a6a69 VO |
1086 | int (*crosschip_bridge_join)(struct dsa_switch *ds, int tree_index, |
1087 | int sw_index, int port, | |
06b9cce4 VO |
1088 | struct dsa_bridge bridge, |
1089 | struct netlink_ext_ack *extack); | |
f66a6a69 VO |
1090 | void (*crosschip_bridge_leave)(struct dsa_switch *ds, int tree_index, |
1091 | int sw_index, int port, | |
d3eed0e5 | 1092 | struct dsa_bridge bridge); |
058102a6 TW |
1093 | int (*crosschip_lag_change)(struct dsa_switch *ds, int sw_index, |
1094 | int port); | |
1095 | int (*crosschip_lag_join)(struct dsa_switch *ds, int sw_index, | |
dedd6a00 | 1096 | int port, struct dsa_lag lag, |
2e359b00 VO |
1097 | struct netdev_lag_upper_info *info, |
1098 | struct netlink_ext_ack *extack); | |
058102a6 | 1099 | int (*crosschip_lag_leave)(struct dsa_switch *ds, int sw_index, |
dedd6a00 | 1100 | int port, struct dsa_lag lag); |
0336369d BS |
1101 | |
1102 | /* | |
1103 | * PTP functionality | |
1104 | */ | |
1105 | int (*port_hwtstamp_get)(struct dsa_switch *ds, int port, | |
1106 | struct ifreq *ifr); | |
1107 | int (*port_hwtstamp_set)(struct dsa_switch *ds, int port, | |
1108 | struct ifreq *ifr); | |
5c5416f5 YL |
1109 | void (*port_txtstamp)(struct dsa_switch *ds, int port, |
1110 | struct sk_buff *skb); | |
90af1059 BS |
1111 | bool (*port_rxtstamp)(struct dsa_switch *ds, int port, |
1112 | struct sk_buff *skb, unsigned int type); | |
97a69a0d | 1113 | |
0f06b855 | 1114 | /* Devlink parameters, etc */ |
6b297524 AL |
1115 | int (*devlink_param_get)(struct dsa_switch *ds, u32 id, |
1116 | struct devlink_param_gset_ctx *ctx); | |
1117 | int (*devlink_param_set)(struct dsa_switch *ds, u32 id, | |
1118 | struct devlink_param_gset_ctx *ctx); | |
0f06b855 AL |
1119 | int (*devlink_info_get)(struct dsa_switch *ds, |
1120 | struct devlink_info_req *req, | |
1121 | struct netlink_ext_ack *extack); | |
2a6ef763 VO |
1122 | int (*devlink_sb_pool_get)(struct dsa_switch *ds, |
1123 | unsigned int sb_index, u16 pool_index, | |
1124 | struct devlink_sb_pool_info *pool_info); | |
1125 | int (*devlink_sb_pool_set)(struct dsa_switch *ds, unsigned int sb_index, | |
1126 | u16 pool_index, u32 size, | |
1127 | enum devlink_sb_threshold_type threshold_type, | |
1128 | struct netlink_ext_ack *extack); | |
1129 | int (*devlink_sb_port_pool_get)(struct dsa_switch *ds, int port, | |
1130 | unsigned int sb_index, u16 pool_index, | |
1131 | u32 *p_threshold); | |
1132 | int (*devlink_sb_port_pool_set)(struct dsa_switch *ds, int port, | |
1133 | unsigned int sb_index, u16 pool_index, | |
1134 | u32 threshold, | |
1135 | struct netlink_ext_ack *extack); | |
1136 | int (*devlink_sb_tc_pool_bind_get)(struct dsa_switch *ds, int port, | |
1137 | unsigned int sb_index, u16 tc_index, | |
1138 | enum devlink_sb_pool_type pool_type, | |
1139 | u16 *p_pool_index, u32 *p_threshold); | |
1140 | int (*devlink_sb_tc_pool_bind_set)(struct dsa_switch *ds, int port, | |
1141 | unsigned int sb_index, u16 tc_index, | |
1142 | enum devlink_sb_pool_type pool_type, | |
1143 | u16 pool_index, u32 threshold, | |
1144 | struct netlink_ext_ack *extack); | |
1145 | int (*devlink_sb_occ_snapshot)(struct dsa_switch *ds, | |
1146 | unsigned int sb_index); | |
1147 | int (*devlink_sb_occ_max_clear)(struct dsa_switch *ds, | |
1148 | unsigned int sb_index); | |
1149 | int (*devlink_sb_occ_port_pool_get)(struct dsa_switch *ds, int port, | |
1150 | unsigned int sb_index, u16 pool_index, | |
1151 | u32 *p_cur, u32 *p_max); | |
1152 | int (*devlink_sb_occ_tc_port_bind_get)(struct dsa_switch *ds, int port, | |
1153 | unsigned int sb_index, u16 tc_index, | |
1154 | enum devlink_sb_pool_type pool_type, | |
1155 | u32 *p_cur, u32 *p_max); | |
bfcb8132 VO |
1156 | |
1157 | /* | |
1158 | * MTU change functionality. Switches can also adjust their MRU through | |
1159 | * this method. By MTU, one understands the SDU (L2 payload) length. | |
1160 | * If the switch needs to account for the DSA tag on the CPU port, this | |
ab88d64a | 1161 | * method needs to do so privately. |
bfcb8132 VO |
1162 | */ |
1163 | int (*port_change_mtu)(struct dsa_switch *ds, int port, | |
1164 | int new_mtu); | |
1165 | int (*port_max_mtu)(struct dsa_switch *ds, int port); | |
058102a6 TW |
1166 | |
1167 | /* | |
1168 | * LAG integration | |
1169 | */ | |
1170 | int (*port_lag_change)(struct dsa_switch *ds, int port); | |
1171 | int (*port_lag_join)(struct dsa_switch *ds, int port, | |
dedd6a00 | 1172 | struct dsa_lag lag, |
2e359b00 VO |
1173 | struct netdev_lag_upper_info *info, |
1174 | struct netlink_ext_ack *extack); | |
058102a6 | 1175 | int (*port_lag_leave)(struct dsa_switch *ds, int port, |
dedd6a00 | 1176 | struct dsa_lag lag); |
18596f50 GM |
1177 | |
1178 | /* | |
1179 | * HSR integration | |
1180 | */ | |
1181 | int (*port_hsr_join)(struct dsa_switch *ds, int port, | |
1182 | struct net_device *hsr); | |
1183 | int (*port_hsr_leave)(struct dsa_switch *ds, int port, | |
1184 | struct net_device *hsr); | |
c595c433 HV |
1185 | |
1186 | /* | |
1187 | * MRP integration | |
1188 | */ | |
1189 | int (*port_mrp_add)(struct dsa_switch *ds, int port, | |
1190 | const struct switchdev_obj_mrp *mrp); | |
1191 | int (*port_mrp_del)(struct dsa_switch *ds, int port, | |
1192 | const struct switchdev_obj_mrp *mrp); | |
1193 | int (*port_mrp_add_ring_role)(struct dsa_switch *ds, int port, | |
1194 | const struct switchdev_obj_ring_role_mrp *mrp); | |
1195 | int (*port_mrp_del_ring_role)(struct dsa_switch *ds, int port, | |
1196 | const struct switchdev_obj_ring_role_mrp *mrp); | |
5da11eb4 VO |
1197 | |
1198 | /* | |
1199 | * tag_8021q operations | |
1200 | */ | |
1201 | int (*tag_8021q_vlan_add)(struct dsa_switch *ds, int port, u16 vid, | |
1202 | u16 flags); | |
1203 | int (*tag_8021q_vlan_del)(struct dsa_switch *ds, int port, u16 vid); | |
295ab96f VO |
1204 | |
1205 | /* | |
1206 | * DSA master tracking operations | |
1207 | */ | |
1208 | void (*master_state_change)(struct dsa_switch *ds, | |
1209 | const struct net_device *master, | |
1210 | bool operational); | |
6b297524 AL |
1211 | }; |
1212 | ||
1213 | #define DSA_DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes) \ | |
1214 | DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, \ | |
1215 | dsa_devlink_param_get, dsa_devlink_param_set, NULL) | |
1216 | ||
1217 | int dsa_devlink_param_get(struct devlink *dl, u32 id, | |
1218 | struct devlink_param_gset_ctx *ctx); | |
1219 | int dsa_devlink_param_set(struct devlink *dl, u32 id, | |
1220 | struct devlink_param_gset_ctx *ctx); | |
1221 | int dsa_devlink_params_register(struct dsa_switch *ds, | |
1222 | const struct devlink_param *params, | |
1223 | size_t params_count); | |
1224 | void dsa_devlink_params_unregister(struct dsa_switch *ds, | |
1225 | const struct devlink_param *params, | |
1226 | size_t params_count); | |
5cd73fbd AL |
1227 | int dsa_devlink_resource_register(struct dsa_switch *ds, |
1228 | const char *resource_name, | |
1229 | u64 resource_size, | |
1230 | u64 resource_id, | |
1231 | u64 parent_resource_id, | |
1232 | const struct devlink_resource_size_params *size_params); | |
1233 | ||
1234 | void dsa_devlink_resources_unregister(struct dsa_switch *ds); | |
1235 | ||
1236 | void dsa_devlink_resource_occ_get_register(struct dsa_switch *ds, | |
1237 | u64 resource_id, | |
1238 | devlink_resource_occ_get_t *occ_get, | |
1239 | void *occ_get_priv); | |
1240 | void dsa_devlink_resource_occ_get_unregister(struct dsa_switch *ds, | |
1241 | u64 resource_id); | |
97c82c23 AL |
1242 | struct devlink_region * |
1243 | dsa_devlink_region_create(struct dsa_switch *ds, | |
1244 | const struct devlink_region_ops *ops, | |
1245 | u32 region_max_snapshots, u64 region_size); | |
08156ba4 AL |
1246 | struct devlink_region * |
1247 | dsa_devlink_port_region_create(struct dsa_switch *ds, | |
1248 | int port, | |
1249 | const struct devlink_port_region_ops *ops, | |
1250 | u32 region_max_snapshots, u64 region_size); | |
97c82c23 AL |
1251 | void dsa_devlink_region_destroy(struct devlink_region *region); |
1252 | ||
e1eea811 | 1253 | struct dsa_port *dsa_port_from_netdev(struct net_device *netdev); |
5cd73fbd | 1254 | |
6b297524 AL |
1255 | struct dsa_devlink_priv { |
1256 | struct dsa_switch *ds; | |
c8f0b869 BH |
1257 | }; |
1258 | ||
ccc3e6b0 AL |
1259 | static inline struct dsa_switch *dsa_devlink_to_ds(struct devlink *dl) |
1260 | { | |
1261 | struct dsa_devlink_priv *dl_priv = devlink_priv(dl); | |
1262 | ||
1263 | return dl_priv->ds; | |
1264 | } | |
1265 | ||
7d1e2a10 AL |
1266 | static inline |
1267 | struct dsa_switch *dsa_devlink_port_to_ds(struct devlink_port *port) | |
1268 | { | |
1269 | struct devlink *dl = port->devlink; | |
1270 | struct dsa_devlink_priv *dl_priv = devlink_priv(dl); | |
1271 | ||
1272 | return dl_priv->ds; | |
1273 | } | |
1274 | ||
1275 | static inline int dsa_devlink_port_to_port(struct devlink_port *port) | |
1276 | { | |
1277 | return port->index; | |
1278 | } | |
1279 | ||
ab3d408d FF |
1280 | struct dsa_switch_driver { |
1281 | struct list_head list; | |
a82f67af | 1282 | const struct dsa_switch_ops *ops; |
ab3d408d FF |
1283 | }; |
1284 | ||
7e580490 VO |
1285 | bool dsa_fdb_present_in_other_db(struct dsa_switch *ds, int port, |
1286 | const unsigned char *addr, u16 vid, | |
1287 | struct dsa_db db); | |
1288 | bool dsa_mdb_present_in_other_db(struct dsa_switch *ds, int port, | |
1289 | const struct switchdev_obj_port_mdb *mdb, | |
1290 | struct dsa_db db); | |
f9cef64f | 1291 | |
73a7ece8 | 1292 | /* Keep inline for faster access in hot path */ |
9eb8eff0 | 1293 | static inline bool netdev_uses_dsa(const struct net_device *dev) |
c6e970a0 AL |
1294 | { |
1295 | #if IS_ENABLED(CONFIG_NET_DSA) | |
717ffbfb | 1296 | return dev->dsa_ptr && dev->dsa_ptr->rcv; |
c6e970a0 AL |
1297 | #endif |
1298 | return false; | |
1299 | } | |
1300 | ||
9790cf20 VO |
1301 | /* All DSA tags that push the EtherType to the right (basically all except tail |
1302 | * tags, which don't break dissection) can be treated the same from the | |
1303 | * perspective of the flow dissector. | |
1304 | * | |
1305 | * We need to return: | |
1306 | * - offset: the (B - A) difference between: | |
1307 | * A. the position of the real EtherType and | |
1308 | * B. the current skb->data (aka ETH_HLEN bytes into the frame, aka 2 bytes | |
1309 | * after the normal EtherType was supposed to be) | |
1310 | * The offset in bytes is exactly equal to the tagger overhead (and half of | |
1311 | * that, in __be16 shorts). | |
1312 | * | |
1313 | * - proto: the value of the real EtherType. | |
1314 | */ | |
1315 | static inline void dsa_tag_generic_flow_dissect(const struct sk_buff *skb, | |
1316 | __be16 *proto, int *offset) | |
1317 | { | |
1318 | #if IS_ENABLED(CONFIG_NET_DSA) | |
1319 | const struct dsa_device_ops *ops = skb->dev->dsa_ptr->tag_ops; | |
4e500251 | 1320 | int tag_len = ops->needed_headroom; |
9790cf20 VO |
1321 | |
1322 | *offset = tag_len; | |
1323 | *proto = ((__be16 *)skb->data)[(tag_len / 2) - 1]; | |
1324 | #endif | |
1325 | } | |
1326 | ||
83c0afae | 1327 | void dsa_unregister_switch(struct dsa_switch *ds); |
23c9ee49 | 1328 | int dsa_register_switch(struct dsa_switch *ds); |
0650bf52 | 1329 | void dsa_switch_shutdown(struct dsa_switch *ds); |
3b7bc1f0 | 1330 | struct dsa_switch *dsa_switch_find(int tree_index, int sw_index); |
a2614140 | 1331 | void dsa_flush_workqueue(void); |
ea825e70 FF |
1332 | #ifdef CONFIG_PM_SLEEP |
1333 | int dsa_switch_suspend(struct dsa_switch *ds); | |
1334 | int dsa_switch_resume(struct dsa_switch *ds); | |
1335 | #else | |
1336 | static inline int dsa_switch_suspend(struct dsa_switch *ds) | |
1337 | { | |
1338 | return 0; | |
1339 | } | |
1340 | static inline int dsa_switch_resume(struct dsa_switch *ds) | |
1341 | { | |
1342 | return 0; | |
1343 | } | |
1344 | #endif /* CONFIG_PM_SLEEP */ | |
1345 | ||
60724d4b | 1346 | #if IS_ENABLED(CONFIG_NET_DSA) |
a5e3c9ba | 1347 | bool dsa_slave_dev_check(const struct net_device *dev); |
60724d4b | 1348 | #else |
a5e3c9ba VO |
1349 | static inline bool dsa_slave_dev_check(const struct net_device *dev) |
1350 | { | |
1351 | return false; | |
1352 | } | |
60724d4b FF |
1353 | #endif |
1354 | ||
97a69a0d | 1355 | netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, struct net_device *dev); |
11d8f3dd | 1356 | void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up); |
cf963573 | 1357 | |
91da11f8 | 1358 | #endif |