xref: /openbmc/linux/include/net/dsa.h (revision 7af4a361)
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 
25f50f2127SFlorian Fainelli struct tc_action;
264d56a29fSRussell King struct phy_device;
274d56a29fSRussell King struct fixed_phy_status;
2811d8f3ddSFlorian Fainelli struct phylink_link_state;
29f50f2127SFlorian Fainelli 
300b42f033SAndrew Lunn #define DSA_TAG_PROTO_NONE_VALUE		0
310b42f033SAndrew Lunn #define DSA_TAG_PROTO_BRCM_VALUE		1
320b42f033SAndrew Lunn #define DSA_TAG_PROTO_BRCM_PREPEND_VALUE	2
330b42f033SAndrew Lunn #define DSA_TAG_PROTO_DSA_VALUE			3
340b42f033SAndrew Lunn #define DSA_TAG_PROTO_EDSA_VALUE		4
350b42f033SAndrew Lunn #define DSA_TAG_PROTO_GSWIP_VALUE		5
360b42f033SAndrew Lunn #define DSA_TAG_PROTO_KSZ9477_VALUE		6
370b42f033SAndrew Lunn #define DSA_TAG_PROTO_KSZ9893_VALUE		7
380b42f033SAndrew Lunn #define DSA_TAG_PROTO_LAN9303_VALUE		8
390b42f033SAndrew Lunn #define DSA_TAG_PROTO_MTK_VALUE			9
400b42f033SAndrew Lunn #define DSA_TAG_PROTO_QCA_VALUE			10
410b42f033SAndrew Lunn #define DSA_TAG_PROTO_TRAILER_VALUE		11
42f9bbe447SVladimir Oltean #define DSA_TAG_PROTO_8021Q_VALUE		12
43227d07a0SVladimir Oltean #define DSA_TAG_PROTO_SJA1105_VALUE		13
44016e43a2STristram Ha #define DSA_TAG_PROTO_KSZ8795_VALUE		14
458dce89aaSVladimir Oltean #define DSA_TAG_PROTO_OCELOT_VALUE		15
4648fda74fSOleksij Rempel #define DSA_TAG_PROTO_AR9331_VALUE		16
47efd7fe68SLinus Walleij #define DSA_TAG_PROTO_RTL4_A_VALUE		17
4801ef09caSKurt Kanzenbach #define DSA_TAG_PROTO_HELLCREEK_VALUE		18
4954a52823SGeorge McCollister #define DSA_TAG_PROTO_XRS700X_VALUE		19
507c83a7c5SVladimir Oltean #define DSA_TAG_PROTO_OCELOT_8021Q_VALUE	20
517c4bb540SVladimir Oltean #define DSA_TAG_PROTO_SEVILLE_VALUE		21
52964dbf18SÁlvaro Fernández Rojas #define DSA_TAG_PROTO_BRCM_LEGACY_VALUE		22
534913b8ebSVladimir Oltean #define DSA_TAG_PROTO_SJA1110_VALUE		23
541521d5adSAlvin Šipraga #define DSA_TAG_PROTO_RTL8_4_VALUE		24
550b42f033SAndrew Lunn 
56ac7a04c3SFlorian Fainelli enum dsa_tag_protocol {
570b42f033SAndrew Lunn 	DSA_TAG_PROTO_NONE		= DSA_TAG_PROTO_NONE_VALUE,
580b42f033SAndrew Lunn 	DSA_TAG_PROTO_BRCM		= DSA_TAG_PROTO_BRCM_VALUE,
59964dbf18SÁlvaro Fernández Rojas 	DSA_TAG_PROTO_BRCM_LEGACY	= DSA_TAG_PROTO_BRCM_LEGACY_VALUE,
600b42f033SAndrew Lunn 	DSA_TAG_PROTO_BRCM_PREPEND	= DSA_TAG_PROTO_BRCM_PREPEND_VALUE,
610b42f033SAndrew Lunn 	DSA_TAG_PROTO_DSA		= DSA_TAG_PROTO_DSA_VALUE,
620b42f033SAndrew Lunn 	DSA_TAG_PROTO_EDSA		= DSA_TAG_PROTO_EDSA_VALUE,
630b42f033SAndrew Lunn 	DSA_TAG_PROTO_GSWIP		= DSA_TAG_PROTO_GSWIP_VALUE,
640b42f033SAndrew Lunn 	DSA_TAG_PROTO_KSZ9477		= DSA_TAG_PROTO_KSZ9477_VALUE,
650b42f033SAndrew Lunn 	DSA_TAG_PROTO_KSZ9893		= DSA_TAG_PROTO_KSZ9893_VALUE,
660b42f033SAndrew Lunn 	DSA_TAG_PROTO_LAN9303		= DSA_TAG_PROTO_LAN9303_VALUE,
670b42f033SAndrew Lunn 	DSA_TAG_PROTO_MTK		= DSA_TAG_PROTO_MTK_VALUE,
680b42f033SAndrew Lunn 	DSA_TAG_PROTO_QCA		= DSA_TAG_PROTO_QCA_VALUE,
690b42f033SAndrew Lunn 	DSA_TAG_PROTO_TRAILER		= DSA_TAG_PROTO_TRAILER_VALUE,
70f9bbe447SVladimir Oltean 	DSA_TAG_PROTO_8021Q		= DSA_TAG_PROTO_8021Q_VALUE,
71227d07a0SVladimir Oltean 	DSA_TAG_PROTO_SJA1105		= DSA_TAG_PROTO_SJA1105_VALUE,
72016e43a2STristram Ha 	DSA_TAG_PROTO_KSZ8795		= DSA_TAG_PROTO_KSZ8795_VALUE,
738dce89aaSVladimir Oltean 	DSA_TAG_PROTO_OCELOT		= DSA_TAG_PROTO_OCELOT_VALUE,
7448fda74fSOleksij Rempel 	DSA_TAG_PROTO_AR9331		= DSA_TAG_PROTO_AR9331_VALUE,
75efd7fe68SLinus Walleij 	DSA_TAG_PROTO_RTL4_A		= DSA_TAG_PROTO_RTL4_A_VALUE,
7601ef09caSKurt Kanzenbach 	DSA_TAG_PROTO_HELLCREEK		= DSA_TAG_PROTO_HELLCREEK_VALUE,
7754a52823SGeorge McCollister 	DSA_TAG_PROTO_XRS700X		= DSA_TAG_PROTO_XRS700X_VALUE,
787c83a7c5SVladimir Oltean 	DSA_TAG_PROTO_OCELOT_8021Q	= DSA_TAG_PROTO_OCELOT_8021Q_VALUE,
797c4bb540SVladimir Oltean 	DSA_TAG_PROTO_SEVILLE		= DSA_TAG_PROTO_SEVILLE_VALUE,
804913b8ebSVladimir Oltean 	DSA_TAG_PROTO_SJA1110		= DSA_TAG_PROTO_SJA1110_VALUE,
811521d5adSAlvin Šipraga 	DSA_TAG_PROTO_RTL8_4		= DSA_TAG_PROTO_RTL8_4_VALUE,
82ac7a04c3SFlorian Fainelli };
835037d532SFlorian Fainelli 
8490af1059SBrandon Streiff struct dsa_switch;
853e8a72d1SFlorian Fainelli 
8668277a2cSJohn Crispin struct dsa_device_ops {
8768277a2cSJohn Crispin 	struct sk_buff *(*xmit)(struct sk_buff *skb, struct net_device *dev);
8829a097b7SVladimir Oltean 	struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev);
892e8cb1b3SVladimir Oltean 	void (*flow_dissect)(const struct sk_buff *skb, __be16 *proto,
90598a9680SJohn Crispin 			     int *offset);
917f297314SVladimir Oltean 	int (*connect)(struct dsa_switch *ds);
927f297314SVladimir Oltean 	void (*disconnect)(struct dsa_switch *ds);
934e500251SVladimir Oltean 	unsigned int needed_headroom;
944e500251SVladimir Oltean 	unsigned int needed_tailroom;
95875138f8SAndrew Lunn 	const char *name;
96056eed2fSAndrew Lunn 	enum dsa_tag_protocol proto;
97c3975400SVladimir Oltean 	/* Some tagging protocols either mangle or shift the destination MAC
98c3975400SVladimir Oltean 	 * address, in which case the DSA master would drop packets on ingress
99c3975400SVladimir Oltean 	 * if what it understands out of the destination MAC address is not in
100c3975400SVladimir Oltean 	 * its RX filter.
101c3975400SVladimir Oltean 	 */
102c3975400SVladimir Oltean 	bool promisc_on_master;
10368277a2cSJohn Crispin };
10468277a2cSJohn Crispin 
1054cfab356SFlorian Fainelli /* This structure defines the control interfaces that are overlayed by the
1064cfab356SFlorian Fainelli  * DSA layer on top of the DSA CPU/management net_device instance. This is
1074cfab356SFlorian Fainelli  * used by the core net_device layer while calling various net_device_ops
1084cfab356SFlorian Fainelli  * function pointers.
1094cfab356SFlorian Fainelli  */
1104cfab356SFlorian Fainelli struct dsa_netdevice_ops {
111a7605370SArnd Bergmann 	int (*ndo_eth_ioctl)(struct net_device *dev, struct ifreq *ifr,
1124cfab356SFlorian Fainelli 			     int cmd);
1134cfab356SFlorian Fainelli };
1144cfab356SFlorian Fainelli 
1150b42f033SAndrew Lunn #define DSA_TAG_DRIVER_ALIAS "dsa_tag-"
1160b42f033SAndrew Lunn #define MODULE_ALIAS_DSA_TAG_DRIVER(__proto)				\
1170b42f033SAndrew Lunn 	MODULE_ALIAS(DSA_TAG_DRIVER_ALIAS __stringify(__proto##_VALUE))
1180b42f033SAndrew Lunn 
119cf50dcc2SBen Hutchings struct dsa_switch_tree {
12083c0afaeSAndrew Lunn 	struct list_head	list;
12183c0afaeSAndrew Lunn 
122b035c88cSVladimir Oltean 	/* List of switch ports */
123b035c88cSVladimir Oltean 	struct list_head ports;
124b035c88cSVladimir Oltean 
125f515f192SVivien Didelot 	/* Notifier chain for switch-wide events */
126f515f192SVivien Didelot 	struct raw_notifier_head	nh;
127f515f192SVivien Didelot 
12883c0afaeSAndrew Lunn 	/* Tree identifier */
12949463b7fSVivien Didelot 	unsigned int index;
13083c0afaeSAndrew Lunn 
13183c0afaeSAndrew Lunn 	/* Number of switches attached to this tree */
13283c0afaeSAndrew Lunn 	struct kref refcount;
13383c0afaeSAndrew Lunn 
134b035c88cSVladimir Oltean 	/* Maps offloaded LAG netdevs to a zero-based linear ID for
135b035c88cSVladimir Oltean 	 * drivers that need it.
136b035c88cSVladimir Oltean 	 */
137b035c88cSVladimir Oltean 	struct net_device **lags;
138b035c88cSVladimir Oltean 
139357f203bSVladimir Oltean 	/* Tagging protocol operations */
140357f203bSVladimir Oltean 	const struct dsa_device_ops *tag_ops;
141357f203bSVladimir Oltean 
142deff7107STobias Waldekranz 	/* Default tagging protocol preferred by the switches in this
143deff7107STobias Waldekranz 	 * tree.
144deff7107STobias Waldekranz 	 */
145deff7107STobias Waldekranz 	enum dsa_tag_protocol default_proto;
146deff7107STobias Waldekranz 
1474b026e82SVladimir Oltean 	/* Has this tree been applied to the hardware? */
1484b026e82SVladimir Oltean 	bool setup;
1494b026e82SVladimir Oltean 
150cf50dcc2SBen Hutchings 	/*
151cf50dcc2SBen Hutchings 	 * Configuration data for the platform device that owns
152cf50dcc2SBen Hutchings 	 * this dsa switch tree instance.
153cf50dcc2SBen Hutchings 	 */
154cf50dcc2SBen Hutchings 	struct dsa_platform_data	*pd;
155cf85d08fSLennert Buytenhek 
156c5f51765SVivien Didelot 	/* List of DSA links composing the routing table */
157c5f51765SVivien Didelot 	struct list_head rtable;
158058102a6STobias Waldekranz 
159b035c88cSVladimir Oltean 	/* Length of "lags" array */
160058102a6STobias Waldekranz 	unsigned int lags_len;
1615b22d366SVladimir Oltean 
1625b22d366SVladimir Oltean 	/* Track the largest switch index within a tree */
1635b22d366SVladimir Oltean 	unsigned int last_switch;
164cf50dcc2SBen Hutchings };
165cf50dcc2SBen Hutchings 
166058102a6STobias Waldekranz #define dsa_lags_foreach_id(_id, _dst)				\
167058102a6STobias Waldekranz 	for ((_id) = 0; (_id) < (_dst)->lags_len; (_id)++)	\
168058102a6STobias Waldekranz 		if ((_dst)->lags[(_id)])
169058102a6STobias Waldekranz 
170058102a6STobias Waldekranz #define dsa_lag_foreach_port(_dp, _dst, _lag)			\
171058102a6STobias Waldekranz 	list_for_each_entry((_dp), &(_dst)->ports, list)	\
172058102a6STobias Waldekranz 		if ((_dp)->lag_dev == (_lag))
173058102a6STobias Waldekranz 
17418596f50SGeorge McCollister #define dsa_hsr_foreach_port(_dp, _ds, _hsr)			\
17518596f50SGeorge McCollister 	list_for_each_entry((_dp), &(_ds)->dst->ports, list)	\
17618596f50SGeorge McCollister 		if ((_dp)->ds == (_ds) && (_dp)->hsr_dev == (_hsr))
17718596f50SGeorge McCollister 
178058102a6STobias Waldekranz static inline struct net_device *dsa_lag_dev(struct dsa_switch_tree *dst,
179058102a6STobias Waldekranz 					     unsigned int id)
180058102a6STobias Waldekranz {
181058102a6STobias Waldekranz 	return dst->lags[id];
182058102a6STobias Waldekranz }
183058102a6STobias Waldekranz 
184058102a6STobias Waldekranz static inline int dsa_lag_id(struct dsa_switch_tree *dst,
185058102a6STobias Waldekranz 			     struct net_device *lag)
186058102a6STobias Waldekranz {
187058102a6STobias Waldekranz 	unsigned int id;
188058102a6STobias Waldekranz 
189058102a6STobias Waldekranz 	dsa_lags_foreach_id(id, dst) {
190058102a6STobias Waldekranz 		if (dsa_lag_dev(dst, id) == lag)
191058102a6STobias Waldekranz 			return id;
192058102a6STobias Waldekranz 	}
193058102a6STobias Waldekranz 
194058102a6STobias Waldekranz 	return -ENODEV;
195058102a6STobias Waldekranz }
196058102a6STobias Waldekranz 
19734297176SVladimir Oltean /* TC matchall action types */
198f50f2127SFlorian Fainelli enum dsa_port_mall_action_type {
199f50f2127SFlorian Fainelli 	DSA_PORT_MALL_MIRROR,
20034297176SVladimir Oltean 	DSA_PORT_MALL_POLICER,
201f50f2127SFlorian Fainelli };
202f50f2127SFlorian Fainelli 
203f50f2127SFlorian Fainelli /* TC mirroring entry */
204f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry {
205f50f2127SFlorian Fainelli 	u8 to_local_port;
206f50f2127SFlorian Fainelli 	bool ingress;
207f50f2127SFlorian Fainelli };
208f50f2127SFlorian Fainelli 
20934297176SVladimir Oltean /* TC port policer entry */
21034297176SVladimir Oltean struct dsa_mall_policer_tc_entry {
2115f035af7SPo Liu 	u32 burst;
21234297176SVladimir Oltean 	u64 rate_bytes_per_sec;
21334297176SVladimir Oltean };
21434297176SVladimir Oltean 
215f50f2127SFlorian Fainelli /* TC matchall entry */
216f50f2127SFlorian Fainelli struct dsa_mall_tc_entry {
217f50f2127SFlorian Fainelli 	struct list_head list;
218f50f2127SFlorian Fainelli 	unsigned long cookie;
219f50f2127SFlorian Fainelli 	enum dsa_port_mall_action_type type;
220f50f2127SFlorian Fainelli 	union {
221f50f2127SFlorian Fainelli 		struct dsa_mall_mirror_tc_entry mirror;
22234297176SVladimir Oltean 		struct dsa_mall_policer_tc_entry policer;
223f50f2127SFlorian Fainelli 	};
224f50f2127SFlorian Fainelli };
225f50f2127SFlorian Fainelli 
226d3eed0e5SVladimir Oltean struct dsa_bridge {
227d3eed0e5SVladimir Oltean 	struct net_device *dev;
228d3eed0e5SVladimir Oltean 	unsigned int num;
229857fdd74SVladimir Oltean 	bool tx_fwd_offload;
230d3eed0e5SVladimir Oltean 	refcount_t refcount;
231d3eed0e5SVladimir Oltean };
232f50f2127SFlorian Fainelli 
233c8b09808SAndrew Lunn struct dsa_port {
234f8b8b1cdSVivien Didelot 	/* A CPU port is physically connected to a master device.
235f8b8b1cdSVivien Didelot 	 * A user port exposed to userspace has a slave device.
236f8b8b1cdSVivien Didelot 	 */
237f8b8b1cdSVivien Didelot 	union {
238f8b8b1cdSVivien Didelot 		struct net_device *master;
239f8b8b1cdSVivien Didelot 		struct net_device *slave;
240f8b8b1cdSVivien Didelot 	};
241f8b8b1cdSVivien Didelot 
242357f203bSVladimir Oltean 	/* Copy of the tagging protocol operations, for quicker access
243357f203bSVladimir Oltean 	 * in the data path. Valid only for the CPU ports.
244357f203bSVladimir Oltean 	 */
24515240248SVivien Didelot 	const struct dsa_device_ops *tag_ops;
24615240248SVivien Didelot 
2473e41f93bSVivien Didelot 	/* Copies for faster access in master receive hot path */
2483e41f93bSVivien Didelot 	struct dsa_switch_tree *dst;
24929a097b7SVladimir Oltean 	struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev);
2503e41f93bSVivien Didelot 
25106251258SVladimir Oltean 	struct dsa_switch	*ds;
25206251258SVladimir Oltean 
25306251258SVladimir Oltean 	unsigned int		index;
25406251258SVladimir Oltean 
255057cad2cSVivien Didelot 	enum {
256057cad2cSVivien Didelot 		DSA_PORT_TYPE_UNUSED = 0,
257057cad2cSVivien Didelot 		DSA_PORT_TYPE_CPU,
258057cad2cSVivien Didelot 		DSA_PORT_TYPE_DSA,
259057cad2cSVivien Didelot 		DSA_PORT_TYPE_USER,
260057cad2cSVivien Didelot 	} type;
261057cad2cSVivien Didelot 
26271e0bbdeSFlorian Fainelli 	const char		*name;
26368b2d4a8SVivien Didelot 	struct dsa_port		*cpu_dp;
26483216e39SMichael Walle 	u8			mac[ETH_ALEN];
265b08db33dSVladimir Oltean 
266b08db33dSVladimir Oltean 	u8			stp_state;
267b08db33dSVladimir Oltean 
2681b26d364SVladimir Oltean 	/* Warning: the following bit fields are not atomic, and updating them
2691b26d364SVladimir Oltean 	 * can only be done from code paths where concurrency is not possible
2701b26d364SVladimir Oltean 	 * (probe time or under rtnl_lock).
2711b26d364SVladimir Oltean 	 */
27263cfc657SVladimir Oltean 	u8			vlan_filtering:1;
27363cfc657SVladimir Oltean 
27463cfc657SVladimir Oltean 	/* Managed by DSA on user ports and by drivers on CPU and DSA ports */
27563cfc657SVladimir Oltean 	u8			learning:1;
27663cfc657SVladimir Oltean 
27763cfc657SVladimir Oltean 	u8			lag_tx_enabled:1;
27863cfc657SVladimir Oltean 
27963cfc657SVladimir Oltean 	u8			devlink_port_setup:1;
28063cfc657SVladimir Oltean 
281295ab96fSVladimir Oltean 	/* Master state bits, valid only on CPU ports */
282295ab96fSVladimir Oltean 	u8			master_admin_up:1;
283295ab96fSVladimir Oltean 	u8			master_oper_up:1;
284295ab96fSVladimir Oltean 
28563cfc657SVladimir Oltean 	u8			setup:1;
286bde82f38SVladimir Oltean 
287189b0d93SAndrew Lunn 	struct device_node	*dn;
28834a79f63SVivien Didelot 	unsigned int		ageing_time;
289bde82f38SVladimir Oltean 
290d3eed0e5SVladimir Oltean 	struct dsa_bridge	*bridge;
29196567d5dSAndrew Lunn 	struct devlink_port	devlink_port;
292aab9c406SFlorian Fainelli 	struct phylink		*pl;
29344cc27e4SIoana Ciornei 	struct phylink_config	pl_config;
294058102a6STobias Waldekranz 	struct net_device	*lag_dev;
29518596f50SGeorge McCollister 	struct net_device	*hsr_dev;
29697a69a0dSVladimir Oltean 
297ab8ccae1SVivien Didelot 	struct list_head list;
298ab8ccae1SVivien Didelot 
29967dbb9d4SFlorian Fainelli 	/*
30067dbb9d4SFlorian Fainelli 	 * Original copy of the master netdev ethtool_ops
30167dbb9d4SFlorian Fainelli 	 */
30267dbb9d4SFlorian Fainelli 	const struct ethtool_ops *orig_ethtool_ops;
303da7b9e9bSFlorian Fainelli 
304da7b9e9bSFlorian Fainelli 	/*
305da7b9e9bSFlorian Fainelli 	 * Original copy of the master netdev net_device_ops
306da7b9e9bSFlorian Fainelli 	 */
3074cfab356SFlorian Fainelli 	const struct dsa_netdevice_ops *netdev_ops;
308fb35c60cSVivien Didelot 
309161ca59dSVladimir Oltean 	/* List of MAC addresses that must be forwarded on this port.
310161ca59dSVladimir Oltean 	 * These are only valid on CPU ports and DSA links.
311161ca59dSVladimir Oltean 	 */
312338a3a47SVladimir Oltean 	struct mutex		addr_lists_lock;
3133f6e32f9SVladimir Oltean 	struct list_head	fdbs;
314161ca59dSVladimir Oltean 	struct list_head	mdbs;
315c8b09808SAndrew Lunn };
316c8b09808SAndrew Lunn 
317c5f51765SVivien Didelot /* TODO: ideally DSA ports would have a single dp->link_dp member,
318c5f51765SVivien Didelot  * and no dst->rtable nor this struct dsa_link would be needed,
319c5f51765SVivien Didelot  * but this would require some more complex tree walking,
320c5f51765SVivien Didelot  * so keep it stupid at the moment and list them all.
321c5f51765SVivien Didelot  */
322c5f51765SVivien Didelot struct dsa_link {
323c5f51765SVivien Didelot 	struct dsa_port *dp;
324c5f51765SVivien Didelot 	struct dsa_port *link_dp;
325c5f51765SVivien Didelot 	struct list_head list;
326c5f51765SVivien Didelot };
327c5f51765SVivien Didelot 
328161ca59dSVladimir Oltean struct dsa_mac_addr {
329161ca59dSVladimir Oltean 	unsigned char addr[ETH_ALEN];
330161ca59dSVladimir Oltean 	u16 vid;
331161ca59dSVladimir Oltean 	refcount_t refcount;
332161ca59dSVladimir Oltean 	struct list_head list;
333161ca59dSVladimir Oltean };
334161ca59dSVladimir Oltean 
335c8f0b869SBen Hutchings struct dsa_switch {
336c33063d6SAndrew Lunn 	struct device *dev;
337c33063d6SAndrew Lunn 
338c8f0b869SBen Hutchings 	/*
339c8f0b869SBen Hutchings 	 * Parent switch tree, and switch index.
340c8f0b869SBen Hutchings 	 */
341c8f0b869SBen Hutchings 	struct dsa_switch_tree	*dst;
34299feaafcSVivien Didelot 	unsigned int		index;
343c8f0b869SBen Hutchings 
3441b26d364SVladimir Oltean 	/* Warning: the following bit fields are not atomic, and updating them
3451b26d364SVladimir Oltean 	 * can only be done from code paths where concurrency is not possible
3461b26d364SVladimir Oltean 	 * (probe time or under rtnl_lock).
3471b26d364SVladimir Oltean 	 */
34863cfc657SVladimir Oltean 	u32			setup:1;
34963cfc657SVladimir Oltean 
35063cfc657SVladimir Oltean 	/* Disallow bridge core from requesting different VLAN awareness
35163cfc657SVladimir Oltean 	 * settings on ports if not hardware-supported
3527787ff77SVladimir Oltean 	 */
35363cfc657SVladimir Oltean 	u32			vlan_filtering_is_global:1;
35463cfc657SVladimir Oltean 
35563cfc657SVladimir Oltean 	/* Keep VLAN filtering enabled on ports not offloading any upper */
35663cfc657SVladimir Oltean 	u32			needs_standalone_vlan_filtering:1;
35763cfc657SVladimir Oltean 
35863cfc657SVladimir Oltean 	/* Pass .port_vlan_add and .port_vlan_del to drivers even for bridges
35963cfc657SVladimir Oltean 	 * that have vlan_filtering=0. All drivers should ideally set this (and
36063cfc657SVladimir Oltean 	 * then the option would get removed), but it is unknown whether this
3617787ff77SVladimir Oltean 	 * would break things or not.
3627787ff77SVladimir Oltean 	 */
36363cfc657SVladimir Oltean 	u32			configure_vlan_while_not_filtering:1;
36463cfc657SVladimir Oltean 
36563cfc657SVladimir Oltean 	/* If the switch driver always programs the CPU port as egress tagged
36663cfc657SVladimir Oltean 	 * despite the VLAN configuration indicating otherwise, then setting
36763cfc657SVladimir Oltean 	 * @untag_bridge_pvid will force the DSA receive path to pop the
36863cfc657SVladimir Oltean 	 * bridge's default_pvid VLAN tagged frames to offer a consistent
36963cfc657SVladimir Oltean 	 * behavior between a vlan_filtering=0 and vlan_filtering=1 bridge
3707787ff77SVladimir Oltean 	 * device.
3717787ff77SVladimir Oltean 	 */
37263cfc657SVladimir Oltean 	u32			untag_bridge_pvid:1;
37363cfc657SVladimir Oltean 
3747787ff77SVladimir Oltean 	/* Let DSA manage the FDB entries towards the
3757787ff77SVladimir Oltean 	 * CPU, based on the software bridge database.
3767787ff77SVladimir Oltean 	 */
37763cfc657SVladimir Oltean 	u32			assisted_learning_on_cpu_port:1;
37863cfc657SVladimir Oltean 
37963cfc657SVladimir Oltean 	/* In case vlan_filtering_is_global is set, the VLAN awareness state
38063cfc657SVladimir Oltean 	 * should be retrieved from here and not from the per-port settings.
3817787ff77SVladimir Oltean 	 */
38263cfc657SVladimir Oltean 	u32			vlan_filtering:1;
38363cfc657SVladimir Oltean 
38463cfc657SVladimir Oltean 	/* MAC PCS does not provide link state change interrupt, and requires
38563cfc657SVladimir Oltean 	 * polling. Flag passed on to PHYLINK.
3867787ff77SVladimir Oltean 	 */
38763cfc657SVladimir Oltean 	u32			pcs_poll:1;
38863cfc657SVladimir Oltean 
38963cfc657SVladimir Oltean 	/* For switches that only have the MRU configurable. To ensure the
39063cfc657SVladimir Oltean 	 * configured MTU is not exceeded, normalization of MRU on all bridged
39163cfc657SVladimir Oltean 	 * interfaces is needed.
3927787ff77SVladimir Oltean 	 */
39363cfc657SVladimir Oltean 	u32			mtu_enforcement_ingress:1;
3947787ff77SVladimir Oltean 
395f515f192SVivien Didelot 	/* Listener for switch fabric events */
396f515f192SVivien Didelot 	struct notifier_block	nb;
397f515f192SVivien Didelot 
398c8f0b869SBen Hutchings 	/*
3997543a6d5SAndrew Lunn 	 * Give the switch driver somewhere to hang its private data
4007543a6d5SAndrew Lunn 	 * structure.
4017543a6d5SAndrew Lunn 	 */
4027543a6d5SAndrew Lunn 	void *priv;
4037543a6d5SAndrew Lunn 
404dc452a47SVladimir Oltean 	void *tagger_data;
405dc452a47SVladimir Oltean 
4067543a6d5SAndrew Lunn 	/*
407c8f0b869SBen Hutchings 	 * Configuration data for this switch.
408c8f0b869SBen Hutchings 	 */
409ff04955cSAndrew Lunn 	struct dsa_chip_data	*cd;
410c8f0b869SBen Hutchings 
411c8f0b869SBen Hutchings 	/*
4129d490b4eSVivien Didelot 	 * The switch operations.
413c8f0b869SBen Hutchings 	 */
414a82f67afSFlorian Fainelli 	const struct dsa_switch_ops	*ops;
415c8f0b869SBen Hutchings 
41666472fc0SAndrew Lunn 	/*
417c8f0b869SBen Hutchings 	 * Slave mii_bus and devices for the individual ports.
418c8f0b869SBen Hutchings 	 */
4190d8bcdd3SFlorian Fainelli 	u32			phys_mii_mask;
420c8f0b869SBen Hutchings 	struct mii_bus		*slave_mii_bus;
421a0c02161SVivien Didelot 
4220f3da6afSVivien Didelot 	/* Ageing Time limits in msecs */
4230f3da6afSVivien Didelot 	unsigned int ageing_time_min;
4240f3da6afSVivien Didelot 	unsigned int ageing_time_max;
4250f3da6afSVivien Didelot 
426d7b1fd52SVladimir Oltean 	/* Storage for drivers using tag_8021q */
427d7b1fd52SVladimir Oltean 	struct dsa_8021q_context *tag_8021q_ctx;
428d7b1fd52SVladimir Oltean 
42996567d5dSAndrew Lunn 	/* devlink used to represent this switch device */
43096567d5dSAndrew Lunn 	struct devlink		*devlink;
43196567d5dSAndrew Lunn 
43255199df6SFlorian Fainelli 	/* Number of switch port queues */
43355199df6SFlorian Fainelli 	unsigned int		num_tx_queues;
43455199df6SFlorian Fainelli 
435058102a6STobias Waldekranz 	/* Drivers that benefit from having an ID associated with each
436058102a6STobias Waldekranz 	 * offloaded LAG should set this to the maximum number of
437058102a6STobias Waldekranz 	 * supported IDs. DSA will then maintain a mapping of _at
438058102a6STobias Waldekranz 	 * least_ these many IDs, accessible to drivers via
439058102a6STobias Waldekranz 	 * dsa_lag_id().
440058102a6STobias Waldekranz 	 */
441058102a6STobias Waldekranz 	unsigned int		num_lag_ids;
442058102a6STobias Waldekranz 
443947c8746SVladimir Oltean 	/* Drivers that support bridge forwarding offload or FDB isolation
444947c8746SVladimir Oltean 	 * should set this to the maximum number of bridges spanning the same
445947c8746SVladimir Oltean 	 * switch tree (or all trees, in the case of cross-tree bridging
446947c8746SVladimir Oltean 	 * support) that can be offloaded.
447123abc06SVladimir Oltean 	 */
448947c8746SVladimir Oltean 	unsigned int		max_num_bridges;
449123abc06SVladimir Oltean 
450258030acSVladimir Oltean 	unsigned int		num_ports;
451c8f0b869SBen Hutchings };
452c8f0b869SBen Hutchings 
45368bb8ea8SVivien Didelot static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p)
454c38c5a66SVivien Didelot {
455b96ddf25SVivien Didelot 	struct dsa_switch_tree *dst = ds->dst;
456d607525bSVivien Didelot 	struct dsa_port *dp;
457b96ddf25SVivien Didelot 
458b96ddf25SVivien Didelot 	list_for_each_entry(dp, &dst->ports, list)
459b96ddf25SVivien Didelot 		if (dp->ds == ds && dp->index == p)
460b96ddf25SVivien Didelot 			return dp;
461d607525bSVivien Didelot 
462d607525bSVivien Didelot 	return NULL;
463c38c5a66SVivien Didelot }
464c38c5a66SVivien Didelot 
465a8986681SVladimir Oltean static inline bool dsa_port_is_dsa(struct dsa_port *port)
466a8986681SVladimir Oltean {
467a8986681SVladimir Oltean 	return port->type == DSA_PORT_TYPE_DSA;
468a8986681SVladimir Oltean }
469a8986681SVladimir Oltean 
470a8986681SVladimir Oltean static inline bool dsa_port_is_cpu(struct dsa_port *port)
471a8986681SVladimir Oltean {
472a8986681SVladimir Oltean 	return port->type == DSA_PORT_TYPE_CPU;
473a8986681SVladimir Oltean }
474a8986681SVladimir Oltean 
475a8986681SVladimir Oltean static inline bool dsa_port_is_user(struct dsa_port *dp)
476a8986681SVladimir Oltean {
477a8986681SVladimir Oltean 	return dp->type == DSA_PORT_TYPE_USER;
478a8986681SVladimir Oltean }
479a8986681SVladimir Oltean 
480a57d8c21SVladimir Oltean static inline bool dsa_port_is_unused(struct dsa_port *dp)
481a57d8c21SVladimir Oltean {
482a57d8c21SVladimir Oltean 	return dp->type == DSA_PORT_TYPE_UNUSED;
483a57d8c21SVladimir Oltean }
484a57d8c21SVladimir Oltean 
485295ab96fSVladimir Oltean static inline bool dsa_port_master_is_operational(struct dsa_port *dp)
486295ab96fSVladimir Oltean {
487295ab96fSVladimir Oltean 	return dsa_port_is_cpu(dp) && dp->master_admin_up &&
488295ab96fSVladimir Oltean 	       dp->master_oper_up;
489295ab96fSVladimir Oltean }
490295ab96fSVladimir Oltean 
491bff7b688SVivien Didelot static inline bool dsa_is_unused_port(struct dsa_switch *ds, int p)
492bff7b688SVivien Didelot {
493c38c5a66SVivien Didelot 	return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_UNUSED;
494bff7b688SVivien Didelot }
495bff7b688SVivien Didelot 
496c8f0b869SBen Hutchings static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
497c8f0b869SBen Hutchings {
498c38c5a66SVivien Didelot 	return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_CPU;
499c8f0b869SBen Hutchings }
500c8f0b869SBen Hutchings 
50160045cbfSAndrew Lunn static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p)
50260045cbfSAndrew Lunn {
503c38c5a66SVivien Didelot 	return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_DSA;
50460045cbfSAndrew Lunn }
50560045cbfSAndrew Lunn 
5062b3e9891SVivien Didelot static inline bool dsa_is_user_port(struct dsa_switch *ds, int p)
5076cd456f3SVivien Didelot {
508c38c5a66SVivien Didelot 	return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_USER;
5096cd456f3SVivien Didelot }
5106cd456f3SVivien Didelot 
51182b31898SVladimir Oltean #define dsa_tree_for_each_user_port(_dp, _dst) \
51282b31898SVladimir Oltean 	list_for_each_entry((_dp), &(_dst)->ports, list) \
51382b31898SVladimir Oltean 		if (dsa_port_is_user((_dp)))
51482b31898SVladimir Oltean 
51582b31898SVladimir Oltean #define dsa_switch_for_each_port(_dp, _ds) \
51682b31898SVladimir Oltean 	list_for_each_entry((_dp), &(_ds)->dst->ports, list) \
51782b31898SVladimir Oltean 		if ((_dp)->ds == (_ds))
51882b31898SVladimir Oltean 
51982b31898SVladimir Oltean #define dsa_switch_for_each_port_safe(_dp, _next, _ds) \
52082b31898SVladimir Oltean 	list_for_each_entry_safe((_dp), (_next), &(_ds)->dst->ports, list) \
52182b31898SVladimir Oltean 		if ((_dp)->ds == (_ds))
52282b31898SVladimir Oltean 
52382b31898SVladimir Oltean #define dsa_switch_for_each_port_continue_reverse(_dp, _ds) \
52482b31898SVladimir Oltean 	list_for_each_entry_continue_reverse((_dp), &(_ds)->dst->ports, list) \
52582b31898SVladimir Oltean 		if ((_dp)->ds == (_ds))
52682b31898SVladimir Oltean 
52782b31898SVladimir Oltean #define dsa_switch_for_each_available_port(_dp, _ds) \
52882b31898SVladimir Oltean 	dsa_switch_for_each_port((_dp), (_ds)) \
52982b31898SVladimir Oltean 		if (!dsa_port_is_unused((_dp)))
53082b31898SVladimir Oltean 
53182b31898SVladimir Oltean #define dsa_switch_for_each_user_port(_dp, _ds) \
53282b31898SVladimir Oltean 	dsa_switch_for_each_port((_dp), (_ds)) \
53382b31898SVladimir Oltean 		if (dsa_port_is_user((_dp)))
53482b31898SVladimir Oltean 
53582b31898SVladimir Oltean #define dsa_switch_for_each_cpu_port(_dp, _ds) \
53682b31898SVladimir Oltean 	dsa_switch_for_each_port((_dp), (_ds)) \
53782b31898SVladimir Oltean 		if (dsa_port_is_cpu((_dp)))
53882b31898SVladimir Oltean 
53902bc6e54SVivien Didelot static inline u32 dsa_user_ports(struct dsa_switch *ds)
54002bc6e54SVivien Didelot {
541d0004a02SVladimir Oltean 	struct dsa_port *dp;
542c38c5a66SVivien Didelot 	u32 mask = 0;
54302bc6e54SVivien Didelot 
544d0004a02SVladimir Oltean 	dsa_switch_for_each_user_port(dp, ds)
545d0004a02SVladimir Oltean 		mask |= BIT(dp->index);
546c38c5a66SVivien Didelot 
547c38c5a66SVivien Didelot 	return mask;
548c8652c83SVivien Didelot }
549c8652c83SVivien Didelot 
550c5f51765SVivien Didelot /* Return the local port used to reach an arbitrary switch device */
551c5f51765SVivien Didelot static inline unsigned int dsa_routing_port(struct dsa_switch *ds, int device)
552c5f51765SVivien Didelot {
553c5f51765SVivien Didelot 	struct dsa_switch_tree *dst = ds->dst;
554c5f51765SVivien Didelot 	struct dsa_link *dl;
555c5f51765SVivien Didelot 
556c5f51765SVivien Didelot 	list_for_each_entry(dl, &dst->rtable, list)
557c5f51765SVivien Didelot 		if (dl->dp->ds == ds && dl->link_dp->ds->index == device)
558c5f51765SVivien Didelot 			return dl->dp->index;
559c5f51765SVivien Didelot 
560c5f51765SVivien Didelot 	return ds->num_ports;
561c5f51765SVivien Didelot }
562c5f51765SVivien Didelot 
5633b8fac5dSVivien Didelot /* Return the local port used to reach an arbitrary switch port */
5643b8fac5dSVivien Didelot static inline unsigned int dsa_towards_port(struct dsa_switch *ds, int device,
5653b8fac5dSVivien Didelot 					    int port)
5663b8fac5dSVivien Didelot {
5673b8fac5dSVivien Didelot 	if (device == ds->index)
5683b8fac5dSVivien Didelot 		return port;
5693b8fac5dSVivien Didelot 	else
570c5f51765SVivien Didelot 		return dsa_routing_port(ds, device);
5713b8fac5dSVivien Didelot }
5723b8fac5dSVivien Didelot 
5733b8fac5dSVivien Didelot /* Return the local port used to reach the dedicated CPU port */
57407073c79SVivien Didelot static inline unsigned int dsa_upstream_port(struct dsa_switch *ds, int port)
575c8f0b869SBen Hutchings {
57607073c79SVivien Didelot 	const struct dsa_port *dp = dsa_to_port(ds, port);
57707073c79SVivien Didelot 	const struct dsa_port *cpu_dp = dp->cpu_dp;
57807073c79SVivien Didelot 
57907073c79SVivien Didelot 	if (!cpu_dp)
58007073c79SVivien Didelot 		return port;
581c8f0b869SBen Hutchings 
5823b8fac5dSVivien Didelot 	return dsa_towards_port(ds, cpu_dp->ds->index, cpu_dp->index);
583c8f0b869SBen Hutchings }
584c8f0b869SBen Hutchings 
58563609c8fSVladimir Oltean /* Return true if this is the local port used to reach the CPU port */
58663609c8fSVladimir Oltean static inline bool dsa_is_upstream_port(struct dsa_switch *ds, int port)
58763609c8fSVladimir Oltean {
58863609c8fSVladimir Oltean 	if (dsa_is_unused_port(ds, port))
58963609c8fSVladimir Oltean 		return false;
59063609c8fSVladimir Oltean 
59163609c8fSVladimir Oltean 	return port == dsa_upstream_port(ds, port);
59263609c8fSVladimir Oltean }
59363609c8fSVladimir Oltean 
594*7af4a361STobias Waldekranz /* Return the local port used to reach the CPU port */
595*7af4a361STobias Waldekranz static inline unsigned int dsa_switch_upstream_port(struct dsa_switch *ds)
596*7af4a361STobias Waldekranz {
597*7af4a361STobias Waldekranz 	struct dsa_port *dp;
598*7af4a361STobias Waldekranz 
599*7af4a361STobias Waldekranz 	dsa_switch_for_each_available_port(dp, ds) {
600*7af4a361STobias Waldekranz 		return dsa_upstream_port(ds, dp->index);
601*7af4a361STobias Waldekranz 	}
602*7af4a361STobias Waldekranz 
603*7af4a361STobias Waldekranz 	return ds->num_ports;
604*7af4a361STobias Waldekranz }
605*7af4a361STobias Waldekranz 
60663609c8fSVladimir Oltean /* Return true if @upstream_ds is an upstream switch of @downstream_ds, meaning
60763609c8fSVladimir Oltean  * that the routing port from @downstream_ds to @upstream_ds is also the port
60863609c8fSVladimir Oltean  * which @downstream_ds uses to reach its dedicated CPU.
60963609c8fSVladimir Oltean  */
61063609c8fSVladimir Oltean static inline bool dsa_switch_is_upstream_of(struct dsa_switch *upstream_ds,
61163609c8fSVladimir Oltean 					     struct dsa_switch *downstream_ds)
61263609c8fSVladimir Oltean {
61363609c8fSVladimir Oltean 	int routing_port;
61463609c8fSVladimir Oltean 
61563609c8fSVladimir Oltean 	if (upstream_ds == downstream_ds)
61663609c8fSVladimir Oltean 		return true;
61763609c8fSVladimir Oltean 
61863609c8fSVladimir Oltean 	routing_port = dsa_routing_port(downstream_ds, upstream_ds->index);
61963609c8fSVladimir Oltean 
62063609c8fSVladimir Oltean 	return dsa_is_upstream_port(downstream_ds, routing_port);
62163609c8fSVladimir Oltean }
62263609c8fSVladimir Oltean 
623cf2d45f5SVladimir Oltean static inline bool dsa_port_is_vlan_filtering(const struct dsa_port *dp)
624cf2d45f5SVladimir Oltean {
625cf2d45f5SVladimir Oltean 	const struct dsa_switch *ds = dp->ds;
626cf2d45f5SVladimir Oltean 
627cf2d45f5SVladimir Oltean 	if (ds->vlan_filtering_is_global)
628cf2d45f5SVladimir Oltean 		return ds->vlan_filtering;
629cf2d45f5SVladimir Oltean 	else
630cf2d45f5SVladimir Oltean 		return dp->vlan_filtering;
631cf2d45f5SVladimir Oltean }
632cf2d45f5SVladimir Oltean 
633cc76ce9eSTobias Waldekranz static inline
634cc76ce9eSTobias Waldekranz struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp)
635cc76ce9eSTobias Waldekranz {
636d3eed0e5SVladimir Oltean 	if (!dp->bridge)
637cc76ce9eSTobias Waldekranz 		return NULL;
638cc76ce9eSTobias Waldekranz 
639cc76ce9eSTobias Waldekranz 	if (dp->lag_dev)
640cc76ce9eSTobias Waldekranz 		return dp->lag_dev;
641cc76ce9eSTobias Waldekranz 	else if (dp->hsr_dev)
642cc76ce9eSTobias Waldekranz 		return dp->hsr_dev;
643cc76ce9eSTobias Waldekranz 
644cc76ce9eSTobias Waldekranz 	return dp->slave;
645cc76ce9eSTobias Waldekranz }
646cc76ce9eSTobias Waldekranz 
64736cbf39bSVladimir Oltean static inline struct net_device *
64836cbf39bSVladimir Oltean dsa_port_bridge_dev_get(const struct dsa_port *dp)
64936cbf39bSVladimir Oltean {
650d3eed0e5SVladimir Oltean 	return dp->bridge ? dp->bridge->dev : NULL;
65136cbf39bSVladimir Oltean }
65236cbf39bSVladimir Oltean 
65336cbf39bSVladimir Oltean static inline unsigned int dsa_port_bridge_num_get(struct dsa_port *dp)
65436cbf39bSVladimir Oltean {
655d3eed0e5SVladimir Oltean 	return dp->bridge ? dp->bridge->num : 0;
65636cbf39bSVladimir Oltean }
65736cbf39bSVladimir Oltean 
65836cbf39bSVladimir Oltean static inline bool dsa_port_bridge_same(const struct dsa_port *a,
65936cbf39bSVladimir Oltean 					const struct dsa_port *b)
66036cbf39bSVladimir Oltean {
66136cbf39bSVladimir Oltean 	struct net_device *br_a = dsa_port_bridge_dev_get(a);
66236cbf39bSVladimir Oltean 	struct net_device *br_b = dsa_port_bridge_dev_get(b);
66336cbf39bSVladimir Oltean 
66436cbf39bSVladimir Oltean 	/* Standalone ports are not in the same bridge with one another */
66536cbf39bSVladimir Oltean 	return (!br_a || !br_b) ? false : (br_a == br_b);
66636cbf39bSVladimir Oltean }
66736cbf39bSVladimir Oltean 
6686a43cba3SVladimir Oltean static inline bool dsa_port_offloads_bridge_port(struct dsa_port *dp,
6696a43cba3SVladimir Oltean 						 const struct net_device *dev)
6706a43cba3SVladimir Oltean {
6716a43cba3SVladimir Oltean 	return dsa_port_to_bridge_port(dp) == dev;
6726a43cba3SVladimir Oltean }
6736a43cba3SVladimir Oltean 
6746a43cba3SVladimir Oltean static inline bool
6756a43cba3SVladimir Oltean dsa_port_offloads_bridge_dev(struct dsa_port *dp,
6766a43cba3SVladimir Oltean 			     const struct net_device *bridge_dev)
6776a43cba3SVladimir Oltean {
6786a43cba3SVladimir Oltean 	/* DSA ports connected to a bridge, and event was emitted
6796a43cba3SVladimir Oltean 	 * for the bridge.
6806a43cba3SVladimir Oltean 	 */
6816a43cba3SVladimir Oltean 	return dsa_port_bridge_dev_get(dp) == bridge_dev;
6826a43cba3SVladimir Oltean }
6836a43cba3SVladimir Oltean 
684d3eed0e5SVladimir Oltean static inline bool dsa_port_offloads_bridge(struct dsa_port *dp,
685d3eed0e5SVladimir Oltean 					    const struct dsa_bridge *bridge)
686d3eed0e5SVladimir Oltean {
687d3eed0e5SVladimir Oltean 	return dsa_port_bridge_dev_get(dp) == bridge->dev;
688d3eed0e5SVladimir Oltean }
689d3eed0e5SVladimir Oltean 
6906a43cba3SVladimir Oltean /* Returns true if any port of this tree offloads the given net_device */
6916a43cba3SVladimir Oltean static inline bool dsa_tree_offloads_bridge_port(struct dsa_switch_tree *dst,
6926a43cba3SVladimir Oltean 						 const struct net_device *dev)
6936a43cba3SVladimir Oltean {
6946a43cba3SVladimir Oltean 	struct dsa_port *dp;
6956a43cba3SVladimir Oltean 
6966a43cba3SVladimir Oltean 	list_for_each_entry(dp, &dst->ports, list)
6976a43cba3SVladimir Oltean 		if (dsa_port_offloads_bridge_port(dp, dev))
6986a43cba3SVladimir Oltean 			return true;
6996a43cba3SVladimir Oltean 
7006a43cba3SVladimir Oltean 	return false;
7016a43cba3SVladimir Oltean }
7026a43cba3SVladimir Oltean 
7036a43cba3SVladimir Oltean /* Returns true if any port of this tree offloads the given bridge */
7046a43cba3SVladimir Oltean static inline bool
7056a43cba3SVladimir Oltean dsa_tree_offloads_bridge_dev(struct dsa_switch_tree *dst,
7066a43cba3SVladimir Oltean 			     const struct net_device *bridge_dev)
7076a43cba3SVladimir Oltean {
7086a43cba3SVladimir Oltean 	struct dsa_port *dp;
7096a43cba3SVladimir Oltean 
7106a43cba3SVladimir Oltean 	list_for_each_entry(dp, &dst->ports, list)
7116a43cba3SVladimir Oltean 		if (dsa_port_offloads_bridge_dev(dp, bridge_dev))
7126a43cba3SVladimir Oltean 			return true;
7136a43cba3SVladimir Oltean 
7146a43cba3SVladimir Oltean 	return false;
7156a43cba3SVladimir Oltean }
7166a43cba3SVladimir Oltean 
7172bedde1aSArkadi Sharshevsky typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid,
7182bedde1aSArkadi Sharshevsky 			      bool is_static, void *data);
7199d490b4eSVivien Didelot struct dsa_switch_ops {
72053da0ebaSVladimir Oltean 	/*
72153da0ebaSVladimir Oltean 	 * Tagging protocol helpers called for the CPU ports and DSA links.
72253da0ebaSVladimir Oltean 	 * @get_tag_protocol retrieves the initial tagging protocol and is
72353da0ebaSVladimir Oltean 	 * mandatory. Switches which can operate using multiple tagging
72453da0ebaSVladimir Oltean 	 * protocols should implement @change_tag_protocol and report in
72553da0ebaSVladimir Oltean 	 * @get_tag_protocol the tagger in current use.
72653da0ebaSVladimir Oltean 	 */
7275ed4e3ebSFlorian Fainelli 	enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds,
7284d776482SFlorian Fainelli 						  int port,
7294d776482SFlorian Fainelli 						  enum dsa_tag_protocol mprot);
73053da0ebaSVladimir Oltean 	int	(*change_tag_protocol)(struct dsa_switch *ds, int port,
73153da0ebaSVladimir Oltean 				       enum dsa_tag_protocol proto);
732dc452a47SVladimir Oltean 	/*
733dc452a47SVladimir Oltean 	 * Method for switch drivers to connect to the tagging protocol driver
734dc452a47SVladimir Oltean 	 * in current use. The switch driver can provide handlers for certain
735dc452a47SVladimir Oltean 	 * types of packets for switch management.
736dc452a47SVladimir Oltean 	 */
737dc452a47SVladimir Oltean 	int	(*connect_tag_protocol)(struct dsa_switch *ds,
738dc452a47SVladimir Oltean 					enum dsa_tag_protocol proto);
7397b314362SAndrew Lunn 
740fd292c18SVladimir Oltean 	/* Optional switch-wide initialization and destruction methods */
741c8f0b869SBen Hutchings 	int	(*setup)(struct dsa_switch *ds);
7425e3f847aSVladimir Oltean 	void	(*teardown)(struct dsa_switch *ds);
743fd292c18SVladimir Oltean 
744fd292c18SVladimir Oltean 	/* Per-port initialization and destruction methods. Mandatory if the
745fd292c18SVladimir Oltean 	 * driver registers devlink port regions, optional otherwise.
746fd292c18SVladimir Oltean 	 */
747fd292c18SVladimir Oltean 	int	(*port_setup)(struct dsa_switch *ds, int port);
748fd292c18SVladimir Oltean 	void	(*port_teardown)(struct dsa_switch *ds, int port);
749fd292c18SVladimir Oltean 
7506819563eSFlorian Fainelli 	u32	(*get_phy_flags)(struct dsa_switch *ds, int port);
751c8f0b869SBen Hutchings 
752c8f0b869SBen Hutchings 	/*
753c8f0b869SBen Hutchings 	 * Access to the switch's PHY registers.
754c8f0b869SBen Hutchings 	 */
755c8f0b869SBen Hutchings 	int	(*phy_read)(struct dsa_switch *ds, int port, int regnum);
756c8f0b869SBen Hutchings 	int	(*phy_write)(struct dsa_switch *ds, int port,
757c8f0b869SBen Hutchings 			     int regnum, u16 val);
758c8f0b869SBen Hutchings 
759c8f0b869SBen Hutchings 	/*
760ec9436baSFlorian Fainelli 	 * Link state adjustment (called from libphy)
761ec9436baSFlorian Fainelli 	 */
762ec9436baSFlorian Fainelli 	void	(*adjust_link)(struct dsa_switch *ds, int port,
763ec9436baSFlorian Fainelli 				struct phy_device *phydev);
764ce31b31cSFlorian Fainelli 	void	(*fixed_link_update)(struct dsa_switch *ds, int port,
765ce31b31cSFlorian Fainelli 				struct fixed_phy_status *st);
766ec9436baSFlorian Fainelli 
767ec9436baSFlorian Fainelli 	/*
76811d8f3ddSFlorian Fainelli 	 * PHYLINK integration
76911d8f3ddSFlorian Fainelli 	 */
770072eea6cSRussell King (Oracle) 	void	(*phylink_get_caps)(struct dsa_switch *ds, int port,
771072eea6cSRussell King (Oracle) 				    struct phylink_config *config);
77211d8f3ddSFlorian Fainelli 	void	(*phylink_validate)(struct dsa_switch *ds, int port,
77311d8f3ddSFlorian Fainelli 				    unsigned long *supported,
77411d8f3ddSFlorian Fainelli 				    struct phylink_link_state *state);
77511d8f3ddSFlorian Fainelli 	int	(*phylink_mac_link_state)(struct dsa_switch *ds, int port,
77611d8f3ddSFlorian Fainelli 					  struct phylink_link_state *state);
77711d8f3ddSFlorian Fainelli 	void	(*phylink_mac_config)(struct dsa_switch *ds, int port,
77811d8f3ddSFlorian Fainelli 				      unsigned int mode,
77911d8f3ddSFlorian Fainelli 				      const struct phylink_link_state *state);
78011d8f3ddSFlorian Fainelli 	void	(*phylink_mac_an_restart)(struct dsa_switch *ds, int port);
78111d8f3ddSFlorian Fainelli 	void	(*phylink_mac_link_down)(struct dsa_switch *ds, int port,
78211d8f3ddSFlorian Fainelli 					 unsigned int mode,
78311d8f3ddSFlorian Fainelli 					 phy_interface_t interface);
78411d8f3ddSFlorian Fainelli 	void	(*phylink_mac_link_up)(struct dsa_switch *ds, int port,
78511d8f3ddSFlorian Fainelli 				       unsigned int mode,
78611d8f3ddSFlorian Fainelli 				       phy_interface_t interface,
7875b502a7bSRussell King 				       struct phy_device *phydev,
7885b502a7bSRussell King 				       int speed, int duplex,
7895b502a7bSRussell King 				       bool tx_pause, bool rx_pause);
79011d8f3ddSFlorian Fainelli 	void	(*phylink_fixed_state)(struct dsa_switch *ds, int port,
79111d8f3ddSFlorian Fainelli 				       struct phylink_link_state *state);
79211d8f3ddSFlorian Fainelli 	/*
793c2ec5f2eSOleksij Rempel 	 * Port statistics counters.
794c8f0b869SBen Hutchings 	 */
79589f09048SFlorian Fainelli 	void	(*get_strings)(struct dsa_switch *ds, int port,
79689f09048SFlorian Fainelli 			       u32 stringset, uint8_t *data);
797c8f0b869SBen Hutchings 	void	(*get_ethtool_stats)(struct dsa_switch *ds,
798c8f0b869SBen Hutchings 				     int port, uint64_t *data);
79989f09048SFlorian Fainelli 	int	(*get_sset_count)(struct dsa_switch *ds, int port, int sset);
800cf963573SFlorian Fainelli 	void	(*get_ethtool_phy_stats)(struct dsa_switch *ds,
801cf963573SFlorian Fainelli 					 int port, uint64_t *data);
802487d3855SAlvin Šipraga 	void	(*get_eth_phy_stats)(struct dsa_switch *ds, int port,
803487d3855SAlvin Šipraga 				     struct ethtool_eth_phy_stats *phy_stats);
804487d3855SAlvin Šipraga 	void	(*get_eth_mac_stats)(struct dsa_switch *ds, int port,
805487d3855SAlvin Šipraga 				     struct ethtool_eth_mac_stats *mac_stats);
806487d3855SAlvin Šipraga 	void	(*get_eth_ctrl_stats)(struct dsa_switch *ds, int port,
807487d3855SAlvin Šipraga 				      struct ethtool_eth_ctrl_stats *ctrl_stats);
808c2ec5f2eSOleksij Rempel 	void	(*get_stats64)(struct dsa_switch *ds, int port,
809c2ec5f2eSOleksij Rempel 				   struct rtnl_link_stats64 *s);
810a71acad9SOleksij Rempel 	void	(*self_test)(struct dsa_switch *ds, int port,
811a71acad9SOleksij Rempel 			     struct ethtool_test *etest, u64 *data);
81224462549SFlorian Fainelli 
81324462549SFlorian Fainelli 	/*
81419e57c4eSFlorian Fainelli 	 * ethtool Wake-on-LAN
81519e57c4eSFlorian Fainelli 	 */
81619e57c4eSFlorian Fainelli 	void	(*get_wol)(struct dsa_switch *ds, int port,
81719e57c4eSFlorian Fainelli 			   struct ethtool_wolinfo *w);
81819e57c4eSFlorian Fainelli 	int	(*set_wol)(struct dsa_switch *ds, int port,
81919e57c4eSFlorian Fainelli 			   struct ethtool_wolinfo *w);
82019e57c4eSFlorian Fainelli 
82119e57c4eSFlorian Fainelli 	/*
8220336369dSBrandon Streiff 	 * ethtool timestamp info
8230336369dSBrandon Streiff 	 */
8240336369dSBrandon Streiff 	int	(*get_ts_info)(struct dsa_switch *ds, int port,
8250336369dSBrandon Streiff 			       struct ethtool_ts_info *ts);
8260336369dSBrandon Streiff 
8270336369dSBrandon Streiff 	/*
82824462549SFlorian Fainelli 	 * Suspend and resume
82924462549SFlorian Fainelli 	 */
83024462549SFlorian Fainelli 	int	(*suspend)(struct dsa_switch *ds);
83124462549SFlorian Fainelli 	int	(*resume)(struct dsa_switch *ds);
832b2f2af21SFlorian Fainelli 
833b2f2af21SFlorian Fainelli 	/*
834b2f2af21SFlorian Fainelli 	 * Port enable/disable
835b2f2af21SFlorian Fainelli 	 */
836b2f2af21SFlorian Fainelli 	int	(*port_enable)(struct dsa_switch *ds, int port,
837b2f2af21SFlorian Fainelli 			       struct phy_device *phy);
83875104db0SAndrew Lunn 	void	(*port_disable)(struct dsa_switch *ds, int port);
8397905288fSFlorian Fainelli 
8407905288fSFlorian Fainelli 	/*
84108f50061SVivien Didelot 	 * Port's MAC EEE settings
8427905288fSFlorian Fainelli 	 */
84308f50061SVivien Didelot 	int	(*set_mac_eee)(struct dsa_switch *ds, int port,
8447905288fSFlorian Fainelli 			       struct ethtool_eee *e);
84508f50061SVivien Didelot 	int	(*get_mac_eee)(struct dsa_switch *ds, int port,
8467905288fSFlorian Fainelli 			       struct ethtool_eee *e);
84751579c3fSGuenter Roeck 
8486793abb4SGuenter Roeck 	/* EEPROM access */
8496793abb4SGuenter Roeck 	int	(*get_eeprom_len)(struct dsa_switch *ds);
8506793abb4SGuenter Roeck 	int	(*get_eeprom)(struct dsa_switch *ds,
8516793abb4SGuenter Roeck 			      struct ethtool_eeprom *eeprom, u8 *data);
8526793abb4SGuenter Roeck 	int	(*set_eeprom)(struct dsa_switch *ds,
8536793abb4SGuenter Roeck 			      struct ethtool_eeprom *eeprom, u8 *data);
8543d762a0fSGuenter Roeck 
8553d762a0fSGuenter Roeck 	/*
8563d762a0fSGuenter Roeck 	 * Register access.
8573d762a0fSGuenter Roeck 	 */
8583d762a0fSGuenter Roeck 	int	(*get_regs_len)(struct dsa_switch *ds, int port);
8593d762a0fSGuenter Roeck 	void	(*get_regs)(struct dsa_switch *ds, int port,
8603d762a0fSGuenter Roeck 			    struct ethtool_regs *regs, void *p);
861b73adef6SFlorian Fainelli 
862b73adef6SFlorian Fainelli 	/*
863e358bef7SVladimir Oltean 	 * Upper device tracking.
864e358bef7SVladimir Oltean 	 */
865e358bef7SVladimir Oltean 	int	(*port_prechangeupper)(struct dsa_switch *ds, int port,
866e358bef7SVladimir Oltean 				       struct netdev_notifier_changeupper_info *info);
867e358bef7SVladimir Oltean 
868e358bef7SVladimir Oltean 	/*
869b73adef6SFlorian Fainelli 	 * Bridge integration
870b73adef6SFlorian Fainelli 	 */
87134a79f63SVivien Didelot 	int	(*set_ageing_time)(struct dsa_switch *ds, unsigned int msecs);
87271327a4eSVivien Didelot 	int	(*port_bridge_join)(struct dsa_switch *ds, int port,
873b079922bSVladimir Oltean 				    struct dsa_bridge bridge,
874b079922bSVladimir Oltean 				    bool *tx_fwd_offload);
875f123f2fbSVivien Didelot 	void	(*port_bridge_leave)(struct dsa_switch *ds, int port,
876d3eed0e5SVladimir Oltean 				     struct dsa_bridge bridge);
87743c44a9fSVivien Didelot 	void	(*port_stp_state_set)(struct dsa_switch *ds, int port,
878b73adef6SFlorian Fainelli 				      u8 state);
879732f794cSVivien Didelot 	void	(*port_fast_age)(struct dsa_switch *ds, int port);
880a8b659e7SVladimir Oltean 	int	(*port_pre_bridge_flags)(struct dsa_switch *ds, int port,
881a8b659e7SVladimir Oltean 					 struct switchdev_brport_flags flags,
882a8b659e7SVladimir Oltean 					 struct netlink_ext_ack *extack);
883a8b659e7SVladimir Oltean 	int	(*port_bridge_flags)(struct dsa_switch *ds, int port,
884a8b659e7SVladimir Oltean 				     struct switchdev_brport_flags flags,
885a8b659e7SVladimir Oltean 				     struct netlink_ext_ack *extack);
8862a778e1bSVivien Didelot 
8872a778e1bSVivien Didelot 	/*
88811149536SVivien Didelot 	 * VLAN support
88911149536SVivien Didelot 	 */
890fb2dabadSVivien Didelot 	int	(*port_vlan_filtering)(struct dsa_switch *ds, int port,
89189153ed6SVladimir Oltean 				       bool vlan_filtering,
89289153ed6SVladimir Oltean 				       struct netlink_ext_ack *extack);
8931958d581SVladimir Oltean 	int	(*port_vlan_add)(struct dsa_switch *ds, int port,
89431046a5fSVladimir Oltean 				 const struct switchdev_obj_port_vlan *vlan,
89531046a5fSVladimir Oltean 				 struct netlink_ext_ack *extack);
89676e398a6SVivien Didelot 	int	(*port_vlan_del)(struct dsa_switch *ds, int port,
89776e398a6SVivien Didelot 				 const struct switchdev_obj_port_vlan *vlan);
89811149536SVivien Didelot 	/*
8992a778e1bSVivien Didelot 	 * Forwarding database
9002a778e1bSVivien Didelot 	 */
9011b6dd556SArkadi Sharshevsky 	int	(*port_fdb_add)(struct dsa_switch *ds, int port,
9026c2c1dcbSArkadi Sharshevsky 				const unsigned char *addr, u16 vid);
9032a778e1bSVivien Didelot 	int	(*port_fdb_del)(struct dsa_switch *ds, int port,
9046c2c1dcbSArkadi Sharshevsky 				const unsigned char *addr, u16 vid);
905ea70ba98SVivien Didelot 	int	(*port_fdb_dump)(struct dsa_switch *ds, int port,
9062bedde1aSArkadi Sharshevsky 				 dsa_fdb_dump_cb_t *cb, void *data);
9078df30255SVivien Didelot 
9088df30255SVivien Didelot 	/*
9098df30255SVivien Didelot 	 * Multicast database
9108df30255SVivien Didelot 	 */
911a52b2da7SVladimir Oltean 	int	(*port_mdb_add)(struct dsa_switch *ds, int port,
9123709aadcSVivien Didelot 				const struct switchdev_obj_port_mdb *mdb);
9138df30255SVivien Didelot 	int	(*port_mdb_del)(struct dsa_switch *ds, int port,
9148df30255SVivien Didelot 				const struct switchdev_obj_port_mdb *mdb);
915bf9f2648SFlorian Fainelli 	/*
916bf9f2648SFlorian Fainelli 	 * RXNFC
917bf9f2648SFlorian Fainelli 	 */
918bf9f2648SFlorian Fainelli 	int	(*get_rxnfc)(struct dsa_switch *ds, int port,
919bf9f2648SFlorian Fainelli 			     struct ethtool_rxnfc *nfc, u32 *rule_locs);
920bf9f2648SFlorian Fainelli 	int	(*set_rxnfc)(struct dsa_switch *ds, int port,
921bf9f2648SFlorian Fainelli 			     struct ethtool_rxnfc *nfc);
922f50f2127SFlorian Fainelli 
923f50f2127SFlorian Fainelli 	/*
924f50f2127SFlorian Fainelli 	 * TC integration
925f50f2127SFlorian Fainelli 	 */
926ed11bb1fSVladimir Oltean 	int	(*cls_flower_add)(struct dsa_switch *ds, int port,
927ed11bb1fSVladimir Oltean 				  struct flow_cls_offload *cls, bool ingress);
928ed11bb1fSVladimir Oltean 	int	(*cls_flower_del)(struct dsa_switch *ds, int port,
929ed11bb1fSVladimir Oltean 				  struct flow_cls_offload *cls, bool ingress);
930ed11bb1fSVladimir Oltean 	int	(*cls_flower_stats)(struct dsa_switch *ds, int port,
931ed11bb1fSVladimir Oltean 				    struct flow_cls_offload *cls, bool ingress);
932f50f2127SFlorian Fainelli 	int	(*port_mirror_add)(struct dsa_switch *ds, int port,
933f50f2127SFlorian Fainelli 				   struct dsa_mall_mirror_tc_entry *mirror,
934f50f2127SFlorian Fainelli 				   bool ingress);
935f50f2127SFlorian Fainelli 	void	(*port_mirror_del)(struct dsa_switch *ds, int port,
936f50f2127SFlorian Fainelli 				   struct dsa_mall_mirror_tc_entry *mirror);
93734297176SVladimir Oltean 	int	(*port_policer_add)(struct dsa_switch *ds, int port,
93834297176SVladimir Oltean 				    struct dsa_mall_policer_tc_entry *policer);
93934297176SVladimir Oltean 	void	(*port_policer_del)(struct dsa_switch *ds, int port);
94047d23af2SVladimir Oltean 	int	(*port_setup_tc)(struct dsa_switch *ds, int port,
94147d23af2SVladimir Oltean 				 enum tc_setup_type type, void *type_data);
94240ef2c93SVivien Didelot 
94340ef2c93SVivien Didelot 	/*
94440ef2c93SVivien Didelot 	 * Cross-chip operations
94540ef2c93SVivien Didelot 	 */
946f66a6a69SVladimir Oltean 	int	(*crosschip_bridge_join)(struct dsa_switch *ds, int tree_index,
947f66a6a69SVladimir Oltean 					 int sw_index, int port,
948d3eed0e5SVladimir Oltean 					 struct dsa_bridge bridge);
949f66a6a69SVladimir Oltean 	void	(*crosschip_bridge_leave)(struct dsa_switch *ds, int tree_index,
950f66a6a69SVladimir Oltean 					  int sw_index, int port,
951d3eed0e5SVladimir Oltean 					  struct dsa_bridge bridge);
952058102a6STobias Waldekranz 	int	(*crosschip_lag_change)(struct dsa_switch *ds, int sw_index,
953058102a6STobias Waldekranz 					int port);
954058102a6STobias Waldekranz 	int	(*crosschip_lag_join)(struct dsa_switch *ds, int sw_index,
955058102a6STobias Waldekranz 				      int port, struct net_device *lag,
956058102a6STobias Waldekranz 				      struct netdev_lag_upper_info *info);
957058102a6STobias Waldekranz 	int	(*crosschip_lag_leave)(struct dsa_switch *ds, int sw_index,
958058102a6STobias Waldekranz 				       int port, struct net_device *lag);
9590336369dSBrandon Streiff 
9600336369dSBrandon Streiff 	/*
9610336369dSBrandon Streiff 	 * PTP functionality
9620336369dSBrandon Streiff 	 */
9630336369dSBrandon Streiff 	int	(*port_hwtstamp_get)(struct dsa_switch *ds, int port,
9640336369dSBrandon Streiff 				     struct ifreq *ifr);
9650336369dSBrandon Streiff 	int	(*port_hwtstamp_set)(struct dsa_switch *ds, int port,
9660336369dSBrandon Streiff 				     struct ifreq *ifr);
9675c5416f5SYangbo Lu 	void	(*port_txtstamp)(struct dsa_switch *ds, int port,
9685c5416f5SYangbo Lu 				 struct sk_buff *skb);
96990af1059SBrandon Streiff 	bool	(*port_rxtstamp)(struct dsa_switch *ds, int port,
97090af1059SBrandon Streiff 				 struct sk_buff *skb, unsigned int type);
97197a69a0dSVladimir Oltean 
9720f06b855SAndrew Lunn 	/* Devlink parameters, etc */
9736b297524SAndrew Lunn 	int	(*devlink_param_get)(struct dsa_switch *ds, u32 id,
9746b297524SAndrew Lunn 				     struct devlink_param_gset_ctx *ctx);
9756b297524SAndrew Lunn 	int	(*devlink_param_set)(struct dsa_switch *ds, u32 id,
9766b297524SAndrew Lunn 				     struct devlink_param_gset_ctx *ctx);
9770f06b855SAndrew Lunn 	int	(*devlink_info_get)(struct dsa_switch *ds,
9780f06b855SAndrew Lunn 				    struct devlink_info_req *req,
9790f06b855SAndrew Lunn 				    struct netlink_ext_ack *extack);
9802a6ef763SVladimir Oltean 	int	(*devlink_sb_pool_get)(struct dsa_switch *ds,
9812a6ef763SVladimir Oltean 				       unsigned int sb_index, u16 pool_index,
9822a6ef763SVladimir Oltean 				       struct devlink_sb_pool_info *pool_info);
9832a6ef763SVladimir Oltean 	int	(*devlink_sb_pool_set)(struct dsa_switch *ds, unsigned int sb_index,
9842a6ef763SVladimir Oltean 				       u16 pool_index, u32 size,
9852a6ef763SVladimir Oltean 				       enum devlink_sb_threshold_type threshold_type,
9862a6ef763SVladimir Oltean 				       struct netlink_ext_ack *extack);
9872a6ef763SVladimir Oltean 	int	(*devlink_sb_port_pool_get)(struct dsa_switch *ds, int port,
9882a6ef763SVladimir Oltean 					    unsigned int sb_index, u16 pool_index,
9892a6ef763SVladimir Oltean 					    u32 *p_threshold);
9902a6ef763SVladimir Oltean 	int	(*devlink_sb_port_pool_set)(struct dsa_switch *ds, int port,
9912a6ef763SVladimir Oltean 					    unsigned int sb_index, u16 pool_index,
9922a6ef763SVladimir Oltean 					    u32 threshold,
9932a6ef763SVladimir Oltean 					    struct netlink_ext_ack *extack);
9942a6ef763SVladimir Oltean 	int	(*devlink_sb_tc_pool_bind_get)(struct dsa_switch *ds, int port,
9952a6ef763SVladimir Oltean 					       unsigned int sb_index, u16 tc_index,
9962a6ef763SVladimir Oltean 					       enum devlink_sb_pool_type pool_type,
9972a6ef763SVladimir Oltean 					       u16 *p_pool_index, u32 *p_threshold);
9982a6ef763SVladimir Oltean 	int	(*devlink_sb_tc_pool_bind_set)(struct dsa_switch *ds, int port,
9992a6ef763SVladimir Oltean 					       unsigned int sb_index, u16 tc_index,
10002a6ef763SVladimir Oltean 					       enum devlink_sb_pool_type pool_type,
10012a6ef763SVladimir Oltean 					       u16 pool_index, u32 threshold,
10022a6ef763SVladimir Oltean 					       struct netlink_ext_ack *extack);
10032a6ef763SVladimir Oltean 	int	(*devlink_sb_occ_snapshot)(struct dsa_switch *ds,
10042a6ef763SVladimir Oltean 					   unsigned int sb_index);
10052a6ef763SVladimir Oltean 	int	(*devlink_sb_occ_max_clear)(struct dsa_switch *ds,
10062a6ef763SVladimir Oltean 					    unsigned int sb_index);
10072a6ef763SVladimir Oltean 	int	(*devlink_sb_occ_port_pool_get)(struct dsa_switch *ds, int port,
10082a6ef763SVladimir Oltean 						unsigned int sb_index, u16 pool_index,
10092a6ef763SVladimir Oltean 						u32 *p_cur, u32 *p_max);
10102a6ef763SVladimir Oltean 	int	(*devlink_sb_occ_tc_port_bind_get)(struct dsa_switch *ds, int port,
10112a6ef763SVladimir Oltean 						   unsigned int sb_index, u16 tc_index,
10122a6ef763SVladimir Oltean 						   enum devlink_sb_pool_type pool_type,
10132a6ef763SVladimir Oltean 						   u32 *p_cur, u32 *p_max);
1014bfcb8132SVladimir Oltean 
1015bfcb8132SVladimir Oltean 	/*
1016bfcb8132SVladimir Oltean 	 * MTU change functionality. Switches can also adjust their MRU through
1017bfcb8132SVladimir Oltean 	 * this method. By MTU, one understands the SDU (L2 payload) length.
1018bfcb8132SVladimir Oltean 	 * If the switch needs to account for the DSA tag on the CPU port, this
1019ab88d64aSRandy Dunlap 	 * method needs to do so privately.
1020bfcb8132SVladimir Oltean 	 */
1021bfcb8132SVladimir Oltean 	int	(*port_change_mtu)(struct dsa_switch *ds, int port,
1022bfcb8132SVladimir Oltean 				   int new_mtu);
1023bfcb8132SVladimir Oltean 	int	(*port_max_mtu)(struct dsa_switch *ds, int port);
1024058102a6STobias Waldekranz 
1025058102a6STobias Waldekranz 	/*
1026058102a6STobias Waldekranz 	 * LAG integration
1027058102a6STobias Waldekranz 	 */
1028058102a6STobias Waldekranz 	int	(*port_lag_change)(struct dsa_switch *ds, int port);
1029058102a6STobias Waldekranz 	int	(*port_lag_join)(struct dsa_switch *ds, int port,
1030058102a6STobias Waldekranz 				 struct net_device *lag,
1031058102a6STobias Waldekranz 				 struct netdev_lag_upper_info *info);
1032058102a6STobias Waldekranz 	int	(*port_lag_leave)(struct dsa_switch *ds, int port,
1033058102a6STobias Waldekranz 				  struct net_device *lag);
103418596f50SGeorge McCollister 
103518596f50SGeorge McCollister 	/*
103618596f50SGeorge McCollister 	 * HSR integration
103718596f50SGeorge McCollister 	 */
103818596f50SGeorge McCollister 	int	(*port_hsr_join)(struct dsa_switch *ds, int port,
103918596f50SGeorge McCollister 				 struct net_device *hsr);
104018596f50SGeorge McCollister 	int	(*port_hsr_leave)(struct dsa_switch *ds, int port,
104118596f50SGeorge McCollister 				  struct net_device *hsr);
1042c595c433SHoratiu Vultur 
1043c595c433SHoratiu Vultur 	/*
1044c595c433SHoratiu Vultur 	 * MRP integration
1045c595c433SHoratiu Vultur 	 */
1046c595c433SHoratiu Vultur 	int	(*port_mrp_add)(struct dsa_switch *ds, int port,
1047c595c433SHoratiu Vultur 				const struct switchdev_obj_mrp *mrp);
1048c595c433SHoratiu Vultur 	int	(*port_mrp_del)(struct dsa_switch *ds, int port,
1049c595c433SHoratiu Vultur 				const struct switchdev_obj_mrp *mrp);
1050c595c433SHoratiu Vultur 	int	(*port_mrp_add_ring_role)(struct dsa_switch *ds, int port,
1051c595c433SHoratiu Vultur 					  const struct switchdev_obj_ring_role_mrp *mrp);
1052c595c433SHoratiu Vultur 	int	(*port_mrp_del_ring_role)(struct dsa_switch *ds, int port,
1053c595c433SHoratiu Vultur 					  const struct switchdev_obj_ring_role_mrp *mrp);
10545da11eb4SVladimir Oltean 
10555da11eb4SVladimir Oltean 	/*
10565da11eb4SVladimir Oltean 	 * tag_8021q operations
10575da11eb4SVladimir Oltean 	 */
10585da11eb4SVladimir Oltean 	int	(*tag_8021q_vlan_add)(struct dsa_switch *ds, int port, u16 vid,
10595da11eb4SVladimir Oltean 				      u16 flags);
10605da11eb4SVladimir Oltean 	int	(*tag_8021q_vlan_del)(struct dsa_switch *ds, int port, u16 vid);
1061295ab96fSVladimir Oltean 
1062295ab96fSVladimir Oltean 	/*
1063295ab96fSVladimir Oltean 	 * DSA master tracking operations
1064295ab96fSVladimir Oltean 	 */
1065295ab96fSVladimir Oltean 	void	(*master_state_change)(struct dsa_switch *ds,
1066295ab96fSVladimir Oltean 				       const struct net_device *master,
1067295ab96fSVladimir Oltean 				       bool operational);
10686b297524SAndrew Lunn };
10696b297524SAndrew Lunn 
10706b297524SAndrew Lunn #define DSA_DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes)		\
10716b297524SAndrew Lunn 	DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes,		\
10726b297524SAndrew Lunn 			     dsa_devlink_param_get, dsa_devlink_param_set, NULL)
10736b297524SAndrew Lunn 
10746b297524SAndrew Lunn int dsa_devlink_param_get(struct devlink *dl, u32 id,
10756b297524SAndrew Lunn 			  struct devlink_param_gset_ctx *ctx);
10766b297524SAndrew Lunn int dsa_devlink_param_set(struct devlink *dl, u32 id,
10776b297524SAndrew Lunn 			  struct devlink_param_gset_ctx *ctx);
10786b297524SAndrew Lunn int dsa_devlink_params_register(struct dsa_switch *ds,
10796b297524SAndrew Lunn 				const struct devlink_param *params,
10806b297524SAndrew Lunn 				size_t params_count);
10816b297524SAndrew Lunn void dsa_devlink_params_unregister(struct dsa_switch *ds,
10826b297524SAndrew Lunn 				   const struct devlink_param *params,
10836b297524SAndrew Lunn 				   size_t params_count);
10845cd73fbdSAndrew Lunn int dsa_devlink_resource_register(struct dsa_switch *ds,
10855cd73fbdSAndrew Lunn 				  const char *resource_name,
10865cd73fbdSAndrew Lunn 				  u64 resource_size,
10875cd73fbdSAndrew Lunn 				  u64 resource_id,
10885cd73fbdSAndrew Lunn 				  u64 parent_resource_id,
10895cd73fbdSAndrew Lunn 				  const struct devlink_resource_size_params *size_params);
10905cd73fbdSAndrew Lunn 
10915cd73fbdSAndrew Lunn void dsa_devlink_resources_unregister(struct dsa_switch *ds);
10925cd73fbdSAndrew Lunn 
10935cd73fbdSAndrew Lunn void dsa_devlink_resource_occ_get_register(struct dsa_switch *ds,
10945cd73fbdSAndrew Lunn 					   u64 resource_id,
10955cd73fbdSAndrew Lunn 					   devlink_resource_occ_get_t *occ_get,
10965cd73fbdSAndrew Lunn 					   void *occ_get_priv);
10975cd73fbdSAndrew Lunn void dsa_devlink_resource_occ_get_unregister(struct dsa_switch *ds,
10985cd73fbdSAndrew Lunn 					     u64 resource_id);
109997c82c23SAndrew Lunn struct devlink_region *
110097c82c23SAndrew Lunn dsa_devlink_region_create(struct dsa_switch *ds,
110197c82c23SAndrew Lunn 			  const struct devlink_region_ops *ops,
110297c82c23SAndrew Lunn 			  u32 region_max_snapshots, u64 region_size);
110308156ba4SAndrew Lunn struct devlink_region *
110408156ba4SAndrew Lunn dsa_devlink_port_region_create(struct dsa_switch *ds,
110508156ba4SAndrew Lunn 			       int port,
110608156ba4SAndrew Lunn 			       const struct devlink_port_region_ops *ops,
110708156ba4SAndrew Lunn 			       u32 region_max_snapshots, u64 region_size);
110897c82c23SAndrew Lunn void dsa_devlink_region_destroy(struct devlink_region *region);
110997c82c23SAndrew Lunn 
1110e1eea811SVladimir Oltean struct dsa_port *dsa_port_from_netdev(struct net_device *netdev);
11115cd73fbdSAndrew Lunn 
11126b297524SAndrew Lunn struct dsa_devlink_priv {
11136b297524SAndrew Lunn 	struct dsa_switch *ds;
1114c8f0b869SBen Hutchings };
1115c8f0b869SBen Hutchings 
1116ccc3e6b0SAndrew Lunn static inline struct dsa_switch *dsa_devlink_to_ds(struct devlink *dl)
1117ccc3e6b0SAndrew Lunn {
1118ccc3e6b0SAndrew Lunn 	struct dsa_devlink_priv *dl_priv = devlink_priv(dl);
1119ccc3e6b0SAndrew Lunn 
1120ccc3e6b0SAndrew Lunn 	return dl_priv->ds;
1121ccc3e6b0SAndrew Lunn }
1122ccc3e6b0SAndrew Lunn 
11237d1e2a10SAndrew Lunn static inline
11247d1e2a10SAndrew Lunn struct dsa_switch *dsa_devlink_port_to_ds(struct devlink_port *port)
11257d1e2a10SAndrew Lunn {
11267d1e2a10SAndrew Lunn 	struct devlink *dl = port->devlink;
11277d1e2a10SAndrew Lunn 	struct dsa_devlink_priv *dl_priv = devlink_priv(dl);
11287d1e2a10SAndrew Lunn 
11297d1e2a10SAndrew Lunn 	return dl_priv->ds;
11307d1e2a10SAndrew Lunn }
11317d1e2a10SAndrew Lunn 
11327d1e2a10SAndrew Lunn static inline int dsa_devlink_port_to_port(struct devlink_port *port)
11337d1e2a10SAndrew Lunn {
11347d1e2a10SAndrew Lunn 	return port->index;
11357d1e2a10SAndrew Lunn }
11367d1e2a10SAndrew Lunn 
1137ab3d408dSFlorian Fainelli struct dsa_switch_driver {
1138ab3d408dSFlorian Fainelli 	struct list_head	list;
1139a82f67afSFlorian Fainelli 	const struct dsa_switch_ops *ops;
1140ab3d408dSFlorian Fainelli };
1141ab3d408dSFlorian Fainelli 
114214b89f36SFlorian Fainelli struct net_device *dsa_dev_to_net_device(struct device *dev);
1143c8f0b869SBen Hutchings 
114473a7ece8SVivien Didelot /* Keep inline for faster access in hot path */
11459eb8eff0SVladimir Oltean static inline bool netdev_uses_dsa(const struct net_device *dev)
1146c6e970a0SAndrew Lunn {
1147c6e970a0SAndrew Lunn #if IS_ENABLED(CONFIG_NET_DSA)
1148717ffbfbSVivien Didelot 	return dev->dsa_ptr && dev->dsa_ptr->rcv;
1149c6e970a0SAndrew Lunn #endif
1150c6e970a0SAndrew Lunn 	return false;
1151c6e970a0SAndrew Lunn }
1152c6e970a0SAndrew Lunn 
11539790cf20SVladimir Oltean /* All DSA tags that push the EtherType to the right (basically all except tail
11549790cf20SVladimir Oltean  * tags, which don't break dissection) can be treated the same from the
11559790cf20SVladimir Oltean  * perspective of the flow dissector.
11569790cf20SVladimir Oltean  *
11579790cf20SVladimir Oltean  * We need to return:
11589790cf20SVladimir Oltean  *  - offset: the (B - A) difference between:
11599790cf20SVladimir Oltean  *    A. the position of the real EtherType and
11609790cf20SVladimir Oltean  *    B. the current skb->data (aka ETH_HLEN bytes into the frame, aka 2 bytes
11619790cf20SVladimir Oltean  *       after the normal EtherType was supposed to be)
11629790cf20SVladimir Oltean  *    The offset in bytes is exactly equal to the tagger overhead (and half of
11639790cf20SVladimir Oltean  *    that, in __be16 shorts).
11649790cf20SVladimir Oltean  *
11659790cf20SVladimir Oltean  *  - proto: the value of the real EtherType.
11669790cf20SVladimir Oltean  */
11679790cf20SVladimir Oltean static inline void dsa_tag_generic_flow_dissect(const struct sk_buff *skb,
11689790cf20SVladimir Oltean 						__be16 *proto, int *offset)
11699790cf20SVladimir Oltean {
11709790cf20SVladimir Oltean #if IS_ENABLED(CONFIG_NET_DSA)
11719790cf20SVladimir Oltean 	const struct dsa_device_ops *ops = skb->dev->dsa_ptr->tag_ops;
11724e500251SVladimir Oltean 	int tag_len = ops->needed_headroom;
11739790cf20SVladimir Oltean 
11749790cf20SVladimir Oltean 	*offset = tag_len;
11759790cf20SVladimir Oltean 	*proto = ((__be16 *)skb->data)[(tag_len / 2) - 1];
11769790cf20SVladimir Oltean #endif
11779790cf20SVladimir Oltean }
11789790cf20SVladimir Oltean 
11794cfab356SFlorian Fainelli #if IS_ENABLED(CONFIG_NET_DSA)
11804cfab356SFlorian Fainelli static inline int __dsa_netdevice_ops_check(struct net_device *dev)
11814cfab356SFlorian Fainelli {
11824cfab356SFlorian Fainelli 	int err = -EOPNOTSUPP;
11834cfab356SFlorian Fainelli 
11844cfab356SFlorian Fainelli 	if (!dev->dsa_ptr)
11854cfab356SFlorian Fainelli 		return err;
11864cfab356SFlorian Fainelli 
11874cfab356SFlorian Fainelli 	if (!dev->dsa_ptr->netdev_ops)
11884cfab356SFlorian Fainelli 		return err;
11894cfab356SFlorian Fainelli 
11904cfab356SFlorian Fainelli 	return 0;
11914cfab356SFlorian Fainelli }
11924cfab356SFlorian Fainelli 
1193a7605370SArnd Bergmann static inline int dsa_ndo_eth_ioctl(struct net_device *dev, struct ifreq *ifr,
11944cfab356SFlorian Fainelli 				    int cmd)
11954cfab356SFlorian Fainelli {
11964cfab356SFlorian Fainelli 	const struct dsa_netdevice_ops *ops;
11974cfab356SFlorian Fainelli 	int err;
11984cfab356SFlorian Fainelli 
11994cfab356SFlorian Fainelli 	err = __dsa_netdevice_ops_check(dev);
12004cfab356SFlorian Fainelli 	if (err)
12014cfab356SFlorian Fainelli 		return err;
12024cfab356SFlorian Fainelli 
12034cfab356SFlorian Fainelli 	ops = dev->dsa_ptr->netdev_ops;
12044cfab356SFlorian Fainelli 
1205a7605370SArnd Bergmann 	return ops->ndo_eth_ioctl(dev, ifr, cmd);
12064cfab356SFlorian Fainelli }
12074cfab356SFlorian Fainelli #else
1208a7605370SArnd Bergmann static inline int dsa_ndo_eth_ioctl(struct net_device *dev, struct ifreq *ifr,
12094cfab356SFlorian Fainelli 				    int cmd)
12104cfab356SFlorian Fainelli {
12114cfab356SFlorian Fainelli 	return -EOPNOTSUPP;
12124cfab356SFlorian Fainelli }
12134cfab356SFlorian Fainelli #endif
12144cfab356SFlorian Fainelli 
121583c0afaeSAndrew Lunn void dsa_unregister_switch(struct dsa_switch *ds);
121623c9ee49SVivien Didelot int dsa_register_switch(struct dsa_switch *ds);
12170650bf52SVladimir Oltean void dsa_switch_shutdown(struct dsa_switch *ds);
12183b7bc1f0SVladimir Oltean struct dsa_switch *dsa_switch_find(int tree_index, int sw_index);
1219ea825e70SFlorian Fainelli #ifdef CONFIG_PM_SLEEP
1220ea825e70SFlorian Fainelli int dsa_switch_suspend(struct dsa_switch *ds);
1221ea825e70SFlorian Fainelli int dsa_switch_resume(struct dsa_switch *ds);
1222ea825e70SFlorian Fainelli #else
1223ea825e70SFlorian Fainelli static inline int dsa_switch_suspend(struct dsa_switch *ds)
1224ea825e70SFlorian Fainelli {
1225ea825e70SFlorian Fainelli 	return 0;
1226ea825e70SFlorian Fainelli }
1227ea825e70SFlorian Fainelli static inline int dsa_switch_resume(struct dsa_switch *ds)
1228ea825e70SFlorian Fainelli {
1229ea825e70SFlorian Fainelli 	return 0;
1230ea825e70SFlorian Fainelli }
1231ea825e70SFlorian Fainelli #endif /* CONFIG_PM_SLEEP */
1232ea825e70SFlorian Fainelli 
123360724d4bSFlorian Fainelli #if IS_ENABLED(CONFIG_NET_DSA)
1234a5e3c9baSVladimir Oltean bool dsa_slave_dev_check(const struct net_device *dev);
123560724d4bSFlorian Fainelli #else
1236a5e3c9baSVladimir Oltean static inline bool dsa_slave_dev_check(const struct net_device *dev)
1237a5e3c9baSVladimir Oltean {
1238a5e3c9baSVladimir Oltean 	return false;
1239a5e3c9baSVladimir Oltean }
124060724d4bSFlorian Fainelli #endif
124160724d4bSFlorian Fainelli 
124297a69a0dSVladimir Oltean netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, struct net_device *dev);
1243cf963573SFlorian Fainelli int dsa_port_get_phy_strings(struct dsa_port *dp, uint8_t *data);
1244cf963573SFlorian Fainelli int dsa_port_get_ethtool_phy_stats(struct dsa_port *dp, uint64_t *data);
1245cf963573SFlorian Fainelli int dsa_port_get_phy_sset_count(struct dsa_port *dp);
124611d8f3ddSFlorian Fainelli void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up);
1247cf963573SFlorian Fainelli 
1248d3b8c049SAndrew Lunn struct dsa_tag_driver {
1249d3b8c049SAndrew Lunn 	const struct dsa_device_ops *ops;
1250d3b8c049SAndrew Lunn 	struct list_head list;
1251d3b8c049SAndrew Lunn 	struct module *owner;
1252d3b8c049SAndrew Lunn };
1253d3b8c049SAndrew Lunn 
1254d3b8c049SAndrew Lunn void dsa_tag_drivers_register(struct dsa_tag_driver *dsa_tag_driver_array[],
1255d3b8c049SAndrew Lunn 			      unsigned int count,
1256d3b8c049SAndrew Lunn 			      struct module *owner);
1257d3b8c049SAndrew Lunn void dsa_tag_drivers_unregister(struct dsa_tag_driver *dsa_tag_driver_array[],
1258d3b8c049SAndrew Lunn 				unsigned int count);
1259d3b8c049SAndrew Lunn 
1260d3b8c049SAndrew Lunn #define dsa_tag_driver_module_drivers(__dsa_tag_drivers_array, __count)	\
1261d3b8c049SAndrew Lunn static int __init dsa_tag_driver_module_init(void)			\
1262d3b8c049SAndrew Lunn {									\
1263d3b8c049SAndrew Lunn 	dsa_tag_drivers_register(__dsa_tag_drivers_array, __count,	\
1264d3b8c049SAndrew Lunn 				 THIS_MODULE);				\
1265d3b8c049SAndrew Lunn 	return 0;							\
1266d3b8c049SAndrew Lunn }									\
1267d3b8c049SAndrew Lunn module_init(dsa_tag_driver_module_init);				\
1268d3b8c049SAndrew Lunn 									\
1269d3b8c049SAndrew Lunn static void __exit dsa_tag_driver_module_exit(void)			\
1270d3b8c049SAndrew Lunn {									\
1271d3b8c049SAndrew Lunn 	dsa_tag_drivers_unregister(__dsa_tag_drivers_array, __count);	\
1272d3b8c049SAndrew Lunn }									\
1273d3b8c049SAndrew Lunn module_exit(dsa_tag_driver_module_exit)
1274d3b8c049SAndrew Lunn 
1275d3b8c049SAndrew Lunn /**
1276d3b8c049SAndrew Lunn  * module_dsa_tag_drivers() - Helper macro for registering DSA tag
1277d3b8c049SAndrew Lunn  * drivers
1278d3b8c049SAndrew Lunn  * @__ops_array: Array of tag driver strucutres
1279d3b8c049SAndrew Lunn  *
1280d3b8c049SAndrew Lunn  * Helper macro for DSA tag drivers which do not do anything special
1281d3b8c049SAndrew Lunn  * in module init/exit. Each module may only use this macro once, and
1282d3b8c049SAndrew Lunn  * calling it replaces module_init() and module_exit().
1283d3b8c049SAndrew Lunn  */
1284d3b8c049SAndrew Lunn #define module_dsa_tag_drivers(__ops_array)				\
1285d3b8c049SAndrew Lunn dsa_tag_driver_module_drivers(__ops_array, ARRAY_SIZE(__ops_array))
1286d3b8c049SAndrew Lunn 
1287d3b8c049SAndrew Lunn #define DSA_TAG_DRIVER_NAME(__ops) dsa_tag_driver ## _ ## __ops
1288d3b8c049SAndrew Lunn 
1289d3b8c049SAndrew Lunn /* Create a static structure we can build a linked list of dsa_tag
1290d3b8c049SAndrew Lunn  * drivers
1291d3b8c049SAndrew Lunn  */
1292d3b8c049SAndrew Lunn #define DSA_TAG_DRIVER(__ops)						\
1293d3b8c049SAndrew Lunn static struct dsa_tag_driver DSA_TAG_DRIVER_NAME(__ops) = {		\
1294d3b8c049SAndrew Lunn 	.ops = &__ops,							\
1295d3b8c049SAndrew Lunn }
1296d3b8c049SAndrew Lunn 
1297d3b8c049SAndrew Lunn /**
1298d3b8c049SAndrew Lunn  * module_dsa_tag_driver() - Helper macro for registering a single DSA tag
1299d3b8c049SAndrew Lunn  * driver
1300d3b8c049SAndrew Lunn  * @__ops: Single tag driver structures
1301d3b8c049SAndrew Lunn  *
1302d3b8c049SAndrew Lunn  * Helper macro for DSA tag drivers which do not do anything special
1303d3b8c049SAndrew Lunn  * in module init/exit. Each module may only use this macro once, and
1304d3b8c049SAndrew Lunn  * calling it replaces module_init() and module_exit().
1305d3b8c049SAndrew Lunn  */
1306d3b8c049SAndrew Lunn #define module_dsa_tag_driver(__ops)					\
1307d3b8c049SAndrew Lunn DSA_TAG_DRIVER(__ops);							\
1308d3b8c049SAndrew Lunn 									\
1309d3b8c049SAndrew Lunn static struct dsa_tag_driver *dsa_tag_driver_array[] =	{		\
1310d3b8c049SAndrew Lunn 	&DSA_TAG_DRIVER_NAME(__ops)					\
1311d3b8c049SAndrew Lunn };									\
1312d3b8c049SAndrew Lunn module_dsa_tag_drivers(dsa_tag_driver_array)
131391da11f8SLennert Buytenhek #endif
1314d3b8c049SAndrew Lunn 
1315