xref: /openbmc/linux/include/net/dsa.h (revision a88dd753)
12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
291da11f8SLennert Buytenhek /*
391da11f8SLennert Buytenhek  * include/net/dsa.h - Driver for Distributed Switch Architecture switch chips
4e84665c9SLennert Buytenhek  * Copyright (c) 2008-2009 Marvell Semiconductor
591da11f8SLennert Buytenhek  */
691da11f8SLennert Buytenhek 
791da11f8SLennert Buytenhek #ifndef __LINUX_NET_DSA_H
891da11f8SLennert Buytenhek #define __LINUX_NET_DSA_H
991da11f8SLennert Buytenhek 
104d56a29fSRussell King #include <linux/if.h>
11ea1f51beSAxel Lin #include <linux/if_ether.h>
12c8f0b869SBen Hutchings #include <linux/list.h>
13f515f192SVivien Didelot #include <linux/notifier.h>
14cf50dcc2SBen Hutchings #include <linux/timer.h>
15cf50dcc2SBen Hutchings #include <linux/workqueue.h>
16fa981d9aSFlorian Fainelli #include <linux/of.h>
17a2820543SFlorian Fainelli #include <linux/ethtool.h>
180336369dSBrandon Streiff #include <linux/net_tstamp.h>
1911d8f3ddSFlorian Fainelli #include <linux/phy.h>
20ecfc9372SFlorian Fainelli #include <linux/platform_data/dsa.h>
2144cc27e4SIoana Ciornei #include <linux/phylink.h>
2296567d5dSAndrew Lunn #include <net/devlink.h>
23f0c24ccfSVivien Didelot #include <net/switchdev.h>
24cf50dcc2SBen Hutchings 
2519d05ea7SVladimir Oltean struct dsa_8021q_context;
26f50f2127SFlorian Fainelli struct tc_action;
274d56a29fSRussell King struct phy_device;
284d56a29fSRussell King struct fixed_phy_status;
2911d8f3ddSFlorian Fainelli struct phylink_link_state;
30f50f2127SFlorian Fainelli 
310b42f033SAndrew Lunn #define DSA_TAG_PROTO_NONE_VALUE		0
320b42f033SAndrew Lunn #define DSA_TAG_PROTO_BRCM_VALUE		1
330b42f033SAndrew Lunn #define DSA_TAG_PROTO_BRCM_PREPEND_VALUE	2
340b42f033SAndrew Lunn #define DSA_TAG_PROTO_DSA_VALUE			3
350b42f033SAndrew Lunn #define DSA_TAG_PROTO_EDSA_VALUE		4
360b42f033SAndrew Lunn #define DSA_TAG_PROTO_GSWIP_VALUE		5
370b42f033SAndrew Lunn #define DSA_TAG_PROTO_KSZ9477_VALUE		6
380b42f033SAndrew Lunn #define DSA_TAG_PROTO_KSZ9893_VALUE		7
390b42f033SAndrew Lunn #define DSA_TAG_PROTO_LAN9303_VALUE		8
400b42f033SAndrew Lunn #define DSA_TAG_PROTO_MTK_VALUE			9
410b42f033SAndrew Lunn #define DSA_TAG_PROTO_QCA_VALUE			10
420b42f033SAndrew Lunn #define DSA_TAG_PROTO_TRAILER_VALUE		11
43f9bbe447SVladimir Oltean #define DSA_TAG_PROTO_8021Q_VALUE		12
44227d07a0SVladimir Oltean #define DSA_TAG_PROTO_SJA1105_VALUE		13
45016e43a2STristram Ha #define DSA_TAG_PROTO_KSZ8795_VALUE		14
468dce89aaSVladimir Oltean #define DSA_TAG_PROTO_OCELOT_VALUE		15
4748fda74fSOleksij Rempel #define DSA_TAG_PROTO_AR9331_VALUE		16
48efd7fe68SLinus Walleij #define DSA_TAG_PROTO_RTL4_A_VALUE		17
4901ef09caSKurt Kanzenbach #define DSA_TAG_PROTO_HELLCREEK_VALUE		18
5054a52823SGeorge McCollister #define DSA_TAG_PROTO_XRS700X_VALUE		19
517c83a7c5SVladimir Oltean #define DSA_TAG_PROTO_OCELOT_8021Q_VALUE	20
527c4bb540SVladimir Oltean #define DSA_TAG_PROTO_SEVILLE_VALUE		21
53964dbf18SÁlvaro Fernández Rojas #define DSA_TAG_PROTO_BRCM_LEGACY_VALUE		22
544913b8ebSVladimir Oltean #define DSA_TAG_PROTO_SJA1110_VALUE		23
551521d5adSAlvin Šipraga #define DSA_TAG_PROTO_RTL8_4_VALUE		24
56cd87fecdSLuiz Angelo Daros de Luca #define DSA_TAG_PROTO_RTL8_4T_VALUE		25
57a08d6a6dSClément Léger #define DSA_TAG_PROTO_RZN1_A5PSW_VALUE		26
58092f8751SPrasanna Vengateshan #define DSA_TAG_PROTO_LAN937X_VALUE		27
590b42f033SAndrew Lunn 
60ac7a04c3SFlorian Fainelli enum dsa_tag_protocol {
610b42f033SAndrew Lunn 	DSA_TAG_PROTO_NONE		= DSA_TAG_PROTO_NONE_VALUE,
620b42f033SAndrew Lunn 	DSA_TAG_PROTO_BRCM		= DSA_TAG_PROTO_BRCM_VALUE,
63964dbf18SÁlvaro Fernández Rojas 	DSA_TAG_PROTO_BRCM_LEGACY	= DSA_TAG_PROTO_BRCM_LEGACY_VALUE,
640b42f033SAndrew Lunn 	DSA_TAG_PROTO_BRCM_PREPEND	= DSA_TAG_PROTO_BRCM_PREPEND_VALUE,
650b42f033SAndrew Lunn 	DSA_TAG_PROTO_DSA		= DSA_TAG_PROTO_DSA_VALUE,
660b42f033SAndrew Lunn 	DSA_TAG_PROTO_EDSA		= DSA_TAG_PROTO_EDSA_VALUE,
670b42f033SAndrew Lunn 	DSA_TAG_PROTO_GSWIP		= DSA_TAG_PROTO_GSWIP_VALUE,
680b42f033SAndrew Lunn 	DSA_TAG_PROTO_KSZ9477		= DSA_TAG_PROTO_KSZ9477_VALUE,
690b42f033SAndrew Lunn 	DSA_TAG_PROTO_KSZ9893		= DSA_TAG_PROTO_KSZ9893_VALUE,
700b42f033SAndrew Lunn 	DSA_TAG_PROTO_LAN9303		= DSA_TAG_PROTO_LAN9303_VALUE,
710b42f033SAndrew Lunn 	DSA_TAG_PROTO_MTK		= DSA_TAG_PROTO_MTK_VALUE,
720b42f033SAndrew Lunn 	DSA_TAG_PROTO_QCA		= DSA_TAG_PROTO_QCA_VALUE,
730b42f033SAndrew Lunn 	DSA_TAG_PROTO_TRAILER		= DSA_TAG_PROTO_TRAILER_VALUE,
74f9bbe447SVladimir Oltean 	DSA_TAG_PROTO_8021Q		= DSA_TAG_PROTO_8021Q_VALUE,
75227d07a0SVladimir Oltean 	DSA_TAG_PROTO_SJA1105		= DSA_TAG_PROTO_SJA1105_VALUE,
76016e43a2STristram Ha 	DSA_TAG_PROTO_KSZ8795		= DSA_TAG_PROTO_KSZ8795_VALUE,
778dce89aaSVladimir Oltean 	DSA_TAG_PROTO_OCELOT		= DSA_TAG_PROTO_OCELOT_VALUE,
7848fda74fSOleksij Rempel 	DSA_TAG_PROTO_AR9331		= DSA_TAG_PROTO_AR9331_VALUE,
79efd7fe68SLinus Walleij 	DSA_TAG_PROTO_RTL4_A		= DSA_TAG_PROTO_RTL4_A_VALUE,
8001ef09caSKurt Kanzenbach 	DSA_TAG_PROTO_HELLCREEK		= DSA_TAG_PROTO_HELLCREEK_VALUE,
8154a52823SGeorge McCollister 	DSA_TAG_PROTO_XRS700X		= DSA_TAG_PROTO_XRS700X_VALUE,
827c83a7c5SVladimir Oltean 	DSA_TAG_PROTO_OCELOT_8021Q	= DSA_TAG_PROTO_OCELOT_8021Q_VALUE,
837c4bb540SVladimir Oltean 	DSA_TAG_PROTO_SEVILLE		= DSA_TAG_PROTO_SEVILLE_VALUE,
844913b8ebSVladimir Oltean 	DSA_TAG_PROTO_SJA1110		= DSA_TAG_PROTO_SJA1110_VALUE,
851521d5adSAlvin Šipraga 	DSA_TAG_PROTO_RTL8_4		= DSA_TAG_PROTO_RTL8_4_VALUE,
86cd87fecdSLuiz Angelo Daros de Luca 	DSA_TAG_PROTO_RTL8_4T		= DSA_TAG_PROTO_RTL8_4T_VALUE,
87a08d6a6dSClément Léger 	DSA_TAG_PROTO_RZN1_A5PSW	= DSA_TAG_PROTO_RZN1_A5PSW_VALUE,
88092f8751SPrasanna Vengateshan 	DSA_TAG_PROTO_LAN937X		= DSA_TAG_PROTO_LAN937X_VALUE,
89ac7a04c3SFlorian Fainelli };
905037d532SFlorian Fainelli 
9190af1059SBrandon Streiff struct dsa_switch;
923e8a72d1SFlorian Fainelli 
9368277a2cSJohn Crispin struct dsa_device_ops {
9468277a2cSJohn Crispin 	struct sk_buff *(*xmit)(struct sk_buff *skb, struct net_device *dev);
9529a097b7SVladimir Oltean 	struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev);
962e8cb1b3SVladimir Oltean 	void (*flow_dissect)(const struct sk_buff *skb, __be16 *proto,
97598a9680SJohn Crispin 			     int *offset);
987f297314SVladimir Oltean 	int (*connect)(struct dsa_switch *ds);
997f297314SVladimir Oltean 	void (*disconnect)(struct dsa_switch *ds);
1004e500251SVladimir Oltean 	unsigned int needed_headroom;
1014e500251SVladimir Oltean 	unsigned int needed_tailroom;
102875138f8SAndrew Lunn 	const char *name;
103056eed2fSAndrew Lunn 	enum dsa_tag_protocol proto;
104c3975400SVladimir Oltean 	/* Some tagging protocols either mangle or shift the destination MAC
105c3975400SVladimir Oltean 	 * address, in which case the DSA master would drop packets on ingress
106c3975400SVladimir Oltean 	 * if what it understands out of the destination MAC address is not in
107c3975400SVladimir Oltean 	 * its RX filter.
108c3975400SVladimir Oltean 	 */
109c3975400SVladimir Oltean 	bool promisc_on_master;
11068277a2cSJohn Crispin };
11168277a2cSJohn Crispin 
112dedd6a00SVladimir Oltean struct dsa_lag {
113dedd6a00SVladimir Oltean 	struct net_device *dev;
114dedd6a00SVladimir Oltean 	unsigned int id;
115e212fa7cSVladimir Oltean 	struct mutex fdb_lock;
116e212fa7cSVladimir Oltean 	struct list_head fdbs;
117dedd6a00SVladimir Oltean 	refcount_t refcount;
118dedd6a00SVladimir Oltean };
119dedd6a00SVladimir Oltean 
120cf50dcc2SBen Hutchings struct dsa_switch_tree {
12183c0afaeSAndrew Lunn 	struct list_head	list;
12283c0afaeSAndrew Lunn 
123b035c88cSVladimir Oltean 	/* List of switch ports */
124b035c88cSVladimir Oltean 	struct list_head ports;
125b035c88cSVladimir Oltean 
126f515f192SVivien Didelot 	/* Notifier chain for switch-wide events */
127f515f192SVivien Didelot 	struct raw_notifier_head	nh;
128f515f192SVivien Didelot 
12983c0afaeSAndrew Lunn 	/* Tree identifier */
13049463b7fSVivien Didelot 	unsigned int index;
13183c0afaeSAndrew Lunn 
13283c0afaeSAndrew Lunn 	/* Number of switches attached to this tree */
13383c0afaeSAndrew Lunn 	struct kref refcount;
13483c0afaeSAndrew Lunn 
135b035c88cSVladimir Oltean 	/* Maps offloaded LAG netdevs to a zero-based linear ID for
136b035c88cSVladimir Oltean 	 * drivers that need it.
137b035c88cSVladimir Oltean 	 */
138dedd6a00SVladimir Oltean 	struct dsa_lag **lags;
139b035c88cSVladimir Oltean 
140357f203bSVladimir Oltean 	/* Tagging protocol operations */
141357f203bSVladimir Oltean 	const struct dsa_device_ops *tag_ops;
142357f203bSVladimir Oltean 
143deff7107STobias Waldekranz 	/* Default tagging protocol preferred by the switches in this
144deff7107STobias Waldekranz 	 * tree.
145deff7107STobias Waldekranz 	 */
146deff7107STobias Waldekranz 	enum dsa_tag_protocol default_proto;
147deff7107STobias Waldekranz 
1484b026e82SVladimir Oltean 	/* Has this tree been applied to the hardware? */
1494b026e82SVladimir Oltean 	bool setup;
1504b026e82SVladimir Oltean 
151cf50dcc2SBen Hutchings 	/*
152cf50dcc2SBen Hutchings 	 * Configuration data for the platform device that owns
153cf50dcc2SBen Hutchings 	 * this dsa switch tree instance.
154cf50dcc2SBen Hutchings 	 */
155cf50dcc2SBen Hutchings 	struct dsa_platform_data	*pd;
156cf85d08fSLennert Buytenhek 
157c5f51765SVivien Didelot 	/* List of DSA links composing the routing table */
158c5f51765SVivien Didelot 	struct list_head rtable;
159058102a6STobias Waldekranz 
160b035c88cSVladimir Oltean 	/* Length of "lags" array */
161058102a6STobias Waldekranz 	unsigned int lags_len;
1625b22d366SVladimir Oltean 
1635b22d366SVladimir Oltean 	/* Track the largest switch index within a tree */
1645b22d366SVladimir Oltean 	unsigned int last_switch;
165cf50dcc2SBen Hutchings };
166cf50dcc2SBen Hutchings 
1673d4a0a2aSVladimir Oltean /* LAG IDs are one-based, the dst->lags array is zero-based */
168058102a6STobias Waldekranz #define dsa_lags_foreach_id(_id, _dst)				\
1693d4a0a2aSVladimir Oltean 	for ((_id) = 1; (_id) <= (_dst)->lags_len; (_id)++)	\
1703d4a0a2aSVladimir Oltean 		if ((_dst)->lags[(_id) - 1])
171058102a6STobias Waldekranz 
172058102a6STobias Waldekranz #define dsa_lag_foreach_port(_dp, _dst, _lag)			\
173058102a6STobias Waldekranz 	list_for_each_entry((_dp), &(_dst)->ports, list)	\
174dedd6a00SVladimir Oltean 		if (dsa_port_offloads_lag((_dp), (_lag)))
175058102a6STobias Waldekranz 
17618596f50SGeorge McCollister #define dsa_hsr_foreach_port(_dp, _ds, _hsr)			\
17718596f50SGeorge McCollister 	list_for_each_entry((_dp), &(_ds)->dst->ports, list)	\
17818596f50SGeorge McCollister 		if ((_dp)->ds == (_ds) && (_dp)->hsr_dev == (_hsr))
17918596f50SGeorge McCollister 
dsa_lag_by_id(struct dsa_switch_tree * dst,unsigned int id)180dedd6a00SVladimir Oltean static inline struct dsa_lag *dsa_lag_by_id(struct dsa_switch_tree *dst,
181058102a6STobias Waldekranz 					    unsigned int id)
182058102a6STobias Waldekranz {
1833d4a0a2aSVladimir Oltean 	/* DSA LAG IDs are one-based, dst->lags is zero-based */
1843d4a0a2aSVladimir Oltean 	return dst->lags[id - 1];
185058102a6STobias Waldekranz }
186058102a6STobias Waldekranz 
dsa_lag_id(struct dsa_switch_tree * dst,struct net_device * lag_dev)187058102a6STobias Waldekranz static inline int dsa_lag_id(struct dsa_switch_tree *dst,
18846a76724SVladimir Oltean 			     struct net_device *lag_dev)
189058102a6STobias Waldekranz {
190058102a6STobias Waldekranz 	unsigned int id;
191058102a6STobias Waldekranz 
192058102a6STobias Waldekranz 	dsa_lags_foreach_id(id, dst) {
193dedd6a00SVladimir Oltean 		struct dsa_lag *lag = dsa_lag_by_id(dst, id);
194dedd6a00SVladimir Oltean 
195dedd6a00SVladimir Oltean 		if (lag->dev == lag_dev)
196dedd6a00SVladimir Oltean 			return lag->id;
197058102a6STobias Waldekranz 	}
198058102a6STobias Waldekranz 
199058102a6STobias Waldekranz 	return -ENODEV;
200058102a6STobias Waldekranz }
201058102a6STobias Waldekranz 
20234297176SVladimir Oltean /* TC matchall action types */
203f50f2127SFlorian Fainelli enum dsa_port_mall_action_type {
204f50f2127SFlorian Fainelli 	DSA_PORT_MALL_MIRROR,
20534297176SVladimir Oltean 	DSA_PORT_MALL_POLICER,
206f50f2127SFlorian Fainelli };
207f50f2127SFlorian Fainelli 
208f50f2127SFlorian Fainelli /* TC mirroring entry */
209f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry {
210f50f2127SFlorian Fainelli 	u8 to_local_port;
211f50f2127SFlorian Fainelli 	bool ingress;
212f50f2127SFlorian Fainelli };
213f50f2127SFlorian Fainelli 
21434297176SVladimir Oltean /* TC port policer entry */
21534297176SVladimir Oltean struct dsa_mall_policer_tc_entry {
2165f035af7SPo Liu 	u32 burst;
21734297176SVladimir Oltean 	u64 rate_bytes_per_sec;
21834297176SVladimir Oltean };
21934297176SVladimir Oltean 
220f50f2127SFlorian Fainelli /* TC matchall entry */
221f50f2127SFlorian Fainelli struct dsa_mall_tc_entry {
222f50f2127SFlorian Fainelli 	struct list_head list;
223f50f2127SFlorian Fainelli 	unsigned long cookie;
224f50f2127SFlorian Fainelli 	enum dsa_port_mall_action_type type;
225f50f2127SFlorian Fainelli 	union {
226f50f2127SFlorian Fainelli 		struct dsa_mall_mirror_tc_entry mirror;
22734297176SVladimir Oltean 		struct dsa_mall_policer_tc_entry policer;
228f50f2127SFlorian Fainelli 	};
229f50f2127SFlorian Fainelli };
230f50f2127SFlorian Fainelli 
231d3eed0e5SVladimir Oltean struct dsa_bridge {
232d3eed0e5SVladimir Oltean 	struct net_device *dev;
233d3eed0e5SVladimir Oltean 	unsigned int num;
234857fdd74SVladimir Oltean 	bool tx_fwd_offload;
235d3eed0e5SVladimir Oltean 	refcount_t refcount;
236d3eed0e5SVladimir Oltean };
237f50f2127SFlorian Fainelli 
238c8b09808SAndrew Lunn struct dsa_port {
239f8b8b1cdSVivien Didelot 	/* A CPU port is physically connected to a master device.
240f8b8b1cdSVivien Didelot 	 * A user port exposed to userspace has a slave device.
241f8b8b1cdSVivien Didelot 	 */
242f8b8b1cdSVivien Didelot 	union {
243f8b8b1cdSVivien Didelot 		struct net_device *master;
244f8b8b1cdSVivien Didelot 		struct net_device *slave;
245f8b8b1cdSVivien Didelot 	};
246f8b8b1cdSVivien Didelot 
247357f203bSVladimir Oltean 	/* Copy of the tagging protocol operations, for quicker access
248357f203bSVladimir Oltean 	 * in the data path. Valid only for the CPU ports.
249357f203bSVladimir Oltean 	 */
25015240248SVivien Didelot 	const struct dsa_device_ops *tag_ops;
25115240248SVivien Didelot 
2523e41f93bSVivien Didelot 	/* Copies for faster access in master receive hot path */
2533e41f93bSVivien Didelot 	struct dsa_switch_tree *dst;
25429a097b7SVladimir Oltean 	struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev);
2553e41f93bSVivien Didelot 
25606251258SVladimir Oltean 	struct dsa_switch	*ds;
25706251258SVladimir Oltean 
25806251258SVladimir Oltean 	unsigned int		index;
25906251258SVladimir Oltean 
260057cad2cSVivien Didelot 	enum {
261057cad2cSVivien Didelot 		DSA_PORT_TYPE_UNUSED = 0,
262057cad2cSVivien Didelot 		DSA_PORT_TYPE_CPU,
263057cad2cSVivien Didelot 		DSA_PORT_TYPE_DSA,
264057cad2cSVivien Didelot 		DSA_PORT_TYPE_USER,
265057cad2cSVivien Didelot 	} type;
266057cad2cSVivien Didelot 
26771e0bbdeSFlorian Fainelli 	const char		*name;
26868b2d4a8SVivien Didelot 	struct dsa_port		*cpu_dp;
26983216e39SMichael Walle 	u8			mac[ETH_ALEN];
270b08db33dSVladimir Oltean 
271b08db33dSVladimir Oltean 	u8			stp_state;
272b08db33dSVladimir Oltean 
2731b26d364SVladimir Oltean 	/* Warning: the following bit fields are not atomic, and updating them
2741b26d364SVladimir Oltean 	 * can only be done from code paths where concurrency is not possible
2751b26d364SVladimir Oltean 	 * (probe time or under rtnl_lock).
2761b26d364SVladimir Oltean 	 */
27763cfc657SVladimir Oltean 	u8			vlan_filtering:1;
27863cfc657SVladimir Oltean 
27963cfc657SVladimir Oltean 	/* Managed by DSA on user ports and by drivers on CPU and DSA ports */
28063cfc657SVladimir Oltean 	u8			learning:1;
28163cfc657SVladimir Oltean 
28263cfc657SVladimir Oltean 	u8			lag_tx_enabled:1;
28363cfc657SVladimir Oltean 
284295ab96fSVladimir Oltean 	/* Master state bits, valid only on CPU ports */
285295ab96fSVladimir Oltean 	u8			master_admin_up:1;
286295ab96fSVladimir Oltean 	u8			master_oper_up:1;
287295ab96fSVladimir Oltean 
288acc43b7bSVladimir Oltean 	/* Valid only on user ports */
289acc43b7bSVladimir Oltean 	u8			cpu_port_in_lag:1;
290acc43b7bSVladimir Oltean 
29163cfc657SVladimir Oltean 	u8			setup:1;
292bde82f38SVladimir Oltean 
293189b0d93SAndrew Lunn 	struct device_node	*dn;
29434a79f63SVivien Didelot 	unsigned int		ageing_time;
295bde82f38SVladimir Oltean 
296d3eed0e5SVladimir Oltean 	struct dsa_bridge	*bridge;
29796567d5dSAndrew Lunn 	struct devlink_port	devlink_port;
298aab9c406SFlorian Fainelli 	struct phylink		*pl;
29944cc27e4SIoana Ciornei 	struct phylink_config	pl_config;
300dedd6a00SVladimir Oltean 	struct dsa_lag		*lag;
30118596f50SGeorge McCollister 	struct net_device	*hsr_dev;
30297a69a0dSVladimir Oltean 
303ab8ccae1SVivien Didelot 	struct list_head list;
304ab8ccae1SVivien Didelot 
30567dbb9d4SFlorian Fainelli 	/*
30667dbb9d4SFlorian Fainelli 	 * Original copy of the master netdev ethtool_ops
30767dbb9d4SFlorian Fainelli 	 */
30867dbb9d4SFlorian Fainelli 	const struct ethtool_ops *orig_ethtool_ops;
309da7b9e9bSFlorian Fainelli 
310161ca59dSVladimir Oltean 	/* List of MAC addresses that must be forwarded on this port.
311161ca59dSVladimir Oltean 	 * These are only valid on CPU ports and DSA links.
312161ca59dSVladimir Oltean 	 */
313338a3a47SVladimir Oltean 	struct mutex		addr_lists_lock;
3143f6e32f9SVladimir Oltean 	struct list_head	fdbs;
315161ca59dSVladimir Oltean 	struct list_head	mdbs;
316134ef238SVladimir Oltean 
317134ef238SVladimir Oltean 	struct mutex		vlans_lock;
318*d06f925fSVladimir Oltean 	union {
319*d06f925fSVladimir Oltean 		/* List of VLANs that CPU and DSA ports are members of.
320*d06f925fSVladimir Oltean 		 * Access to this is serialized by the sleepable @vlans_lock.
321*d06f925fSVladimir Oltean 		 */
322134ef238SVladimir Oltean 		struct list_head	vlans;
323*d06f925fSVladimir Oltean 		/* List of VLANs that user ports are members of.
324*d06f925fSVladimir Oltean 		 * Access to this is serialized by netif_addr_lock_bh().
325*d06f925fSVladimir Oltean 		 */
326*d06f925fSVladimir Oltean 		struct list_head	user_vlans;
327*d06f925fSVladimir Oltean 	};
328c8b09808SAndrew Lunn };
329c8b09808SAndrew Lunn 
330c5f51765SVivien Didelot /* TODO: ideally DSA ports would have a single dp->link_dp member,
331c5f51765SVivien Didelot  * and no dst->rtable nor this struct dsa_link would be needed,
332c5f51765SVivien Didelot  * but this would require some more complex tree walking,
333c5f51765SVivien Didelot  * so keep it stupid at the moment and list them all.
334c5f51765SVivien Didelot  */
335c5f51765SVivien Didelot struct dsa_link {
336c5f51765SVivien Didelot 	struct dsa_port *dp;
337c5f51765SVivien Didelot 	struct dsa_port *link_dp;
338c5f51765SVivien Didelot 	struct list_head list;
339c5f51765SVivien Didelot };
340c5f51765SVivien Didelot 
341c2693363SVladimir Oltean enum dsa_db_type {
342c2693363SVladimir Oltean 	DSA_DB_PORT,
343c2693363SVladimir Oltean 	DSA_DB_LAG,
344c2693363SVladimir Oltean 	DSA_DB_BRIDGE,
345c2693363SVladimir Oltean };
346c2693363SVladimir Oltean 
347c2693363SVladimir Oltean struct dsa_db {
348c2693363SVladimir Oltean 	enum dsa_db_type type;
349c2693363SVladimir Oltean 
350c2693363SVladimir Oltean 	union {
351c2693363SVladimir Oltean 		const struct dsa_port *dp;
352c2693363SVladimir Oltean 		struct dsa_lag lag;
353c2693363SVladimir Oltean 		struct dsa_bridge bridge;
354c2693363SVladimir Oltean 	};
355c2693363SVladimir Oltean };
356c2693363SVladimir Oltean 
357161ca59dSVladimir Oltean struct dsa_mac_addr {
358161ca59dSVladimir Oltean 	unsigned char addr[ETH_ALEN];
359161ca59dSVladimir Oltean 	u16 vid;
360161ca59dSVladimir Oltean 	refcount_t refcount;
361161ca59dSVladimir Oltean 	struct list_head list;
362c2693363SVladimir Oltean 	struct dsa_db db;
363161ca59dSVladimir Oltean };
364161ca59dSVladimir Oltean 
365134ef238SVladimir Oltean struct dsa_vlan {
366134ef238SVladimir Oltean 	u16 vid;
367134ef238SVladimir Oltean 	refcount_t refcount;
368134ef238SVladimir Oltean 	struct list_head list;
369134ef238SVladimir Oltean };
370134ef238SVladimir Oltean 
371c8f0b869SBen Hutchings struct dsa_switch {
372c33063d6SAndrew Lunn 	struct device *dev;
373c33063d6SAndrew Lunn 
374c8f0b869SBen Hutchings 	/*
375c8f0b869SBen Hutchings 	 * Parent switch tree, and switch index.
376c8f0b869SBen Hutchings 	 */
377c8f0b869SBen Hutchings 	struct dsa_switch_tree	*dst;
37899feaafcSVivien Didelot 	unsigned int		index;
379c8f0b869SBen Hutchings 
3801b26d364SVladimir Oltean 	/* Warning: the following bit fields are not atomic, and updating them
3811b26d364SVladimir Oltean 	 * can only be done from code paths where concurrency is not possible
3821b26d364SVladimir Oltean 	 * (probe time or under rtnl_lock).
3831b26d364SVladimir Oltean 	 */
38463cfc657SVladimir Oltean 	u32			setup:1;
38563cfc657SVladimir Oltean 
38663cfc657SVladimir Oltean 	/* Disallow bridge core from requesting different VLAN awareness
38763cfc657SVladimir Oltean 	 * settings on ports if not hardware-supported
3887787ff77SVladimir Oltean 	 */
38963cfc657SVladimir Oltean 	u32			vlan_filtering_is_global:1;
39063cfc657SVladimir Oltean 
39163cfc657SVladimir Oltean 	/* Keep VLAN filtering enabled on ports not offloading any upper */
39263cfc657SVladimir Oltean 	u32			needs_standalone_vlan_filtering:1;
39363cfc657SVladimir Oltean 
39463cfc657SVladimir Oltean 	/* Pass .port_vlan_add and .port_vlan_del to drivers even for bridges
39563cfc657SVladimir Oltean 	 * that have vlan_filtering=0. All drivers should ideally set this (and
39663cfc657SVladimir Oltean 	 * then the option would get removed), but it is unknown whether this
3977787ff77SVladimir Oltean 	 * would break things or not.
3987787ff77SVladimir Oltean 	 */
39963cfc657SVladimir Oltean 	u32			configure_vlan_while_not_filtering:1;
40063cfc657SVladimir Oltean 
40163cfc657SVladimir Oltean 	/* If the switch driver always programs the CPU port as egress tagged
40263cfc657SVladimir Oltean 	 * despite the VLAN configuration indicating otherwise, then setting
40363cfc657SVladimir Oltean 	 * @untag_bridge_pvid will force the DSA receive path to pop the
40463cfc657SVladimir Oltean 	 * bridge's default_pvid VLAN tagged frames to offer a consistent
40563cfc657SVladimir Oltean 	 * behavior between a vlan_filtering=0 and vlan_filtering=1 bridge
4067787ff77SVladimir Oltean 	 * device.
4077787ff77SVladimir Oltean 	 */
40863cfc657SVladimir Oltean 	u32			untag_bridge_pvid:1;
40963cfc657SVladimir Oltean 
4107787ff77SVladimir Oltean 	/* Let DSA manage the FDB entries towards the
4117787ff77SVladimir Oltean 	 * CPU, based on the software bridge database.
4127787ff77SVladimir Oltean 	 */
41363cfc657SVladimir Oltean 	u32			assisted_learning_on_cpu_port:1;
41463cfc657SVladimir Oltean 
41563cfc657SVladimir Oltean 	/* In case vlan_filtering_is_global is set, the VLAN awareness state
41663cfc657SVladimir Oltean 	 * should be retrieved from here and not from the per-port settings.
4177787ff77SVladimir Oltean 	 */
41863cfc657SVladimir Oltean 	u32			vlan_filtering:1;
41963cfc657SVladimir Oltean 
42063cfc657SVladimir Oltean 	/* For switches that only have the MRU configurable. To ensure the
42163cfc657SVladimir Oltean 	 * configured MTU is not exceeded, normalization of MRU on all bridged
42263cfc657SVladimir Oltean 	 * interfaces is needed.
4237787ff77SVladimir Oltean 	 */
42463cfc657SVladimir Oltean 	u32			mtu_enforcement_ingress:1;
4257787ff77SVladimir Oltean 
426c2693363SVladimir Oltean 	/* Drivers that isolate the FDBs of multiple bridges must set this
427c2693363SVladimir Oltean 	 * to true to receive the bridge as an argument in .port_fdb_{add,del}
428c2693363SVladimir Oltean 	 * and .port_mdb_{add,del}. Otherwise, the bridge.num will always be
429c2693363SVladimir Oltean 	 * passed as zero.
430c2693363SVladimir Oltean 	 */
431c2693363SVladimir Oltean 	u32			fdb_isolation:1;
432c2693363SVladimir Oltean 
433f515f192SVivien Didelot 	/* Listener for switch fabric events */
434f515f192SVivien Didelot 	struct notifier_block	nb;
435f515f192SVivien Didelot 
436c8f0b869SBen Hutchings 	/*
4377543a6d5SAndrew Lunn 	 * Give the switch driver somewhere to hang its private data
4387543a6d5SAndrew Lunn 	 * structure.
4397543a6d5SAndrew Lunn 	 */
4407543a6d5SAndrew Lunn 	void *priv;
4417543a6d5SAndrew Lunn 
442dc452a47SVladimir Oltean 	void *tagger_data;
443dc452a47SVladimir Oltean 
4447543a6d5SAndrew Lunn 	/*
445c8f0b869SBen Hutchings 	 * Configuration data for this switch.
446c8f0b869SBen Hutchings 	 */
447ff04955cSAndrew Lunn 	struct dsa_chip_data	*cd;
448c8f0b869SBen Hutchings 
449c8f0b869SBen Hutchings 	/*
4509d490b4eSVivien Didelot 	 * The switch operations.
451c8f0b869SBen Hutchings 	 */
452a82f67afSFlorian Fainelli 	const struct dsa_switch_ops	*ops;
453c8f0b869SBen Hutchings 
45466472fc0SAndrew Lunn 	/*
455c8f0b869SBen Hutchings 	 * Slave mii_bus and devices for the individual ports.
456c8f0b869SBen Hutchings 	 */
4570d8bcdd3SFlorian Fainelli 	u32			phys_mii_mask;
458c8f0b869SBen Hutchings 	struct mii_bus		*slave_mii_bus;
459a0c02161SVivien Didelot 
4600f3da6afSVivien Didelot 	/* Ageing Time limits in msecs */
4610f3da6afSVivien Didelot 	unsigned int ageing_time_min;
4620f3da6afSVivien Didelot 	unsigned int ageing_time_max;
4630f3da6afSVivien Didelot 
464d7b1fd52SVladimir Oltean 	/* Storage for drivers using tag_8021q */
465d7b1fd52SVladimir Oltean 	struct dsa_8021q_context *tag_8021q_ctx;
466d7b1fd52SVladimir Oltean 
46796567d5dSAndrew Lunn 	/* devlink used to represent this switch device */
46896567d5dSAndrew Lunn 	struct devlink		*devlink;
46996567d5dSAndrew Lunn 
47055199df6SFlorian Fainelli 	/* Number of switch port queues */
47155199df6SFlorian Fainelli 	unsigned int		num_tx_queues;
47255199df6SFlorian Fainelli 
473058102a6STobias Waldekranz 	/* Drivers that benefit from having an ID associated with each
474058102a6STobias Waldekranz 	 * offloaded LAG should set this to the maximum number of
475058102a6STobias Waldekranz 	 * supported IDs. DSA will then maintain a mapping of _at
476058102a6STobias Waldekranz 	 * least_ these many IDs, accessible to drivers via
477058102a6STobias Waldekranz 	 * dsa_lag_id().
478058102a6STobias Waldekranz 	 */
479058102a6STobias Waldekranz 	unsigned int		num_lag_ids;
480058102a6STobias Waldekranz 
481947c8746SVladimir Oltean 	/* Drivers that support bridge forwarding offload or FDB isolation
482947c8746SVladimir Oltean 	 * should set this to the maximum number of bridges spanning the same
483947c8746SVladimir Oltean 	 * switch tree (or all trees, in the case of cross-tree bridging
484947c8746SVladimir Oltean 	 * support) that can be offloaded.
485123abc06SVladimir Oltean 	 */
486947c8746SVladimir Oltean 	unsigned int		max_num_bridges;
487123abc06SVladimir Oltean 
488258030acSVladimir Oltean 	unsigned int		num_ports;
489c8f0b869SBen Hutchings };
490c8f0b869SBen Hutchings 
dsa_to_port(struct dsa_switch * ds,int p)49168bb8ea8SVivien Didelot static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p)
492c38c5a66SVivien Didelot {
493b96ddf25SVivien Didelot 	struct dsa_switch_tree *dst = ds->dst;
494d607525bSVivien Didelot 	struct dsa_port *dp;
495b96ddf25SVivien Didelot 
496b96ddf25SVivien Didelot 	list_for_each_entry(dp, &dst->ports, list)
497b96ddf25SVivien Didelot 		if (dp->ds == ds && dp->index == p)
498b96ddf25SVivien Didelot 			return dp;
499d607525bSVivien Didelot 
500d607525bSVivien Didelot 	return NULL;
501c38c5a66SVivien Didelot }
502c38c5a66SVivien Didelot 
dsa_port_is_dsa(struct dsa_port * port)503a8986681SVladimir Oltean static inline bool dsa_port_is_dsa(struct dsa_port *port)
504a8986681SVladimir Oltean {
505a8986681SVladimir Oltean 	return port->type == DSA_PORT_TYPE_DSA;
506a8986681SVladimir Oltean }
507a8986681SVladimir Oltean 
dsa_port_is_cpu(struct dsa_port * port)508a8986681SVladimir Oltean static inline bool dsa_port_is_cpu(struct dsa_port *port)
509a8986681SVladimir Oltean {
510a8986681SVladimir Oltean 	return port->type == DSA_PORT_TYPE_CPU;
511a8986681SVladimir Oltean }
512a8986681SVladimir Oltean 
dsa_port_is_user(struct dsa_port * dp)513a8986681SVladimir Oltean static inline bool dsa_port_is_user(struct dsa_port *dp)
514a8986681SVladimir Oltean {
515a8986681SVladimir Oltean 	return dp->type == DSA_PORT_TYPE_USER;
516a8986681SVladimir Oltean }
517a8986681SVladimir Oltean 
dsa_port_is_unused(struct dsa_port * dp)518a57d8c21SVladimir Oltean static inline bool dsa_port_is_unused(struct dsa_port *dp)
519a57d8c21SVladimir Oltean {
520a57d8c21SVladimir Oltean 	return dp->type == DSA_PORT_TYPE_UNUSED;
521a57d8c21SVladimir Oltean }
522a57d8c21SVladimir Oltean 
dsa_port_master_is_operational(struct dsa_port * dp)523295ab96fSVladimir Oltean static inline bool dsa_port_master_is_operational(struct dsa_port *dp)
524295ab96fSVladimir Oltean {
525295ab96fSVladimir Oltean 	return dsa_port_is_cpu(dp) && dp->master_admin_up &&
526295ab96fSVladimir Oltean 	       dp->master_oper_up;
527295ab96fSVladimir Oltean }
528295ab96fSVladimir Oltean 
dsa_is_unused_port(struct dsa_switch * ds,int p)529bff7b688SVivien Didelot static inline bool dsa_is_unused_port(struct dsa_switch *ds, int p)
530bff7b688SVivien Didelot {
531c38c5a66SVivien Didelot 	return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_UNUSED;
532bff7b688SVivien Didelot }
533bff7b688SVivien Didelot 
dsa_is_cpu_port(struct dsa_switch * ds,int p)534c8f0b869SBen Hutchings static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
535c8f0b869SBen Hutchings {
536c38c5a66SVivien Didelot 	return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_CPU;
537c8f0b869SBen Hutchings }
538c8f0b869SBen Hutchings 
dsa_is_dsa_port(struct dsa_switch * ds,int p)53960045cbfSAndrew Lunn static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p)
54060045cbfSAndrew Lunn {
541c38c5a66SVivien Didelot 	return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_DSA;
54260045cbfSAndrew Lunn }
54360045cbfSAndrew Lunn 
dsa_is_user_port(struct dsa_switch * ds,int p)5442b3e9891SVivien Didelot static inline bool dsa_is_user_port(struct dsa_switch *ds, int p)
5456cd456f3SVivien Didelot {
546c38c5a66SVivien Didelot 	return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_USER;
5476cd456f3SVivien Didelot }
5486cd456f3SVivien Didelot 
54982b31898SVladimir Oltean #define dsa_tree_for_each_user_port(_dp, _dst) \
55082b31898SVladimir Oltean 	list_for_each_entry((_dp), &(_dst)->ports, list) \
55182b31898SVladimir Oltean 		if (dsa_port_is_user((_dp)))
55282b31898SVladimir Oltean 
55395f510d0SVladimir Oltean #define dsa_tree_for_each_user_port_continue_reverse(_dp, _dst) \
55495f510d0SVladimir Oltean 	list_for_each_entry_continue_reverse((_dp), &(_dst)->ports, list) \
55595f510d0SVladimir Oltean 		if (dsa_port_is_user((_dp)))
55695f510d0SVladimir Oltean 
5575dc760d1SVladimir Oltean #define dsa_tree_for_each_cpu_port(_dp, _dst) \
5585dc760d1SVladimir Oltean 	list_for_each_entry((_dp), &(_dst)->ports, list) \
5595dc760d1SVladimir Oltean 		if (dsa_port_is_cpu((_dp)))
5605dc760d1SVladimir Oltean 
56182b31898SVladimir Oltean #define dsa_switch_for_each_port(_dp, _ds) \
56282b31898SVladimir Oltean 	list_for_each_entry((_dp), &(_ds)->dst->ports, list) \
56382b31898SVladimir Oltean 		if ((_dp)->ds == (_ds))
56482b31898SVladimir Oltean 
56582b31898SVladimir Oltean #define dsa_switch_for_each_port_safe(_dp, _next, _ds) \
56682b31898SVladimir Oltean 	list_for_each_entry_safe((_dp), (_next), &(_ds)->dst->ports, list) \
56782b31898SVladimir Oltean 		if ((_dp)->ds == (_ds))
56882b31898SVladimir Oltean 
56982b31898SVladimir Oltean #define dsa_switch_for_each_port_continue_reverse(_dp, _ds) \
57082b31898SVladimir Oltean 	list_for_each_entry_continue_reverse((_dp), &(_ds)->dst->ports, list) \
57182b31898SVladimir Oltean 		if ((_dp)->ds == (_ds))
57282b31898SVladimir Oltean 
57382b31898SVladimir Oltean #define dsa_switch_for_each_available_port(_dp, _ds) \
57482b31898SVladimir Oltean 	dsa_switch_for_each_port((_dp), (_ds)) \
57582b31898SVladimir Oltean 		if (!dsa_port_is_unused((_dp)))
57682b31898SVladimir Oltean 
57782b31898SVladimir Oltean #define dsa_switch_for_each_user_port(_dp, _ds) \
57882b31898SVladimir Oltean 	dsa_switch_for_each_port((_dp), (_ds)) \
57982b31898SVladimir Oltean 		if (dsa_port_is_user((_dp)))
58082b31898SVladimir Oltean 
58182b31898SVladimir Oltean #define dsa_switch_for_each_cpu_port(_dp, _ds) \
58282b31898SVladimir Oltean 	dsa_switch_for_each_port((_dp), (_ds)) \
58382b31898SVladimir Oltean 		if (dsa_port_is_cpu((_dp)))
58482b31898SVladimir Oltean 
585bacf93b0SVladimir Oltean #define dsa_switch_for_each_cpu_port_continue_reverse(_dp, _ds) \
586bacf93b0SVladimir Oltean 	dsa_switch_for_each_port_continue_reverse((_dp), (_ds)) \
587bacf93b0SVladimir Oltean 		if (dsa_port_is_cpu((_dp)))
588bacf93b0SVladimir Oltean 
dsa_user_ports(struct dsa_switch * ds)58902bc6e54SVivien Didelot static inline u32 dsa_user_ports(struct dsa_switch *ds)
59002bc6e54SVivien Didelot {
591d0004a02SVladimir Oltean 	struct dsa_port *dp;
592c38c5a66SVivien Didelot 	u32 mask = 0;
59302bc6e54SVivien Didelot 
594d0004a02SVladimir Oltean 	dsa_switch_for_each_user_port(dp, ds)
595d0004a02SVladimir Oltean 		mask |= BIT(dp->index);
596c38c5a66SVivien Didelot 
597c38c5a66SVivien Didelot 	return mask;
598c8652c83SVivien Didelot }
599c8652c83SVivien Didelot 
dsa_cpu_ports(struct dsa_switch * ds)600465c3de4SVladimir Oltean static inline u32 dsa_cpu_ports(struct dsa_switch *ds)
601465c3de4SVladimir Oltean {
602465c3de4SVladimir Oltean 	struct dsa_port *cpu_dp;
603465c3de4SVladimir Oltean 	u32 mask = 0;
604465c3de4SVladimir Oltean 
605465c3de4SVladimir Oltean 	dsa_switch_for_each_cpu_port(cpu_dp, ds)
606465c3de4SVladimir Oltean 		mask |= BIT(cpu_dp->index);
607465c3de4SVladimir Oltean 
608465c3de4SVladimir Oltean 	return mask;
609465c3de4SVladimir Oltean }
610465c3de4SVladimir Oltean 
611c5f51765SVivien Didelot /* Return the local port used to reach an arbitrary switch device */
dsa_routing_port(struct dsa_switch * ds,int device)612c5f51765SVivien Didelot static inline unsigned int dsa_routing_port(struct dsa_switch *ds, int device)
613c5f51765SVivien Didelot {
614c5f51765SVivien Didelot 	struct dsa_switch_tree *dst = ds->dst;
615c5f51765SVivien Didelot 	struct dsa_link *dl;
616c5f51765SVivien Didelot 
617c5f51765SVivien Didelot 	list_for_each_entry(dl, &dst->rtable, list)
618c5f51765SVivien Didelot 		if (dl->dp->ds == ds && dl->link_dp->ds->index == device)
619c5f51765SVivien Didelot 			return dl->dp->index;
620c5f51765SVivien Didelot 
621c5f51765SVivien Didelot 	return ds->num_ports;
622c5f51765SVivien Didelot }
623c5f51765SVivien Didelot 
6243b8fac5dSVivien Didelot /* Return the local port used to reach an arbitrary switch port */
dsa_towards_port(struct dsa_switch * ds,int device,int port)6253b8fac5dSVivien Didelot static inline unsigned int dsa_towards_port(struct dsa_switch *ds, int device,
6263b8fac5dSVivien Didelot 					    int port)
6273b8fac5dSVivien Didelot {
6283b8fac5dSVivien Didelot 	if (device == ds->index)
6293b8fac5dSVivien Didelot 		return port;
6303b8fac5dSVivien Didelot 	else
631c5f51765SVivien Didelot 		return dsa_routing_port(ds, device);
6323b8fac5dSVivien Didelot }
6333b8fac5dSVivien Didelot 
6343b8fac5dSVivien Didelot /* Return the local port used to reach the dedicated CPU port */
dsa_upstream_port(struct dsa_switch * ds,int port)63507073c79SVivien Didelot static inline unsigned int dsa_upstream_port(struct dsa_switch *ds, int port)
636c8f0b869SBen Hutchings {
63707073c79SVivien Didelot 	const struct dsa_port *dp = dsa_to_port(ds, port);
63807073c79SVivien Didelot 	const struct dsa_port *cpu_dp = dp->cpu_dp;
63907073c79SVivien Didelot 
64007073c79SVivien Didelot 	if (!cpu_dp)
64107073c79SVivien Didelot 		return port;
642c8f0b869SBen Hutchings 
6433b8fac5dSVivien Didelot 	return dsa_towards_port(ds, cpu_dp->ds->index, cpu_dp->index);
644c8f0b869SBen Hutchings }
645c8f0b869SBen Hutchings 
64663609c8fSVladimir Oltean /* Return true if this is the local port used to reach the CPU port */
dsa_is_upstream_port(struct dsa_switch * ds,int port)64763609c8fSVladimir Oltean static inline bool dsa_is_upstream_port(struct dsa_switch *ds, int port)
64863609c8fSVladimir Oltean {
64963609c8fSVladimir Oltean 	if (dsa_is_unused_port(ds, port))
65063609c8fSVladimir Oltean 		return false;
65163609c8fSVladimir Oltean 
65263609c8fSVladimir Oltean 	return port == dsa_upstream_port(ds, port);
65363609c8fSVladimir Oltean }
65463609c8fSVladimir Oltean 
655d352b20fSTobias Waldekranz /* Return true if this is a DSA port leading away from the CPU */
dsa_is_downstream_port(struct dsa_switch * ds,int port)656d352b20fSTobias Waldekranz static inline bool dsa_is_downstream_port(struct dsa_switch *ds, int port)
657d352b20fSTobias Waldekranz {
658d352b20fSTobias Waldekranz 	return dsa_is_dsa_port(ds, port) && !dsa_is_upstream_port(ds, port);
659d352b20fSTobias Waldekranz }
660d352b20fSTobias Waldekranz 
6617af4a361STobias Waldekranz /* Return the local port used to reach the CPU port */
dsa_switch_upstream_port(struct dsa_switch * ds)6627af4a361STobias Waldekranz static inline unsigned int dsa_switch_upstream_port(struct dsa_switch *ds)
6637af4a361STobias Waldekranz {
6647af4a361STobias Waldekranz 	struct dsa_port *dp;
6657af4a361STobias Waldekranz 
6667af4a361STobias Waldekranz 	dsa_switch_for_each_available_port(dp, ds) {
6677af4a361STobias Waldekranz 		return dsa_upstream_port(ds, dp->index);
6687af4a361STobias Waldekranz 	}
6697af4a361STobias Waldekranz 
6707af4a361STobias Waldekranz 	return ds->num_ports;
6717af4a361STobias Waldekranz }
6727af4a361STobias Waldekranz 
67363609c8fSVladimir Oltean /* Return true if @upstream_ds is an upstream switch of @downstream_ds, meaning
67463609c8fSVladimir Oltean  * that the routing port from @downstream_ds to @upstream_ds is also the port
67563609c8fSVladimir Oltean  * which @downstream_ds uses to reach its dedicated CPU.
67663609c8fSVladimir Oltean  */
dsa_switch_is_upstream_of(struct dsa_switch * upstream_ds,struct dsa_switch * downstream_ds)67763609c8fSVladimir Oltean static inline bool dsa_switch_is_upstream_of(struct dsa_switch *upstream_ds,
67863609c8fSVladimir Oltean 					     struct dsa_switch *downstream_ds)
67963609c8fSVladimir Oltean {
68063609c8fSVladimir Oltean 	int routing_port;
68163609c8fSVladimir Oltean 
68263609c8fSVladimir Oltean 	if (upstream_ds == downstream_ds)
68363609c8fSVladimir Oltean 		return true;
68463609c8fSVladimir Oltean 
68563609c8fSVladimir Oltean 	routing_port = dsa_routing_port(downstream_ds, upstream_ds->index);
68663609c8fSVladimir Oltean 
68763609c8fSVladimir Oltean 	return dsa_is_upstream_port(downstream_ds, routing_port);
68863609c8fSVladimir Oltean }
68963609c8fSVladimir Oltean 
dsa_port_is_vlan_filtering(const struct dsa_port * dp)690cf2d45f5SVladimir Oltean static inline bool dsa_port_is_vlan_filtering(const struct dsa_port *dp)
691cf2d45f5SVladimir Oltean {
692cf2d45f5SVladimir Oltean 	const struct dsa_switch *ds = dp->ds;
693cf2d45f5SVladimir Oltean 
694cf2d45f5SVladimir Oltean 	if (ds->vlan_filtering_is_global)
695cf2d45f5SVladimir Oltean 		return ds->vlan_filtering;
696cf2d45f5SVladimir Oltean 	else
697cf2d45f5SVladimir Oltean 		return dp->vlan_filtering;
698cf2d45f5SVladimir Oltean }
699cf2d45f5SVladimir Oltean 
dsa_port_lag_id_get(struct dsa_port * dp)700dedd6a00SVladimir Oltean static inline unsigned int dsa_port_lag_id_get(struct dsa_port *dp)
701dedd6a00SVladimir Oltean {
702dedd6a00SVladimir Oltean 	return dp->lag ? dp->lag->id : 0;
703dedd6a00SVladimir Oltean }
704dedd6a00SVladimir Oltean 
dsa_port_lag_dev_get(struct dsa_port * dp)705dedd6a00SVladimir Oltean static inline struct net_device *dsa_port_lag_dev_get(struct dsa_port *dp)
706dedd6a00SVladimir Oltean {
707dedd6a00SVladimir Oltean 	return dp->lag ? dp->lag->dev : NULL;
708dedd6a00SVladimir Oltean }
709dedd6a00SVladimir Oltean 
dsa_port_offloads_lag(struct dsa_port * dp,const struct dsa_lag * lag)710dedd6a00SVladimir Oltean static inline bool dsa_port_offloads_lag(struct dsa_port *dp,
711dedd6a00SVladimir Oltean 					 const struct dsa_lag *lag)
712dedd6a00SVladimir Oltean {
713dedd6a00SVladimir Oltean 	return dsa_port_lag_dev_get(dp) == lag->dev;
714dedd6a00SVladimir Oltean }
715dedd6a00SVladimir Oltean 
dsa_port_to_master(const struct dsa_port * dp)7168f6a19c0SVladimir Oltean static inline struct net_device *dsa_port_to_master(const struct dsa_port *dp)
7178f6a19c0SVladimir Oltean {
718acc43b7bSVladimir Oltean 	if (dp->cpu_port_in_lag)
719acc43b7bSVladimir Oltean 		return dsa_port_lag_dev_get(dp->cpu_dp);
720acc43b7bSVladimir Oltean 
7218f6a19c0SVladimir Oltean 	return dp->cpu_dp->master;
7228f6a19c0SVladimir Oltean }
7238f6a19c0SVladimir Oltean 
724cc76ce9eSTobias Waldekranz static inline
dsa_port_to_bridge_port(const struct dsa_port * dp)725cc76ce9eSTobias Waldekranz struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp)
726cc76ce9eSTobias Waldekranz {
727d3eed0e5SVladimir Oltean 	if (!dp->bridge)
728cc76ce9eSTobias Waldekranz 		return NULL;
729cc76ce9eSTobias Waldekranz 
730dedd6a00SVladimir Oltean 	if (dp->lag)
731dedd6a00SVladimir Oltean 		return dp->lag->dev;
732cc76ce9eSTobias Waldekranz 	else if (dp->hsr_dev)
733cc76ce9eSTobias Waldekranz 		return dp->hsr_dev;
734cc76ce9eSTobias Waldekranz 
735cc76ce9eSTobias Waldekranz 	return dp->slave;
736cc76ce9eSTobias Waldekranz }
737cc76ce9eSTobias Waldekranz 
73836cbf39bSVladimir Oltean static inline struct net_device *
dsa_port_bridge_dev_get(const struct dsa_port * dp)73936cbf39bSVladimir Oltean dsa_port_bridge_dev_get(const struct dsa_port *dp)
74036cbf39bSVladimir Oltean {
741d3eed0e5SVladimir Oltean 	return dp->bridge ? dp->bridge->dev : NULL;
74236cbf39bSVladimir Oltean }
74336cbf39bSVladimir Oltean 
dsa_port_bridge_num_get(struct dsa_port * dp)74436cbf39bSVladimir Oltean static inline unsigned int dsa_port_bridge_num_get(struct dsa_port *dp)
74536cbf39bSVladimir Oltean {
746d3eed0e5SVladimir Oltean 	return dp->bridge ? dp->bridge->num : 0;
74736cbf39bSVladimir Oltean }
74836cbf39bSVladimir Oltean 
dsa_port_bridge_same(const struct dsa_port * a,const struct dsa_port * b)74936cbf39bSVladimir Oltean static inline bool dsa_port_bridge_same(const struct dsa_port *a,
75036cbf39bSVladimir Oltean 					const struct dsa_port *b)
75136cbf39bSVladimir Oltean {
75236cbf39bSVladimir Oltean 	struct net_device *br_a = dsa_port_bridge_dev_get(a);
75336cbf39bSVladimir Oltean 	struct net_device *br_b = dsa_port_bridge_dev_get(b);
75436cbf39bSVladimir Oltean 
75536cbf39bSVladimir Oltean 	/* Standalone ports are not in the same bridge with one another */
75636cbf39bSVladimir Oltean 	return (!br_a || !br_b) ? false : (br_a == br_b);
75736cbf39bSVladimir Oltean }
75836cbf39bSVladimir Oltean 
dsa_port_offloads_bridge_port(struct dsa_port * dp,const struct net_device * dev)7596a43cba3SVladimir Oltean static inline bool dsa_port_offloads_bridge_port(struct dsa_port *dp,
7606a43cba3SVladimir Oltean 						 const struct net_device *dev)
7616a43cba3SVladimir Oltean {
7626a43cba3SVladimir Oltean 	return dsa_port_to_bridge_port(dp) == dev;
7636a43cba3SVladimir Oltean }
7646a43cba3SVladimir Oltean 
7656a43cba3SVladimir Oltean static inline bool
dsa_port_offloads_bridge_dev(struct dsa_port * dp,const struct net_device * bridge_dev)7666a43cba3SVladimir Oltean dsa_port_offloads_bridge_dev(struct dsa_port *dp,
7676a43cba3SVladimir Oltean 			     const struct net_device *bridge_dev)
7686a43cba3SVladimir Oltean {
7696a43cba3SVladimir Oltean 	/* DSA ports connected to a bridge, and event was emitted
7706a43cba3SVladimir Oltean 	 * for the bridge.
7716a43cba3SVladimir Oltean 	 */
7726a43cba3SVladimir Oltean 	return dsa_port_bridge_dev_get(dp) == bridge_dev;
7736a43cba3SVladimir Oltean }
7746a43cba3SVladimir Oltean 
dsa_port_offloads_bridge(struct dsa_port * dp,const struct dsa_bridge * bridge)775d3eed0e5SVladimir Oltean static inline bool dsa_port_offloads_bridge(struct dsa_port *dp,
776d3eed0e5SVladimir Oltean 					    const struct dsa_bridge *bridge)
777d3eed0e5SVladimir Oltean {
778d3eed0e5SVladimir Oltean 	return dsa_port_bridge_dev_get(dp) == bridge->dev;
779d3eed0e5SVladimir Oltean }
780d3eed0e5SVladimir Oltean 
7816a43cba3SVladimir Oltean /* Returns true if any port of this tree offloads the given net_device */
dsa_tree_offloads_bridge_port(struct dsa_switch_tree * dst,const struct net_device * dev)7826a43cba3SVladimir Oltean static inline bool dsa_tree_offloads_bridge_port(struct dsa_switch_tree *dst,
7836a43cba3SVladimir Oltean 						 const struct net_device *dev)
7846a43cba3SVladimir Oltean {
7856a43cba3SVladimir Oltean 	struct dsa_port *dp;
7866a43cba3SVladimir Oltean 
7876a43cba3SVladimir Oltean 	list_for_each_entry(dp, &dst->ports, list)
7886a43cba3SVladimir Oltean 		if (dsa_port_offloads_bridge_port(dp, dev))
7896a43cba3SVladimir Oltean 			return true;
7906a43cba3SVladimir Oltean 
7916a43cba3SVladimir Oltean 	return false;
7926a43cba3SVladimir Oltean }
7936a43cba3SVladimir Oltean 
7946a43cba3SVladimir Oltean /* Returns true if any port of this tree offloads the given bridge */
7956a43cba3SVladimir Oltean static inline bool
dsa_tree_offloads_bridge_dev(struct dsa_switch_tree * dst,const struct net_device * bridge_dev)7966a43cba3SVladimir Oltean dsa_tree_offloads_bridge_dev(struct dsa_switch_tree *dst,
7976a43cba3SVladimir Oltean 			     const struct net_device *bridge_dev)
7986a43cba3SVladimir Oltean {
7996a43cba3SVladimir Oltean 	struct dsa_port *dp;
8006a43cba3SVladimir Oltean 
8016a43cba3SVladimir Oltean 	list_for_each_entry(dp, &dst->ports, list)
8026a43cba3SVladimir Oltean 		if (dsa_port_offloads_bridge_dev(dp, bridge_dev))
8036a43cba3SVladimir Oltean 			return true;
8046a43cba3SVladimir Oltean 
8056a43cba3SVladimir Oltean 	return false;
8066a43cba3SVladimir Oltean }
8076a43cba3SVladimir Oltean 
dsa_port_tree_same(const struct dsa_port * a,const struct dsa_port * b)808acc43b7bSVladimir Oltean static inline bool dsa_port_tree_same(const struct dsa_port *a,
809acc43b7bSVladimir Oltean 				      const struct dsa_port *b)
810acc43b7bSVladimir Oltean {
811acc43b7bSVladimir Oltean 	return a->ds->dst == b->ds->dst;
812acc43b7bSVladimir Oltean }
813acc43b7bSVladimir Oltean 
8142bedde1aSArkadi Sharshevsky typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid,
8152bedde1aSArkadi Sharshevsky 			      bool is_static, void *data);
8169d490b4eSVivien Didelot struct dsa_switch_ops {
81753da0ebaSVladimir Oltean 	/*
81853da0ebaSVladimir Oltean 	 * Tagging protocol helpers called for the CPU ports and DSA links.
81953da0ebaSVladimir Oltean 	 * @get_tag_protocol retrieves the initial tagging protocol and is
82053da0ebaSVladimir Oltean 	 * mandatory. Switches which can operate using multiple tagging
82153da0ebaSVladimir Oltean 	 * protocols should implement @change_tag_protocol and report in
82253da0ebaSVladimir Oltean 	 * @get_tag_protocol the tagger in current use.
82353da0ebaSVladimir Oltean 	 */
8245ed4e3ebSFlorian Fainelli 	enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds,
8254d776482SFlorian Fainelli 						  int port,
8264d776482SFlorian Fainelli 						  enum dsa_tag_protocol mprot);
827bacf93b0SVladimir Oltean 	int	(*change_tag_protocol)(struct dsa_switch *ds,
82853da0ebaSVladimir Oltean 				       enum dsa_tag_protocol proto);
829dc452a47SVladimir Oltean 	/*
830dc452a47SVladimir Oltean 	 * Method for switch drivers to connect to the tagging protocol driver
831dc452a47SVladimir Oltean 	 * in current use. The switch driver can provide handlers for certain
832dc452a47SVladimir Oltean 	 * types of packets for switch management.
833dc452a47SVladimir Oltean 	 */
834dc452a47SVladimir Oltean 	int	(*connect_tag_protocol)(struct dsa_switch *ds,
835dc452a47SVladimir Oltean 					enum dsa_tag_protocol proto);
8367b314362SAndrew Lunn 
83795f510d0SVladimir Oltean 	int	(*port_change_master)(struct dsa_switch *ds, int port,
83895f510d0SVladimir Oltean 				      struct net_device *master,
83995f510d0SVladimir Oltean 				      struct netlink_ext_ack *extack);
84095f510d0SVladimir Oltean 
841fd292c18SVladimir Oltean 	/* Optional switch-wide initialization and destruction methods */
842c8f0b869SBen Hutchings 	int	(*setup)(struct dsa_switch *ds);
8435e3f847aSVladimir Oltean 	void	(*teardown)(struct dsa_switch *ds);
844fd292c18SVladimir Oltean 
845fd292c18SVladimir Oltean 	/* Per-port initialization and destruction methods. Mandatory if the
846fd292c18SVladimir Oltean 	 * driver registers devlink port regions, optional otherwise.
847fd292c18SVladimir Oltean 	 */
848fd292c18SVladimir Oltean 	int	(*port_setup)(struct dsa_switch *ds, int port);
849fd292c18SVladimir Oltean 	void	(*port_teardown)(struct dsa_switch *ds, int port);
850fd292c18SVladimir Oltean 
8516819563eSFlorian Fainelli 	u32	(*get_phy_flags)(struct dsa_switch *ds, int port);
852c8f0b869SBen Hutchings 
853c8f0b869SBen Hutchings 	/*
854c8f0b869SBen Hutchings 	 * Access to the switch's PHY registers.
855c8f0b869SBen Hutchings 	 */
856c8f0b869SBen Hutchings 	int	(*phy_read)(struct dsa_switch *ds, int port, int regnum);
857c8f0b869SBen Hutchings 	int	(*phy_write)(struct dsa_switch *ds, int port,
858c8f0b869SBen Hutchings 			     int regnum, u16 val);
859c8f0b869SBen Hutchings 
860c8f0b869SBen Hutchings 	/*
861ec9436baSFlorian Fainelli 	 * Link state adjustment (called from libphy)
862ec9436baSFlorian Fainelli 	 */
863ec9436baSFlorian Fainelli 	void	(*adjust_link)(struct dsa_switch *ds, int port,
864ec9436baSFlorian Fainelli 				struct phy_device *phydev);
865ce31b31cSFlorian Fainelli 	void	(*fixed_link_update)(struct dsa_switch *ds, int port,
866ce31b31cSFlorian Fainelli 				struct fixed_phy_status *st);
867ec9436baSFlorian Fainelli 
868ec9436baSFlorian Fainelli 	/*
86911d8f3ddSFlorian Fainelli 	 * PHYLINK integration
87011d8f3ddSFlorian Fainelli 	 */
871072eea6cSRussell King (Oracle) 	void	(*phylink_get_caps)(struct dsa_switch *ds, int port,
872072eea6cSRussell King (Oracle) 				    struct phylink_config *config);
873bde01822SRussell King (Oracle) 	struct phylink_pcs *(*phylink_mac_select_pcs)(struct dsa_switch *ds,
874bde01822SRussell King (Oracle) 						      int port,
875bde01822SRussell King (Oracle) 						      phy_interface_t iface);
876dd805cf3SRussell King (Oracle) 	int	(*phylink_mac_prepare)(struct dsa_switch *ds, int port,
877dd805cf3SRussell King (Oracle) 				       unsigned int mode,
878dd805cf3SRussell King (Oracle) 				       phy_interface_t interface);
87911d8f3ddSFlorian Fainelli 	void	(*phylink_mac_config)(struct dsa_switch *ds, int port,
88011d8f3ddSFlorian Fainelli 				      unsigned int mode,
88111d8f3ddSFlorian Fainelli 				      const struct phylink_link_state *state);
882dd805cf3SRussell King (Oracle) 	int	(*phylink_mac_finish)(struct dsa_switch *ds, int port,
883dd805cf3SRussell King (Oracle) 				      unsigned int mode,
884dd805cf3SRussell King (Oracle) 				      phy_interface_t interface);
88511d8f3ddSFlorian Fainelli 	void	(*phylink_mac_link_down)(struct dsa_switch *ds, int port,
88611d8f3ddSFlorian Fainelli 					 unsigned int mode,
88711d8f3ddSFlorian Fainelli 					 phy_interface_t interface);
88811d8f3ddSFlorian Fainelli 	void	(*phylink_mac_link_up)(struct dsa_switch *ds, int port,
88911d8f3ddSFlorian Fainelli 				       unsigned int mode,
89011d8f3ddSFlorian Fainelli 				       phy_interface_t interface,
8915b502a7bSRussell King 				       struct phy_device *phydev,
8925b502a7bSRussell King 				       int speed, int duplex,
8935b502a7bSRussell King 				       bool tx_pause, bool rx_pause);
89411d8f3ddSFlorian Fainelli 	void	(*phylink_fixed_state)(struct dsa_switch *ds, int port,
89511d8f3ddSFlorian Fainelli 				       struct phylink_link_state *state);
89611d8f3ddSFlorian Fainelli 	/*
897c2ec5f2eSOleksij Rempel 	 * Port statistics counters.
898c8f0b869SBen Hutchings 	 */
89989f09048SFlorian Fainelli 	void	(*get_strings)(struct dsa_switch *ds, int port,
90089f09048SFlorian Fainelli 			       u32 stringset, uint8_t *data);
901c8f0b869SBen Hutchings 	void	(*get_ethtool_stats)(struct dsa_switch *ds,
902c8f0b869SBen Hutchings 				     int port, uint64_t *data);
90389f09048SFlorian Fainelli 	int	(*get_sset_count)(struct dsa_switch *ds, int port, int sset);
904cf963573SFlorian Fainelli 	void	(*get_ethtool_phy_stats)(struct dsa_switch *ds,
905cf963573SFlorian Fainelli 					 int port, uint64_t *data);
906487d3855SAlvin Šipraga 	void	(*get_eth_phy_stats)(struct dsa_switch *ds, int port,
907487d3855SAlvin Šipraga 				     struct ethtool_eth_phy_stats *phy_stats);
908487d3855SAlvin Šipraga 	void	(*get_eth_mac_stats)(struct dsa_switch *ds, int port,
909487d3855SAlvin Šipraga 				     struct ethtool_eth_mac_stats *mac_stats);
910487d3855SAlvin Šipraga 	void	(*get_eth_ctrl_stats)(struct dsa_switch *ds, int port,
911487d3855SAlvin Šipraga 				      struct ethtool_eth_ctrl_stats *ctrl_stats);
91267f38b1cSClément Léger 	void	(*get_rmon_stats)(struct dsa_switch *ds, int port,
91367f38b1cSClément Léger 				  struct ethtool_rmon_stats *rmon_stats,
91467f38b1cSClément Léger 				  const struct ethtool_rmon_hist_range **ranges);
915c2ec5f2eSOleksij Rempel 	void	(*get_stats64)(struct dsa_switch *ds, int port,
916c2ec5f2eSOleksij Rempel 				   struct rtnl_link_stats64 *s);
9173d410403SOleksij Rempel 	void	(*get_pause_stats)(struct dsa_switch *ds, int port,
9183d410403SOleksij Rempel 				   struct ethtool_pause_stats *pause_stats);
919a71acad9SOleksij Rempel 	void	(*self_test)(struct dsa_switch *ds, int port,
920a71acad9SOleksij Rempel 			     struct ethtool_test *etest, u64 *data);
92124462549SFlorian Fainelli 
92224462549SFlorian Fainelli 	/*
92319e57c4eSFlorian Fainelli 	 * ethtool Wake-on-LAN
92419e57c4eSFlorian Fainelli 	 */
92519e57c4eSFlorian Fainelli 	void	(*get_wol)(struct dsa_switch *ds, int port,
92619e57c4eSFlorian Fainelli 			   struct ethtool_wolinfo *w);
92719e57c4eSFlorian Fainelli 	int	(*set_wol)(struct dsa_switch *ds, int port,
92819e57c4eSFlorian Fainelli 			   struct ethtool_wolinfo *w);
92919e57c4eSFlorian Fainelli 
93019e57c4eSFlorian Fainelli 	/*
9310336369dSBrandon Streiff 	 * ethtool timestamp info
9320336369dSBrandon Streiff 	 */
9330336369dSBrandon Streiff 	int	(*get_ts_info)(struct dsa_switch *ds, int port,
9340336369dSBrandon Streiff 			       struct ethtool_ts_info *ts);
9350336369dSBrandon Streiff 
9360336369dSBrandon Streiff 	/*
9375f6c2d49SVladimir Oltean 	 * ethtool MAC merge layer
9385f6c2d49SVladimir Oltean 	 */
9395f6c2d49SVladimir Oltean 	int	(*get_mm)(struct dsa_switch *ds, int port,
9405f6c2d49SVladimir Oltean 			  struct ethtool_mm_state *state);
9415f6c2d49SVladimir Oltean 	int	(*set_mm)(struct dsa_switch *ds, int port,
9425f6c2d49SVladimir Oltean 			  struct ethtool_mm_cfg *cfg,
9435f6c2d49SVladimir Oltean 			  struct netlink_ext_ack *extack);
9445f6c2d49SVladimir Oltean 	void	(*get_mm_stats)(struct dsa_switch *ds, int port,
9455f6c2d49SVladimir Oltean 				struct ethtool_mm_stats *stats);
9465f6c2d49SVladimir Oltean 
9475f6c2d49SVladimir Oltean 	/*
948d538eca8SVladimir Oltean 	 * DCB ops
949d538eca8SVladimir Oltean 	 */
950d538eca8SVladimir Oltean 	int	(*port_get_default_prio)(struct dsa_switch *ds, int port);
951d538eca8SVladimir Oltean 	int	(*port_set_default_prio)(struct dsa_switch *ds, int port,
952d538eca8SVladimir Oltean 					 u8 prio);
95347d75f78SVladimir Oltean 	int	(*port_get_dscp_prio)(struct dsa_switch *ds, int port, u8 dscp);
95447d75f78SVladimir Oltean 	int	(*port_add_dscp_prio)(struct dsa_switch *ds, int port, u8 dscp,
95547d75f78SVladimir Oltean 				      u8 prio);
95647d75f78SVladimir Oltean 	int	(*port_del_dscp_prio)(struct dsa_switch *ds, int port, u8 dscp,
95747d75f78SVladimir Oltean 				      u8 prio);
958d538eca8SVladimir Oltean 
959d538eca8SVladimir Oltean 	/*
96024462549SFlorian Fainelli 	 * Suspend and resume
96124462549SFlorian Fainelli 	 */
96224462549SFlorian Fainelli 	int	(*suspend)(struct dsa_switch *ds);
96324462549SFlorian Fainelli 	int	(*resume)(struct dsa_switch *ds);
964b2f2af21SFlorian Fainelli 
965b2f2af21SFlorian Fainelli 	/*
966b2f2af21SFlorian Fainelli 	 * Port enable/disable
967b2f2af21SFlorian Fainelli 	 */
968b2f2af21SFlorian Fainelli 	int	(*port_enable)(struct dsa_switch *ds, int port,
969b2f2af21SFlorian Fainelli 			       struct phy_device *phy);
97075104db0SAndrew Lunn 	void	(*port_disable)(struct dsa_switch *ds, int port);
9717905288fSFlorian Fainelli 
9727905288fSFlorian Fainelli 	/*
973b79d7c14SVladimir Oltean 	 * Compatibility between device trees defining multiple CPU ports and
974b79d7c14SVladimir Oltean 	 * drivers which are not OK to use by default the numerically smallest
975b79d7c14SVladimir Oltean 	 * CPU port of a switch for its local ports. This can return NULL,
976b79d7c14SVladimir Oltean 	 * meaning "don't know/don't care".
977b79d7c14SVladimir Oltean 	 */
978b79d7c14SVladimir Oltean 	struct dsa_port *(*preferred_default_local_cpu_port)(struct dsa_switch *ds);
979b79d7c14SVladimir Oltean 
980b79d7c14SVladimir Oltean 	/*
98108f50061SVivien Didelot 	 * Port's MAC EEE settings
9827905288fSFlorian Fainelli 	 */
98308f50061SVivien Didelot 	int	(*set_mac_eee)(struct dsa_switch *ds, int port,
9847905288fSFlorian Fainelli 			       struct ethtool_eee *e);
98508f50061SVivien Didelot 	int	(*get_mac_eee)(struct dsa_switch *ds, int port,
9867905288fSFlorian Fainelli 			       struct ethtool_eee *e);
98751579c3fSGuenter Roeck 
9886793abb4SGuenter Roeck 	/* EEPROM access */
9896793abb4SGuenter Roeck 	int	(*get_eeprom_len)(struct dsa_switch *ds);
9906793abb4SGuenter Roeck 	int	(*get_eeprom)(struct dsa_switch *ds,
9916793abb4SGuenter Roeck 			      struct ethtool_eeprom *eeprom, u8 *data);
9926793abb4SGuenter Roeck 	int	(*set_eeprom)(struct dsa_switch *ds,
9936793abb4SGuenter Roeck 			      struct ethtool_eeprom *eeprom, u8 *data);
9943d762a0fSGuenter Roeck 
9953d762a0fSGuenter Roeck 	/*
9963d762a0fSGuenter Roeck 	 * Register access.
9973d762a0fSGuenter Roeck 	 */
9983d762a0fSGuenter Roeck 	int	(*get_regs_len)(struct dsa_switch *ds, int port);
9993d762a0fSGuenter Roeck 	void	(*get_regs)(struct dsa_switch *ds, int port,
10003d762a0fSGuenter Roeck 			    struct ethtool_regs *regs, void *p);
1001b73adef6SFlorian Fainelli 
1002b73adef6SFlorian Fainelli 	/*
1003e358bef7SVladimir Oltean 	 * Upper device tracking.
1004e358bef7SVladimir Oltean 	 */
1005e358bef7SVladimir Oltean 	int	(*port_prechangeupper)(struct dsa_switch *ds, int port,
1006e358bef7SVladimir Oltean 				       struct netdev_notifier_changeupper_info *info);
1007e358bef7SVladimir Oltean 
1008e358bef7SVladimir Oltean 	/*
1009b73adef6SFlorian Fainelli 	 * Bridge integration
1010b73adef6SFlorian Fainelli 	 */
101134a79f63SVivien Didelot 	int	(*set_ageing_time)(struct dsa_switch *ds, unsigned int msecs);
101271327a4eSVivien Didelot 	int	(*port_bridge_join)(struct dsa_switch *ds, int port,
1013b079922bSVladimir Oltean 				    struct dsa_bridge bridge,
101406b9cce4SVladimir Oltean 				    bool *tx_fwd_offload,
101506b9cce4SVladimir Oltean 				    struct netlink_ext_ack *extack);
1016f123f2fbSVivien Didelot 	void	(*port_bridge_leave)(struct dsa_switch *ds, int port,
1017d3eed0e5SVladimir Oltean 				     struct dsa_bridge bridge);
101843c44a9fSVivien Didelot 	void	(*port_stp_state_set)(struct dsa_switch *ds, int port,
1019b73adef6SFlorian Fainelli 				      u8 state);
10207414af30STobias Waldekranz 	int	(*port_mst_state_set)(struct dsa_switch *ds, int port,
10217414af30STobias Waldekranz 				      const struct switchdev_mst_state *state);
1022732f794cSVivien Didelot 	void	(*port_fast_age)(struct dsa_switch *ds, int port);
10237414af30STobias Waldekranz 	int	(*port_vlan_fast_age)(struct dsa_switch *ds, int port, u16 vid);
1024a8b659e7SVladimir Oltean 	int	(*port_pre_bridge_flags)(struct dsa_switch *ds, int port,
1025a8b659e7SVladimir Oltean 					 struct switchdev_brport_flags flags,
1026a8b659e7SVladimir Oltean 					 struct netlink_ext_ack *extack);
1027a8b659e7SVladimir Oltean 	int	(*port_bridge_flags)(struct dsa_switch *ds, int port,
1028a8b659e7SVladimir Oltean 				     struct switchdev_brport_flags flags,
1029a8b659e7SVladimir Oltean 				     struct netlink_ext_ack *extack);
103072c3b0c7SVladimir Oltean 	void	(*port_set_host_flood)(struct dsa_switch *ds, int port,
103172c3b0c7SVladimir Oltean 				       bool uc, bool mc);
10322a778e1bSVivien Didelot 
10332a778e1bSVivien Didelot 	/*
103411149536SVivien Didelot 	 * VLAN support
103511149536SVivien Didelot 	 */
1036fb2dabadSVivien Didelot 	int	(*port_vlan_filtering)(struct dsa_switch *ds, int port,
103789153ed6SVladimir Oltean 				       bool vlan_filtering,
103889153ed6SVladimir Oltean 				       struct netlink_ext_ack *extack);
10391958d581SVladimir Oltean 	int	(*port_vlan_add)(struct dsa_switch *ds, int port,
104031046a5fSVladimir Oltean 				 const struct switchdev_obj_port_vlan *vlan,
104131046a5fSVladimir Oltean 				 struct netlink_ext_ack *extack);
104276e398a6SVivien Didelot 	int	(*port_vlan_del)(struct dsa_switch *ds, int port,
104376e398a6SVivien Didelot 				 const struct switchdev_obj_port_vlan *vlan);
10448e6598a7STobias Waldekranz 	int	(*vlan_msti_set)(struct dsa_switch *ds, struct dsa_bridge bridge,
10458e6598a7STobias Waldekranz 				 const struct switchdev_vlan_msti *msti);
10468e6598a7STobias Waldekranz 
104711149536SVivien Didelot 	/*
10482a778e1bSVivien Didelot 	 * Forwarding database
10492a778e1bSVivien Didelot 	 */
10501b6dd556SArkadi Sharshevsky 	int	(*port_fdb_add)(struct dsa_switch *ds, int port,
1051c2693363SVladimir Oltean 				const unsigned char *addr, u16 vid,
1052c2693363SVladimir Oltean 				struct dsa_db db);
10532a778e1bSVivien Didelot 	int	(*port_fdb_del)(struct dsa_switch *ds, int port,
1054c2693363SVladimir Oltean 				const unsigned char *addr, u16 vid,
1055c2693363SVladimir Oltean 				struct dsa_db db);
1056ea70ba98SVivien Didelot 	int	(*port_fdb_dump)(struct dsa_switch *ds, int port,
10572bedde1aSArkadi Sharshevsky 				 dsa_fdb_dump_cb_t *cb, void *data);
1058e212fa7cSVladimir Oltean 	int	(*lag_fdb_add)(struct dsa_switch *ds, struct dsa_lag lag,
1059c2693363SVladimir Oltean 			       const unsigned char *addr, u16 vid,
1060c2693363SVladimir Oltean 			       struct dsa_db db);
1061e212fa7cSVladimir Oltean 	int	(*lag_fdb_del)(struct dsa_switch *ds, struct dsa_lag lag,
1062c2693363SVladimir Oltean 			       const unsigned char *addr, u16 vid,
1063c2693363SVladimir Oltean 			       struct dsa_db db);
10648df30255SVivien Didelot 
10658df30255SVivien Didelot 	/*
10668df30255SVivien Didelot 	 * Multicast database
10678df30255SVivien Didelot 	 */
1068a52b2da7SVladimir Oltean 	int	(*port_mdb_add)(struct dsa_switch *ds, int port,
1069c2693363SVladimir Oltean 				const struct switchdev_obj_port_mdb *mdb,
1070c2693363SVladimir Oltean 				struct dsa_db db);
10718df30255SVivien Didelot 	int	(*port_mdb_del)(struct dsa_switch *ds, int port,
1072c2693363SVladimir Oltean 				const struct switchdev_obj_port_mdb *mdb,
1073c2693363SVladimir Oltean 				struct dsa_db db);
1074bf9f2648SFlorian Fainelli 	/*
1075bf9f2648SFlorian Fainelli 	 * RXNFC
1076bf9f2648SFlorian Fainelli 	 */
1077bf9f2648SFlorian Fainelli 	int	(*get_rxnfc)(struct dsa_switch *ds, int port,
1078bf9f2648SFlorian Fainelli 			     struct ethtool_rxnfc *nfc, u32 *rule_locs);
1079bf9f2648SFlorian Fainelli 	int	(*set_rxnfc)(struct dsa_switch *ds, int port,
1080bf9f2648SFlorian Fainelli 			     struct ethtool_rxnfc *nfc);
1081f50f2127SFlorian Fainelli 
1082f50f2127SFlorian Fainelli 	/*
1083f50f2127SFlorian Fainelli 	 * TC integration
1084f50f2127SFlorian Fainelli 	 */
1085ed11bb1fSVladimir Oltean 	int	(*cls_flower_add)(struct dsa_switch *ds, int port,
1086ed11bb1fSVladimir Oltean 				  struct flow_cls_offload *cls, bool ingress);
1087ed11bb1fSVladimir Oltean 	int	(*cls_flower_del)(struct dsa_switch *ds, int port,
1088ed11bb1fSVladimir Oltean 				  struct flow_cls_offload *cls, bool ingress);
1089ed11bb1fSVladimir Oltean 	int	(*cls_flower_stats)(struct dsa_switch *ds, int port,
1090ed11bb1fSVladimir Oltean 				    struct flow_cls_offload *cls, bool ingress);
1091f50f2127SFlorian Fainelli 	int	(*port_mirror_add)(struct dsa_switch *ds, int port,
1092f50f2127SFlorian Fainelli 				   struct dsa_mall_mirror_tc_entry *mirror,
10930148bb50SVladimir Oltean 				   bool ingress, struct netlink_ext_ack *extack);
1094f50f2127SFlorian Fainelli 	void	(*port_mirror_del)(struct dsa_switch *ds, int port,
1095f50f2127SFlorian Fainelli 				   struct dsa_mall_mirror_tc_entry *mirror);
109634297176SVladimir Oltean 	int	(*port_policer_add)(struct dsa_switch *ds, int port,
109734297176SVladimir Oltean 				    struct dsa_mall_policer_tc_entry *policer);
109834297176SVladimir Oltean 	void	(*port_policer_del)(struct dsa_switch *ds, int port);
109947d23af2SVladimir Oltean 	int	(*port_setup_tc)(struct dsa_switch *ds, int port,
110047d23af2SVladimir Oltean 				 enum tc_setup_type type, void *type_data);
110140ef2c93SVivien Didelot 
110240ef2c93SVivien Didelot 	/*
110340ef2c93SVivien Didelot 	 * Cross-chip operations
110440ef2c93SVivien Didelot 	 */
1105f66a6a69SVladimir Oltean 	int	(*crosschip_bridge_join)(struct dsa_switch *ds, int tree_index,
1106f66a6a69SVladimir Oltean 					 int sw_index, int port,
110706b9cce4SVladimir Oltean 					 struct dsa_bridge bridge,
110806b9cce4SVladimir Oltean 					 struct netlink_ext_ack *extack);
1109f66a6a69SVladimir Oltean 	void	(*crosschip_bridge_leave)(struct dsa_switch *ds, int tree_index,
1110f66a6a69SVladimir Oltean 					  int sw_index, int port,
1111d3eed0e5SVladimir Oltean 					  struct dsa_bridge bridge);
1112058102a6STobias Waldekranz 	int	(*crosschip_lag_change)(struct dsa_switch *ds, int sw_index,
1113058102a6STobias Waldekranz 					int port);
1114058102a6STobias Waldekranz 	int	(*crosschip_lag_join)(struct dsa_switch *ds, int sw_index,
1115dedd6a00SVladimir Oltean 				      int port, struct dsa_lag lag,
11162e359b00SVladimir Oltean 				      struct netdev_lag_upper_info *info,
11172e359b00SVladimir Oltean 				      struct netlink_ext_ack *extack);
1118058102a6STobias Waldekranz 	int	(*crosschip_lag_leave)(struct dsa_switch *ds, int sw_index,
1119dedd6a00SVladimir Oltean 				       int port, struct dsa_lag lag);
11200336369dSBrandon Streiff 
11210336369dSBrandon Streiff 	/*
11220336369dSBrandon Streiff 	 * PTP functionality
11230336369dSBrandon Streiff 	 */
11240336369dSBrandon Streiff 	int	(*port_hwtstamp_get)(struct dsa_switch *ds, int port,
11250336369dSBrandon Streiff 				     struct ifreq *ifr);
11260336369dSBrandon Streiff 	int	(*port_hwtstamp_set)(struct dsa_switch *ds, int port,
11270336369dSBrandon Streiff 				     struct ifreq *ifr);
11285c5416f5SYangbo Lu 	void	(*port_txtstamp)(struct dsa_switch *ds, int port,
11295c5416f5SYangbo Lu 				 struct sk_buff *skb);
113090af1059SBrandon Streiff 	bool	(*port_rxtstamp)(struct dsa_switch *ds, int port,
113190af1059SBrandon Streiff 				 struct sk_buff *skb, unsigned int type);
113297a69a0dSVladimir Oltean 
11330f06b855SAndrew Lunn 	/* Devlink parameters, etc */
11346b297524SAndrew Lunn 	int	(*devlink_param_get)(struct dsa_switch *ds, u32 id,
11356b297524SAndrew Lunn 				     struct devlink_param_gset_ctx *ctx);
11366b297524SAndrew Lunn 	int	(*devlink_param_set)(struct dsa_switch *ds, u32 id,
11376b297524SAndrew Lunn 				     struct devlink_param_gset_ctx *ctx);
11380f06b855SAndrew Lunn 	int	(*devlink_info_get)(struct dsa_switch *ds,
11390f06b855SAndrew Lunn 				    struct devlink_info_req *req,
11400f06b855SAndrew Lunn 				    struct netlink_ext_ack *extack);
11412a6ef763SVladimir Oltean 	int	(*devlink_sb_pool_get)(struct dsa_switch *ds,
11422a6ef763SVladimir Oltean 				       unsigned int sb_index, u16 pool_index,
11432a6ef763SVladimir Oltean 				       struct devlink_sb_pool_info *pool_info);
11442a6ef763SVladimir Oltean 	int	(*devlink_sb_pool_set)(struct dsa_switch *ds, unsigned int sb_index,
11452a6ef763SVladimir Oltean 				       u16 pool_index, u32 size,
11462a6ef763SVladimir Oltean 				       enum devlink_sb_threshold_type threshold_type,
11472a6ef763SVladimir Oltean 				       struct netlink_ext_ack *extack);
11482a6ef763SVladimir Oltean 	int	(*devlink_sb_port_pool_get)(struct dsa_switch *ds, int port,
11492a6ef763SVladimir Oltean 					    unsigned int sb_index, u16 pool_index,
11502a6ef763SVladimir Oltean 					    u32 *p_threshold);
11512a6ef763SVladimir Oltean 	int	(*devlink_sb_port_pool_set)(struct dsa_switch *ds, int port,
11522a6ef763SVladimir Oltean 					    unsigned int sb_index, u16 pool_index,
11532a6ef763SVladimir Oltean 					    u32 threshold,
11542a6ef763SVladimir Oltean 					    struct netlink_ext_ack *extack);
11552a6ef763SVladimir Oltean 	int	(*devlink_sb_tc_pool_bind_get)(struct dsa_switch *ds, int port,
11562a6ef763SVladimir Oltean 					       unsigned int sb_index, u16 tc_index,
11572a6ef763SVladimir Oltean 					       enum devlink_sb_pool_type pool_type,
11582a6ef763SVladimir Oltean 					       u16 *p_pool_index, u32 *p_threshold);
11592a6ef763SVladimir Oltean 	int	(*devlink_sb_tc_pool_bind_set)(struct dsa_switch *ds, int port,
11602a6ef763SVladimir Oltean 					       unsigned int sb_index, u16 tc_index,
11612a6ef763SVladimir Oltean 					       enum devlink_sb_pool_type pool_type,
11622a6ef763SVladimir Oltean 					       u16 pool_index, u32 threshold,
11632a6ef763SVladimir Oltean 					       struct netlink_ext_ack *extack);
11642a6ef763SVladimir Oltean 	int	(*devlink_sb_occ_snapshot)(struct dsa_switch *ds,
11652a6ef763SVladimir Oltean 					   unsigned int sb_index);
11662a6ef763SVladimir Oltean 	int	(*devlink_sb_occ_max_clear)(struct dsa_switch *ds,
11672a6ef763SVladimir Oltean 					    unsigned int sb_index);
11682a6ef763SVladimir Oltean 	int	(*devlink_sb_occ_port_pool_get)(struct dsa_switch *ds, int port,
11692a6ef763SVladimir Oltean 						unsigned int sb_index, u16 pool_index,
11702a6ef763SVladimir Oltean 						u32 *p_cur, u32 *p_max);
11712a6ef763SVladimir Oltean 	int	(*devlink_sb_occ_tc_port_bind_get)(struct dsa_switch *ds, int port,
11722a6ef763SVladimir Oltean 						   unsigned int sb_index, u16 tc_index,
11732a6ef763SVladimir Oltean 						   enum devlink_sb_pool_type pool_type,
11742a6ef763SVladimir Oltean 						   u32 *p_cur, u32 *p_max);
1175bfcb8132SVladimir Oltean 
1176bfcb8132SVladimir Oltean 	/*
1177bfcb8132SVladimir Oltean 	 * MTU change functionality. Switches can also adjust their MRU through
1178bfcb8132SVladimir Oltean 	 * this method. By MTU, one understands the SDU (L2 payload) length.
1179bfcb8132SVladimir Oltean 	 * If the switch needs to account for the DSA tag on the CPU port, this
1180ab88d64aSRandy Dunlap 	 * method needs to do so privately.
1181bfcb8132SVladimir Oltean 	 */
1182bfcb8132SVladimir Oltean 	int	(*port_change_mtu)(struct dsa_switch *ds, int port,
1183bfcb8132SVladimir Oltean 				   int new_mtu);
1184bfcb8132SVladimir Oltean 	int	(*port_max_mtu)(struct dsa_switch *ds, int port);
1185058102a6STobias Waldekranz 
1186058102a6STobias Waldekranz 	/*
1187058102a6STobias Waldekranz 	 * LAG integration
1188058102a6STobias Waldekranz 	 */
1189058102a6STobias Waldekranz 	int	(*port_lag_change)(struct dsa_switch *ds, int port);
1190058102a6STobias Waldekranz 	int	(*port_lag_join)(struct dsa_switch *ds, int port,
1191dedd6a00SVladimir Oltean 				 struct dsa_lag lag,
11922e359b00SVladimir Oltean 				 struct netdev_lag_upper_info *info,
11932e359b00SVladimir Oltean 				 struct netlink_ext_ack *extack);
1194058102a6STobias Waldekranz 	int	(*port_lag_leave)(struct dsa_switch *ds, int port,
1195dedd6a00SVladimir Oltean 				  struct dsa_lag lag);
119618596f50SGeorge McCollister 
119718596f50SGeorge McCollister 	/*
119818596f50SGeorge McCollister 	 * HSR integration
119918596f50SGeorge McCollister 	 */
120018596f50SGeorge McCollister 	int	(*port_hsr_join)(struct dsa_switch *ds, int port,
120118596f50SGeorge McCollister 				 struct net_device *hsr);
120218596f50SGeorge McCollister 	int	(*port_hsr_leave)(struct dsa_switch *ds, int port,
120318596f50SGeorge McCollister 				  struct net_device *hsr);
1204c595c433SHoratiu Vultur 
1205c595c433SHoratiu Vultur 	/*
1206c595c433SHoratiu Vultur 	 * MRP integration
1207c595c433SHoratiu Vultur 	 */
1208c595c433SHoratiu Vultur 	int	(*port_mrp_add)(struct dsa_switch *ds, int port,
1209c595c433SHoratiu Vultur 				const struct switchdev_obj_mrp *mrp);
1210c595c433SHoratiu Vultur 	int	(*port_mrp_del)(struct dsa_switch *ds, int port,
1211c595c433SHoratiu Vultur 				const struct switchdev_obj_mrp *mrp);
1212c595c433SHoratiu Vultur 	int	(*port_mrp_add_ring_role)(struct dsa_switch *ds, int port,
1213c595c433SHoratiu Vultur 					  const struct switchdev_obj_ring_role_mrp *mrp);
1214c595c433SHoratiu Vultur 	int	(*port_mrp_del_ring_role)(struct dsa_switch *ds, int port,
1215c595c433SHoratiu Vultur 					  const struct switchdev_obj_ring_role_mrp *mrp);
12165da11eb4SVladimir Oltean 
12175da11eb4SVladimir Oltean 	/*
12185da11eb4SVladimir Oltean 	 * tag_8021q operations
12195da11eb4SVladimir Oltean 	 */
12205da11eb4SVladimir Oltean 	int	(*tag_8021q_vlan_add)(struct dsa_switch *ds, int port, u16 vid,
12215da11eb4SVladimir Oltean 				      u16 flags);
12225da11eb4SVladimir Oltean 	int	(*tag_8021q_vlan_del)(struct dsa_switch *ds, int port, u16 vid);
1223295ab96fSVladimir Oltean 
1224295ab96fSVladimir Oltean 	/*
1225295ab96fSVladimir Oltean 	 * DSA master tracking operations
1226295ab96fSVladimir Oltean 	 */
1227295ab96fSVladimir Oltean 	void	(*master_state_change)(struct dsa_switch *ds,
1228295ab96fSVladimir Oltean 				       const struct net_device *master,
1229295ab96fSVladimir Oltean 				       bool operational);
12306b297524SAndrew Lunn };
12316b297524SAndrew Lunn 
12326b297524SAndrew Lunn #define DSA_DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes)		\
12336b297524SAndrew Lunn 	DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes,		\
12346b297524SAndrew Lunn 			     dsa_devlink_param_get, dsa_devlink_param_set, NULL)
12356b297524SAndrew Lunn 
12366b297524SAndrew Lunn int dsa_devlink_param_get(struct devlink *dl, u32 id,
12376b297524SAndrew Lunn 			  struct devlink_param_gset_ctx *ctx);
12386b297524SAndrew Lunn int dsa_devlink_param_set(struct devlink *dl, u32 id,
12396b297524SAndrew Lunn 			  struct devlink_param_gset_ctx *ctx);
12406b297524SAndrew Lunn int dsa_devlink_params_register(struct dsa_switch *ds,
12416b297524SAndrew Lunn 				const struct devlink_param *params,
12426b297524SAndrew Lunn 				size_t params_count);
12436b297524SAndrew Lunn void dsa_devlink_params_unregister(struct dsa_switch *ds,
12446b297524SAndrew Lunn 				   const struct devlink_param *params,
12456b297524SAndrew Lunn 				   size_t params_count);
12465cd73fbdSAndrew Lunn int dsa_devlink_resource_register(struct dsa_switch *ds,
12475cd73fbdSAndrew Lunn 				  const char *resource_name,
12485cd73fbdSAndrew Lunn 				  u64 resource_size,
12495cd73fbdSAndrew Lunn 				  u64 resource_id,
12505cd73fbdSAndrew Lunn 				  u64 parent_resource_id,
12515cd73fbdSAndrew Lunn 				  const struct devlink_resource_size_params *size_params);
12525cd73fbdSAndrew Lunn 
12535cd73fbdSAndrew Lunn void dsa_devlink_resources_unregister(struct dsa_switch *ds);
12545cd73fbdSAndrew Lunn 
12555cd73fbdSAndrew Lunn void dsa_devlink_resource_occ_get_register(struct dsa_switch *ds,
12565cd73fbdSAndrew Lunn 					   u64 resource_id,
12575cd73fbdSAndrew Lunn 					   devlink_resource_occ_get_t *occ_get,
12585cd73fbdSAndrew Lunn 					   void *occ_get_priv);
12595cd73fbdSAndrew Lunn void dsa_devlink_resource_occ_get_unregister(struct dsa_switch *ds,
12605cd73fbdSAndrew Lunn 					     u64 resource_id);
126197c82c23SAndrew Lunn struct devlink_region *
126297c82c23SAndrew Lunn dsa_devlink_region_create(struct dsa_switch *ds,
126397c82c23SAndrew Lunn 			  const struct devlink_region_ops *ops,
126497c82c23SAndrew Lunn 			  u32 region_max_snapshots, u64 region_size);
126508156ba4SAndrew Lunn struct devlink_region *
126608156ba4SAndrew Lunn dsa_devlink_port_region_create(struct dsa_switch *ds,
126708156ba4SAndrew Lunn 			       int port,
126808156ba4SAndrew Lunn 			       const struct devlink_port_region_ops *ops,
126908156ba4SAndrew Lunn 			       u32 region_max_snapshots, u64 region_size);
127097c82c23SAndrew Lunn void dsa_devlink_region_destroy(struct devlink_region *region);
127197c82c23SAndrew Lunn 
1272e1eea811SVladimir Oltean struct dsa_port *dsa_port_from_netdev(struct net_device *netdev);
12735cd73fbdSAndrew Lunn 
12746b297524SAndrew Lunn struct dsa_devlink_priv {
12756b297524SAndrew Lunn 	struct dsa_switch *ds;
1276c8f0b869SBen Hutchings };
1277c8f0b869SBen Hutchings 
dsa_devlink_to_ds(struct devlink * dl)1278ccc3e6b0SAndrew Lunn static inline struct dsa_switch *dsa_devlink_to_ds(struct devlink *dl)
1279ccc3e6b0SAndrew Lunn {
1280ccc3e6b0SAndrew Lunn 	struct dsa_devlink_priv *dl_priv = devlink_priv(dl);
1281ccc3e6b0SAndrew Lunn 
1282ccc3e6b0SAndrew Lunn 	return dl_priv->ds;
1283ccc3e6b0SAndrew Lunn }
1284ccc3e6b0SAndrew Lunn 
12857d1e2a10SAndrew Lunn static inline
dsa_devlink_port_to_ds(struct devlink_port * port)12867d1e2a10SAndrew Lunn struct dsa_switch *dsa_devlink_port_to_ds(struct devlink_port *port)
12877d1e2a10SAndrew Lunn {
12887d1e2a10SAndrew Lunn 	struct devlink *dl = port->devlink;
12897d1e2a10SAndrew Lunn 	struct dsa_devlink_priv *dl_priv = devlink_priv(dl);
12907d1e2a10SAndrew Lunn 
12917d1e2a10SAndrew Lunn 	return dl_priv->ds;
12927d1e2a10SAndrew Lunn }
12937d1e2a10SAndrew Lunn 
dsa_devlink_port_to_port(struct devlink_port * port)12947d1e2a10SAndrew Lunn static inline int dsa_devlink_port_to_port(struct devlink_port *port)
12957d1e2a10SAndrew Lunn {
12967d1e2a10SAndrew Lunn 	return port->index;
12977d1e2a10SAndrew Lunn }
12987d1e2a10SAndrew Lunn 
1299ab3d408dSFlorian Fainelli struct dsa_switch_driver {
1300ab3d408dSFlorian Fainelli 	struct list_head	list;
1301a82f67afSFlorian Fainelli 	const struct dsa_switch_ops *ops;
1302ab3d408dSFlorian Fainelli };
1303ab3d408dSFlorian Fainelli 
13047e580490SVladimir Oltean bool dsa_fdb_present_in_other_db(struct dsa_switch *ds, int port,
13057e580490SVladimir Oltean 				 const unsigned char *addr, u16 vid,
13067e580490SVladimir Oltean 				 struct dsa_db db);
13077e580490SVladimir Oltean bool dsa_mdb_present_in_other_db(struct dsa_switch *ds, int port,
13087e580490SVladimir Oltean 				 const struct switchdev_obj_port_mdb *mdb,
13097e580490SVladimir Oltean 				 struct dsa_db db);
1310f9cef64fSVladimir Oltean 
131173a7ece8SVivien Didelot /* Keep inline for faster access in hot path */
netdev_uses_dsa(const struct net_device * dev)13129eb8eff0SVladimir Oltean static inline bool netdev_uses_dsa(const struct net_device *dev)
1313c6e970a0SAndrew Lunn {
1314c6e970a0SAndrew Lunn #if IS_ENABLED(CONFIG_NET_DSA)
1315717ffbfbSVivien Didelot 	return dev->dsa_ptr && dev->dsa_ptr->rcv;
1316c6e970a0SAndrew Lunn #endif
1317c6e970a0SAndrew Lunn 	return false;
1318c6e970a0SAndrew Lunn }
1319c6e970a0SAndrew Lunn 
13209790cf20SVladimir Oltean /* All DSA tags that push the EtherType to the right (basically all except tail
13219790cf20SVladimir Oltean  * tags, which don't break dissection) can be treated the same from the
13229790cf20SVladimir Oltean  * perspective of the flow dissector.
13239790cf20SVladimir Oltean  *
13249790cf20SVladimir Oltean  * We need to return:
13259790cf20SVladimir Oltean  *  - offset: the (B - A) difference between:
13269790cf20SVladimir Oltean  *    A. the position of the real EtherType and
13279790cf20SVladimir Oltean  *    B. the current skb->data (aka ETH_HLEN bytes into the frame, aka 2 bytes
13289790cf20SVladimir Oltean  *       after the normal EtherType was supposed to be)
13299790cf20SVladimir Oltean  *    The offset in bytes is exactly equal to the tagger overhead (and half of
13309790cf20SVladimir Oltean  *    that, in __be16 shorts).
13319790cf20SVladimir Oltean  *
13329790cf20SVladimir Oltean  *  - proto: the value of the real EtherType.
13339790cf20SVladimir Oltean  */
dsa_tag_generic_flow_dissect(const struct sk_buff * skb,__be16 * proto,int * offset)13349790cf20SVladimir Oltean static inline void dsa_tag_generic_flow_dissect(const struct sk_buff *skb,
13359790cf20SVladimir Oltean 						__be16 *proto, int *offset)
13369790cf20SVladimir Oltean {
13379790cf20SVladimir Oltean #if IS_ENABLED(CONFIG_NET_DSA)
13389790cf20SVladimir Oltean 	const struct dsa_device_ops *ops = skb->dev->dsa_ptr->tag_ops;
13394e500251SVladimir Oltean 	int tag_len = ops->needed_headroom;
13409790cf20SVladimir Oltean 
13419790cf20SVladimir Oltean 	*offset = tag_len;
13429790cf20SVladimir Oltean 	*proto = ((__be16 *)skb->data)[(tag_len / 2) - 1];
13439790cf20SVladimir Oltean #endif
13449790cf20SVladimir Oltean }
13459790cf20SVladimir Oltean 
134683c0afaeSAndrew Lunn void dsa_unregister_switch(struct dsa_switch *ds);
134723c9ee49SVivien Didelot int dsa_register_switch(struct dsa_switch *ds);
13480650bf52SVladimir Oltean void dsa_switch_shutdown(struct dsa_switch *ds);
13493b7bc1f0SVladimir Oltean struct dsa_switch *dsa_switch_find(int tree_index, int sw_index);
1350a2614140SVladimir Oltean void dsa_flush_workqueue(void);
1351ea825e70SFlorian Fainelli #ifdef CONFIG_PM_SLEEP
1352ea825e70SFlorian Fainelli int dsa_switch_suspend(struct dsa_switch *ds);
1353ea825e70SFlorian Fainelli int dsa_switch_resume(struct dsa_switch *ds);
1354ea825e70SFlorian Fainelli #else
dsa_switch_suspend(struct dsa_switch * ds)1355ea825e70SFlorian Fainelli static inline int dsa_switch_suspend(struct dsa_switch *ds)
1356ea825e70SFlorian Fainelli {
1357ea825e70SFlorian Fainelli 	return 0;
1358ea825e70SFlorian Fainelli }
dsa_switch_resume(struct dsa_switch * ds)1359ea825e70SFlorian Fainelli static inline int dsa_switch_resume(struct dsa_switch *ds)
1360ea825e70SFlorian Fainelli {
1361ea825e70SFlorian Fainelli 	return 0;
1362ea825e70SFlorian Fainelli }
1363ea825e70SFlorian Fainelli #endif /* CONFIG_PM_SLEEP */
1364ea825e70SFlorian Fainelli 
136560724d4bSFlorian Fainelli #if IS_ENABLED(CONFIG_NET_DSA)
1366a5e3c9baSVladimir Oltean bool dsa_slave_dev_check(const struct net_device *dev);
136760724d4bSFlorian Fainelli #else
dsa_slave_dev_check(const struct net_device * dev)1368a5e3c9baSVladimir Oltean static inline bool dsa_slave_dev_check(const struct net_device *dev)
1369a5e3c9baSVladimir Oltean {
1370a5e3c9baSVladimir Oltean 	return false;
1371a5e3c9baSVladimir Oltean }
137260724d4bSFlorian Fainelli #endif
137360724d4bSFlorian Fainelli 
137497a69a0dSVladimir Oltean netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, struct net_device *dev);
137511d8f3ddSFlorian Fainelli void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up);
1376cf963573SFlorian Fainelli 
137791da11f8SLennert Buytenhek #endif
1378