Commit | Line | Data |
---|---|---|
91da11f8 LB |
1 | /* |
2 | * include/net/dsa.h - Driver for Distributed Switch Architecture switch chips | |
e84665c9 | 3 | * Copyright (c) 2008-2009 Marvell Semiconductor |
91da11f8 LB |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | */ | |
10 | ||
11 | #ifndef __LINUX_NET_DSA_H | |
12 | #define __LINUX_NET_DSA_H | |
13 | ||
4d56a29f | 14 | #include <linux/if.h> |
ea1f51be | 15 | #include <linux/if_ether.h> |
c8f0b869 | 16 | #include <linux/list.h> |
f515f192 | 17 | #include <linux/notifier.h> |
cf50dcc2 BH |
18 | #include <linux/timer.h> |
19 | #include <linux/workqueue.h> | |
fa981d9a | 20 | #include <linux/of.h> |
a2820543 | 21 | #include <linux/ethtool.h> |
0336369d | 22 | #include <linux/net_tstamp.h> |
11d8f3dd | 23 | #include <linux/phy.h> |
ecfc9372 | 24 | #include <linux/platform_data/dsa.h> |
96567d5d | 25 | #include <net/devlink.h> |
f0c24ccf | 26 | #include <net/switchdev.h> |
cf50dcc2 | 27 | |
f50f2127 | 28 | struct tc_action; |
4d56a29f RK |
29 | struct phy_device; |
30 | struct fixed_phy_status; | |
11d8f3dd | 31 | struct phylink_link_state; |
f50f2127 | 32 | |
0b42f033 AL |
33 | #define DSA_TAG_PROTO_NONE_VALUE 0 |
34 | #define DSA_TAG_PROTO_BRCM_VALUE 1 | |
35 | #define DSA_TAG_PROTO_BRCM_PREPEND_VALUE 2 | |
36 | #define DSA_TAG_PROTO_DSA_VALUE 3 | |
37 | #define DSA_TAG_PROTO_EDSA_VALUE 4 | |
38 | #define DSA_TAG_PROTO_GSWIP_VALUE 5 | |
39 | #define DSA_TAG_PROTO_KSZ9477_VALUE 6 | |
40 | #define DSA_TAG_PROTO_KSZ9893_VALUE 7 | |
41 | #define DSA_TAG_PROTO_LAN9303_VALUE 8 | |
42 | #define DSA_TAG_PROTO_MTK_VALUE 9 | |
43 | #define DSA_TAG_PROTO_QCA_VALUE 10 | |
44 | #define DSA_TAG_PROTO_TRAILER_VALUE 11 | |
45 | ||
ac7a04c3 | 46 | enum dsa_tag_protocol { |
0b42f033 AL |
47 | DSA_TAG_PROTO_NONE = DSA_TAG_PROTO_NONE_VALUE, |
48 | DSA_TAG_PROTO_BRCM = DSA_TAG_PROTO_BRCM_VALUE, | |
49 | DSA_TAG_PROTO_BRCM_PREPEND = DSA_TAG_PROTO_BRCM_PREPEND_VALUE, | |
50 | DSA_TAG_PROTO_DSA = DSA_TAG_PROTO_DSA_VALUE, | |
51 | DSA_TAG_PROTO_EDSA = DSA_TAG_PROTO_EDSA_VALUE, | |
52 | DSA_TAG_PROTO_GSWIP = DSA_TAG_PROTO_GSWIP_VALUE, | |
53 | DSA_TAG_PROTO_KSZ9477 = DSA_TAG_PROTO_KSZ9477_VALUE, | |
54 | DSA_TAG_PROTO_KSZ9893 = DSA_TAG_PROTO_KSZ9893_VALUE, | |
55 | DSA_TAG_PROTO_LAN9303 = DSA_TAG_PROTO_LAN9303_VALUE, | |
56 | DSA_TAG_PROTO_MTK = DSA_TAG_PROTO_MTK_VALUE, | |
57 | DSA_TAG_PROTO_QCA = DSA_TAG_PROTO_QCA_VALUE, | |
58 | DSA_TAG_PROTO_TRAILER = DSA_TAG_PROTO_TRAILER_VALUE, | |
59 | DSA_TAG_LAST, /* MUST BE LAST */ | |
ac7a04c3 | 60 | }; |
5037d532 | 61 | |
5075314e | 62 | struct packet_type; |
90af1059 | 63 | struct dsa_switch; |
3e8a72d1 | 64 | |
68277a2c JC |
65 | struct dsa_device_ops { |
66 | struct sk_buff *(*xmit)(struct sk_buff *skb, struct net_device *dev); | |
67 | struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev, | |
89e49506 | 68 | struct packet_type *pt); |
598a9680 JC |
69 | int (*flow_dissect)(const struct sk_buff *skb, __be16 *proto, |
70 | int *offset); | |
a5dd3087 | 71 | unsigned int overhead; |
875138f8 | 72 | const char *name; |
056eed2f | 73 | enum dsa_tag_protocol proto; |
68277a2c JC |
74 | }; |
75 | ||
0b42f033 AL |
76 | #define DSA_TAG_DRIVER_ALIAS "dsa_tag-" |
77 | #define MODULE_ALIAS_DSA_TAG_DRIVER(__proto) \ | |
78 | MODULE_ALIAS(DSA_TAG_DRIVER_ALIAS __stringify(__proto##_VALUE)) | |
79 | ||
cf50dcc2 | 80 | struct dsa_switch_tree { |
83c0afae AL |
81 | struct list_head list; |
82 | ||
f515f192 VD |
83 | /* Notifier chain for switch-wide events */ |
84 | struct raw_notifier_head nh; | |
85 | ||
83c0afae | 86 | /* Tree identifier */ |
49463b7f | 87 | unsigned int index; |
83c0afae AL |
88 | |
89 | /* Number of switches attached to this tree */ | |
90 | struct kref refcount; | |
91 | ||
92 | /* Has this tree been applied to the hardware? */ | |
ec15dd42 | 93 | bool setup; |
83c0afae | 94 | |
cf50dcc2 BH |
95 | /* |
96 | * Configuration data for the platform device that owns | |
97 | * this dsa switch tree instance. | |
98 | */ | |
99 | struct dsa_platform_data *pd; | |
100 | ||
cf50dcc2 | 101 | /* |
8b0d3ea5 | 102 | * The switch port to which the CPU is attached. |
cf50dcc2 | 103 | */ |
8b0d3ea5 | 104 | struct dsa_port *cpu_dp; |
cf50dcc2 | 105 | |
cf50dcc2 BH |
106 | /* |
107 | * Data for the individual switch chips. | |
108 | */ | |
109 | struct dsa_switch *ds[DSA_MAX_SWITCHES]; | |
110 | }; | |
111 | ||
f50f2127 FF |
112 | /* TC matchall action types, only mirroring for now */ |
113 | enum dsa_port_mall_action_type { | |
114 | DSA_PORT_MALL_MIRROR, | |
115 | }; | |
116 | ||
117 | /* TC mirroring entry */ | |
118 | struct dsa_mall_mirror_tc_entry { | |
119 | u8 to_local_port; | |
120 | bool ingress; | |
121 | }; | |
122 | ||
123 | /* TC matchall entry */ | |
124 | struct dsa_mall_tc_entry { | |
125 | struct list_head list; | |
126 | unsigned long cookie; | |
127 | enum dsa_port_mall_action_type type; | |
128 | union { | |
129 | struct dsa_mall_mirror_tc_entry mirror; | |
130 | }; | |
131 | }; | |
132 | ||
133 | ||
c8b09808 | 134 | struct dsa_port { |
f8b8b1cd VD |
135 | /* A CPU port is physically connected to a master device. |
136 | * A user port exposed to userspace has a slave device. | |
137 | */ | |
138 | union { | |
139 | struct net_device *master; | |
140 | struct net_device *slave; | |
141 | }; | |
142 | ||
15240248 VD |
143 | /* CPU port tagging operations used by master or slave devices */ |
144 | const struct dsa_device_ops *tag_ops; | |
145 | ||
3e41f93b VD |
146 | /* Copies for faster access in master receive hot path */ |
147 | struct dsa_switch_tree *dst; | |
148 | struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev, | |
149 | struct packet_type *pt); | |
150 | ||
057cad2c VD |
151 | enum { |
152 | DSA_PORT_TYPE_UNUSED = 0, | |
153 | DSA_PORT_TYPE_CPU, | |
154 | DSA_PORT_TYPE_DSA, | |
155 | DSA_PORT_TYPE_USER, | |
156 | } type; | |
157 | ||
818be848 VD |
158 | struct dsa_switch *ds; |
159 | unsigned int index; | |
71e0bbde | 160 | const char *name; |
24a9332a | 161 | const struct dsa_port *cpu_dp; |
a2c7023f | 162 | const char *mac; |
189b0d93 | 163 | struct device_node *dn; |
34a79f63 | 164 | unsigned int ageing_time; |
732f794c | 165 | u8 stp_state; |
a5e9a02e | 166 | struct net_device *bridge_dev; |
96567d5d | 167 | struct devlink_port devlink_port; |
aab9c406 | 168 | struct phylink *pl; |
67dbb9d4 FF |
169 | /* |
170 | * Original copy of the master netdev ethtool_ops | |
171 | */ | |
67dbb9d4 | 172 | const struct ethtool_ops *orig_ethtool_ops; |
da7b9e9b FF |
173 | |
174 | /* | |
175 | * Original copy of the master netdev net_device_ops | |
176 | */ | |
177 | const struct net_device_ops *orig_ndo_ops; | |
c8b09808 AL |
178 | }; |
179 | ||
c8f0b869 | 180 | struct dsa_switch { |
c33063d6 AL |
181 | struct device *dev; |
182 | ||
c8f0b869 BH |
183 | /* |
184 | * Parent switch tree, and switch index. | |
185 | */ | |
186 | struct dsa_switch_tree *dst; | |
99feaafc | 187 | unsigned int index; |
c8f0b869 | 188 | |
f515f192 VD |
189 | /* Listener for switch fabric events */ |
190 | struct notifier_block nb; | |
191 | ||
7543a6d5 AL |
192 | /* |
193 | * Give the switch driver somewhere to hang its private data | |
194 | * structure. | |
195 | */ | |
196 | void *priv; | |
197 | ||
c8f0b869 BH |
198 | /* |
199 | * Configuration data for this switch. | |
200 | */ | |
ff04955c | 201 | struct dsa_chip_data *cd; |
c8f0b869 BH |
202 | |
203 | /* | |
9d490b4e | 204 | * The switch operations. |
c8f0b869 | 205 | */ |
a82f67af | 206 | const struct dsa_switch_ops *ops; |
c8f0b869 | 207 | |
66472fc0 AL |
208 | /* |
209 | * An array of which element [a] indicates which port on this | |
210 | * switch should be used to send packets to that are destined | |
211 | * for switch a. Can be NULL if there is only one switch chip. | |
212 | */ | |
213 | s8 rtable[DSA_MAX_SWITCHES]; | |
214 | ||
c8f0b869 BH |
215 | /* |
216 | * Slave mii_bus and devices for the individual ports. | |
217 | */ | |
0d8bcdd3 | 218 | u32 phys_mii_mask; |
c8f0b869 | 219 | struct mii_bus *slave_mii_bus; |
a0c02161 | 220 | |
0f3da6af VD |
221 | /* Ageing Time limits in msecs */ |
222 | unsigned int ageing_time_min; | |
223 | unsigned int ageing_time_max; | |
224 | ||
96567d5d AL |
225 | /* devlink used to represent this switch device */ |
226 | struct devlink *devlink; | |
227 | ||
55199df6 FF |
228 | /* Number of switch port queues */ |
229 | unsigned int num_tx_queues; | |
230 | ||
0015b80a SM |
231 | unsigned long *bitmap; |
232 | unsigned long _bitmap; | |
233 | ||
a0c02161 VD |
234 | /* Dynamically allocated ports, keep last */ |
235 | size_t num_ports; | |
236 | struct dsa_port ports[]; | |
c8f0b869 BH |
237 | }; |
238 | ||
c38c5a66 | 239 | static inline const struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p) |
bff7b688 | 240 | { |
c38c5a66 VD |
241 | return &ds->ports[p]; |
242 | } | |
bff7b688 | 243 | |
c38c5a66 VD |
244 | static inline bool dsa_is_unused_port(struct dsa_switch *ds, int p) |
245 | { | |
246 | return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_UNUSED; | |
bff7b688 VD |
247 | } |
248 | ||
c8f0b869 BH |
249 | static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p) |
250 | { | |
c38c5a66 | 251 | return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_CPU; |
c8f0b869 BH |
252 | } |
253 | ||
60045cbf AL |
254 | static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p) |
255 | { | |
c38c5a66 | 256 | return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_DSA; |
60045cbf AL |
257 | } |
258 | ||
2b3e9891 | 259 | static inline bool dsa_is_user_port(struct dsa_switch *ds, int p) |
6cd456f3 | 260 | { |
c38c5a66 | 261 | return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_USER; |
6cd456f3 VD |
262 | } |
263 | ||
02bc6e54 VD |
264 | static inline u32 dsa_user_ports(struct dsa_switch *ds) |
265 | { | |
c38c5a66 VD |
266 | u32 mask = 0; |
267 | int p; | |
02bc6e54 | 268 | |
c38c5a66 VD |
269 | for (p = 0; p < ds->num_ports; p++) |
270 | if (dsa_is_user_port(ds, p)) | |
271 | mask |= BIT(p); | |
272 | ||
273 | return mask; | |
c8652c83 VD |
274 | } |
275 | ||
3b8fac5d VD |
276 | /* Return the local port used to reach an arbitrary switch port */ |
277 | static inline unsigned int dsa_towards_port(struct dsa_switch *ds, int device, | |
278 | int port) | |
279 | { | |
280 | if (device == ds->index) | |
281 | return port; | |
282 | else | |
283 | return ds->rtable[device]; | |
284 | } | |
285 | ||
286 | /* Return the local port used to reach the dedicated CPU port */ | |
07073c79 | 287 | static inline unsigned int dsa_upstream_port(struct dsa_switch *ds, int port) |
c8f0b869 | 288 | { |
07073c79 VD |
289 | const struct dsa_port *dp = dsa_to_port(ds, port); |
290 | const struct dsa_port *cpu_dp = dp->cpu_dp; | |
291 | ||
292 | if (!cpu_dp) | |
293 | return port; | |
c8f0b869 | 294 | |
3b8fac5d | 295 | return dsa_towards_port(ds, cpu_dp->ds->index, cpu_dp->index); |
c8f0b869 BH |
296 | } |
297 | ||
2bedde1a AS |
298 | typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid, |
299 | bool is_static, void *data); | |
9d490b4e | 300 | struct dsa_switch_ops { |
2a93c1a3 | 301 | #if IS_ENABLED(CONFIG_NET_DSA_LEGACY) |
c8f0b869 | 302 | /* |
a6a71f19 | 303 | * Legacy probing. |
c8f0b869 | 304 | */ |
0209d144 VD |
305 | const char *(*probe)(struct device *dsa_dev, |
306 | struct device *host_dev, int sw_addr, | |
307 | void **priv); | |
2a93c1a3 | 308 | #endif |
7b314362 | 309 | |
5ed4e3eb FF |
310 | enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds, |
311 | int port); | |
7b314362 | 312 | |
c8f0b869 | 313 | int (*setup)(struct dsa_switch *ds); |
6819563e | 314 | u32 (*get_phy_flags)(struct dsa_switch *ds, int port); |
c8f0b869 BH |
315 | |
316 | /* | |
317 | * Access to the switch's PHY registers. | |
318 | */ | |
319 | int (*phy_read)(struct dsa_switch *ds, int port, int regnum); | |
320 | int (*phy_write)(struct dsa_switch *ds, int port, | |
321 | int regnum, u16 val); | |
322 | ||
ec9436ba FF |
323 | /* |
324 | * Link state adjustment (called from libphy) | |
325 | */ | |
326 | void (*adjust_link)(struct dsa_switch *ds, int port, | |
327 | struct phy_device *phydev); | |
ce31b31c FF |
328 | void (*fixed_link_update)(struct dsa_switch *ds, int port, |
329 | struct fixed_phy_status *st); | |
ec9436ba | 330 | |
11d8f3dd FF |
331 | /* |
332 | * PHYLINK integration | |
333 | */ | |
334 | void (*phylink_validate)(struct dsa_switch *ds, int port, | |
335 | unsigned long *supported, | |
336 | struct phylink_link_state *state); | |
337 | int (*phylink_mac_link_state)(struct dsa_switch *ds, int port, | |
338 | struct phylink_link_state *state); | |
339 | void (*phylink_mac_config)(struct dsa_switch *ds, int port, | |
340 | unsigned int mode, | |
341 | const struct phylink_link_state *state); | |
342 | void (*phylink_mac_an_restart)(struct dsa_switch *ds, int port); | |
343 | void (*phylink_mac_link_down)(struct dsa_switch *ds, int port, | |
344 | unsigned int mode, | |
345 | phy_interface_t interface); | |
346 | void (*phylink_mac_link_up)(struct dsa_switch *ds, int port, | |
347 | unsigned int mode, | |
348 | phy_interface_t interface, | |
349 | struct phy_device *phydev); | |
350 | void (*phylink_fixed_state)(struct dsa_switch *ds, int port, | |
351 | struct phylink_link_state *state); | |
c8f0b869 BH |
352 | /* |
353 | * ethtool hardware statistics. | |
354 | */ | |
89f09048 FF |
355 | void (*get_strings)(struct dsa_switch *ds, int port, |
356 | u32 stringset, uint8_t *data); | |
c8f0b869 BH |
357 | void (*get_ethtool_stats)(struct dsa_switch *ds, |
358 | int port, uint64_t *data); | |
89f09048 | 359 | int (*get_sset_count)(struct dsa_switch *ds, int port, int sset); |
cf963573 FF |
360 | void (*get_ethtool_phy_stats)(struct dsa_switch *ds, |
361 | int port, uint64_t *data); | |
24462549 | 362 | |
19e57c4e FF |
363 | /* |
364 | * ethtool Wake-on-LAN | |
365 | */ | |
366 | void (*get_wol)(struct dsa_switch *ds, int port, | |
367 | struct ethtool_wolinfo *w); | |
368 | int (*set_wol)(struct dsa_switch *ds, int port, | |
369 | struct ethtool_wolinfo *w); | |
370 | ||
0336369d BS |
371 | /* |
372 | * ethtool timestamp info | |
373 | */ | |
374 | int (*get_ts_info)(struct dsa_switch *ds, int port, | |
375 | struct ethtool_ts_info *ts); | |
376 | ||
24462549 FF |
377 | /* |
378 | * Suspend and resume | |
379 | */ | |
380 | int (*suspend)(struct dsa_switch *ds); | |
381 | int (*resume)(struct dsa_switch *ds); | |
b2f2af21 FF |
382 | |
383 | /* | |
384 | * Port enable/disable | |
385 | */ | |
386 | int (*port_enable)(struct dsa_switch *ds, int port, | |
387 | struct phy_device *phy); | |
75104db0 | 388 | void (*port_disable)(struct dsa_switch *ds, int port); |
7905288f FF |
389 | |
390 | /* | |
08f50061 | 391 | * Port's MAC EEE settings |
7905288f | 392 | */ |
08f50061 VD |
393 | int (*set_mac_eee)(struct dsa_switch *ds, int port, |
394 | struct ethtool_eee *e); | |
395 | int (*get_mac_eee)(struct dsa_switch *ds, int port, | |
396 | struct ethtool_eee *e); | |
51579c3f | 397 | |
6793abb4 GR |
398 | /* EEPROM access */ |
399 | int (*get_eeprom_len)(struct dsa_switch *ds); | |
400 | int (*get_eeprom)(struct dsa_switch *ds, | |
401 | struct ethtool_eeprom *eeprom, u8 *data); | |
402 | int (*set_eeprom)(struct dsa_switch *ds, | |
403 | struct ethtool_eeprom *eeprom, u8 *data); | |
3d762a0f GR |
404 | |
405 | /* | |
406 | * Register access. | |
407 | */ | |
408 | int (*get_regs_len)(struct dsa_switch *ds, int port); | |
409 | void (*get_regs)(struct dsa_switch *ds, int port, | |
410 | struct ethtool_regs *regs, void *p); | |
b73adef6 FF |
411 | |
412 | /* | |
413 | * Bridge integration | |
414 | */ | |
34a79f63 | 415 | int (*set_ageing_time)(struct dsa_switch *ds, unsigned int msecs); |
71327a4e | 416 | int (*port_bridge_join)(struct dsa_switch *ds, int port, |
a6692754 | 417 | struct net_device *bridge); |
f123f2fb VD |
418 | void (*port_bridge_leave)(struct dsa_switch *ds, int port, |
419 | struct net_device *bridge); | |
43c44a9f VD |
420 | void (*port_stp_state_set)(struct dsa_switch *ds, int port, |
421 | u8 state); | |
732f794c | 422 | void (*port_fast_age)(struct dsa_switch *ds, int port); |
57652796 RK |
423 | int (*port_egress_floods)(struct dsa_switch *ds, int port, |
424 | bool unicast, bool multicast); | |
2a778e1b | 425 | |
11149536 VD |
426 | /* |
427 | * VLAN support | |
428 | */ | |
fb2dabad VD |
429 | int (*port_vlan_filtering)(struct dsa_switch *ds, int port, |
430 | bool vlan_filtering); | |
80e02360 VD |
431 | int (*port_vlan_prepare)(struct dsa_switch *ds, int port, |
432 | const struct switchdev_obj_port_vlan *vlan); | |
433 | void (*port_vlan_add)(struct dsa_switch *ds, int port, | |
434 | const struct switchdev_obj_port_vlan *vlan); | |
76e398a6 VD |
435 | int (*port_vlan_del)(struct dsa_switch *ds, int port, |
436 | const struct switchdev_obj_port_vlan *vlan); | |
2a778e1b VD |
437 | /* |
438 | * Forwarding database | |
439 | */ | |
1b6dd556 | 440 | int (*port_fdb_add)(struct dsa_switch *ds, int port, |
6c2c1dcb | 441 | const unsigned char *addr, u16 vid); |
2a778e1b | 442 | int (*port_fdb_del)(struct dsa_switch *ds, int port, |
6c2c1dcb | 443 | const unsigned char *addr, u16 vid); |
ea70ba98 | 444 | int (*port_fdb_dump)(struct dsa_switch *ds, int port, |
2bedde1a | 445 | dsa_fdb_dump_cb_t *cb, void *data); |
8df30255 VD |
446 | |
447 | /* | |
448 | * Multicast database | |
449 | */ | |
3709aadc VD |
450 | int (*port_mdb_prepare)(struct dsa_switch *ds, int port, |
451 | const struct switchdev_obj_port_mdb *mdb); | |
452 | void (*port_mdb_add)(struct dsa_switch *ds, int port, | |
453 | const struct switchdev_obj_port_mdb *mdb); | |
8df30255 VD |
454 | int (*port_mdb_del)(struct dsa_switch *ds, int port, |
455 | const struct switchdev_obj_port_mdb *mdb); | |
bf9f2648 FF |
456 | /* |
457 | * RXNFC | |
458 | */ | |
459 | int (*get_rxnfc)(struct dsa_switch *ds, int port, | |
460 | struct ethtool_rxnfc *nfc, u32 *rule_locs); | |
461 | int (*set_rxnfc)(struct dsa_switch *ds, int port, | |
462 | struct ethtool_rxnfc *nfc); | |
f50f2127 FF |
463 | |
464 | /* | |
465 | * TC integration | |
466 | */ | |
467 | int (*port_mirror_add)(struct dsa_switch *ds, int port, | |
468 | struct dsa_mall_mirror_tc_entry *mirror, | |
469 | bool ingress); | |
470 | void (*port_mirror_del)(struct dsa_switch *ds, int port, | |
471 | struct dsa_mall_mirror_tc_entry *mirror); | |
40ef2c93 VD |
472 | |
473 | /* | |
474 | * Cross-chip operations | |
475 | */ | |
476 | int (*crosschip_bridge_join)(struct dsa_switch *ds, int sw_index, | |
477 | int port, struct net_device *br); | |
478 | void (*crosschip_bridge_leave)(struct dsa_switch *ds, int sw_index, | |
479 | int port, struct net_device *br); | |
0336369d BS |
480 | |
481 | /* | |
482 | * PTP functionality | |
483 | */ | |
484 | int (*port_hwtstamp_get)(struct dsa_switch *ds, int port, | |
485 | struct ifreq *ifr); | |
486 | int (*port_hwtstamp_set)(struct dsa_switch *ds, int port, | |
487 | struct ifreq *ifr); | |
90af1059 BS |
488 | bool (*port_txtstamp)(struct dsa_switch *ds, int port, |
489 | struct sk_buff *clone, unsigned int type); | |
490 | bool (*port_rxtstamp)(struct dsa_switch *ds, int port, | |
491 | struct sk_buff *skb, unsigned int type); | |
c8f0b869 BH |
492 | }; |
493 | ||
ab3d408d FF |
494 | struct dsa_switch_driver { |
495 | struct list_head list; | |
a82f67af | 496 | const struct dsa_switch_ops *ops; |
ab3d408d FF |
497 | }; |
498 | ||
2a93c1a3 | 499 | #if IS_ENABLED(CONFIG_NET_DSA_LEGACY) |
a6a71f19 | 500 | /* Legacy driver registration */ |
ab3d408d FF |
501 | void register_switch_driver(struct dsa_switch_driver *type); |
502 | void unregister_switch_driver(struct dsa_switch_driver *type); | |
b4d2394d | 503 | struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev); |
a6a71f19 | 504 | |
2a93c1a3 FF |
505 | #else |
506 | static inline void register_switch_driver(struct dsa_switch_driver *type) { } | |
507 | static inline void unregister_switch_driver(struct dsa_switch_driver *type) { } | |
508 | static inline struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev) | |
509 | { | |
510 | return NULL; | |
511 | } | |
512 | #endif | |
14b89f36 | 513 | struct net_device *dsa_dev_to_net_device(struct device *dev); |
c8f0b869 | 514 | |
73a7ece8 | 515 | /* Keep inline for faster access in hot path */ |
c6e970a0 AL |
516 | static inline bool netdev_uses_dsa(struct net_device *dev) |
517 | { | |
518 | #if IS_ENABLED(CONFIG_NET_DSA) | |
717ffbfb | 519 | return dev->dsa_ptr && dev->dsa_ptr->rcv; |
c6e970a0 AL |
520 | #endif |
521 | return false; | |
522 | } | |
523 | ||
a0c02161 | 524 | struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n); |
83c0afae | 525 | void dsa_unregister_switch(struct dsa_switch *ds); |
23c9ee49 | 526 | int dsa_register_switch(struct dsa_switch *ds); |
ea825e70 FF |
527 | #ifdef CONFIG_PM_SLEEP |
528 | int dsa_switch_suspend(struct dsa_switch *ds); | |
529 | int dsa_switch_resume(struct dsa_switch *ds); | |
530 | #else | |
531 | static inline int dsa_switch_suspend(struct dsa_switch *ds) | |
532 | { | |
533 | return 0; | |
534 | } | |
535 | static inline int dsa_switch_resume(struct dsa_switch *ds) | |
536 | { | |
537 | return 0; | |
538 | } | |
539 | #endif /* CONFIG_PM_SLEEP */ | |
540 | ||
60724d4b FF |
541 | enum dsa_notifier_type { |
542 | DSA_PORT_REGISTER, | |
543 | DSA_PORT_UNREGISTER, | |
544 | }; | |
545 | ||
546 | struct dsa_notifier_info { | |
547 | struct net_device *dev; | |
548 | }; | |
549 | ||
550 | struct dsa_notifier_register_info { | |
551 | struct dsa_notifier_info info; /* must be first */ | |
552 | struct net_device *master; | |
553 | unsigned int port_number; | |
554 | unsigned int switch_number; | |
555 | }; | |
556 | ||
557 | static inline struct net_device * | |
558 | dsa_notifier_info_to_dev(const struct dsa_notifier_info *info) | |
559 | { | |
560 | return info->dev; | |
561 | } | |
562 | ||
563 | #if IS_ENABLED(CONFIG_NET_DSA) | |
564 | int register_dsa_notifier(struct notifier_block *nb); | |
565 | int unregister_dsa_notifier(struct notifier_block *nb); | |
566 | int call_dsa_notifiers(unsigned long val, struct net_device *dev, | |
567 | struct dsa_notifier_info *info); | |
568 | #else | |
569 | static inline int register_dsa_notifier(struct notifier_block *nb) | |
570 | { | |
571 | return 0; | |
572 | } | |
573 | ||
574 | static inline int unregister_dsa_notifier(struct notifier_block *nb) | |
575 | { | |
576 | return 0; | |
577 | } | |
578 | ||
579 | static inline int call_dsa_notifiers(unsigned long val, struct net_device *dev, | |
580 | struct dsa_notifier_info *info) | |
581 | { | |
582 | return NOTIFY_DONE; | |
583 | } | |
584 | #endif | |
585 | ||
0a5f14ce FF |
586 | /* Broadcom tag specific helpers to insert and extract queue/port number */ |
587 | #define BRCM_TAG_SET_PORT_QUEUE(p, q) ((p) << 8 | q) | |
588 | #define BRCM_TAG_GET_PORT(v) ((v) >> 8) | |
589 | #define BRCM_TAG_GET_QUEUE(v) ((v) & 0xff) | |
590 | ||
cf963573 FF |
591 | |
592 | int dsa_port_get_phy_strings(struct dsa_port *dp, uint8_t *data); | |
593 | int dsa_port_get_ethtool_phy_stats(struct dsa_port *dp, uint64_t *data); | |
594 | int dsa_port_get_phy_sset_count(struct dsa_port *dp); | |
11d8f3dd | 595 | void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up); |
cf963573 | 596 | |
91da11f8 | 597 | #endif |