xref: /openbmc/linux/include/net/dsa.h (revision 134ef238)
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;
315*134ef238SVladimir Oltean 
316*134ef238SVladimir Oltean 	/* List of VLANs that CPU and DSA ports are members of. */
317*134ef238SVladimir Oltean 	struct mutex		vlans_lock;
318*134ef238SVladimir Oltean 	struct list_head	vlans;
319c8b09808SAndrew Lunn };
320c8b09808SAndrew Lunn 
321c5f51765SVivien Didelot /* TODO: ideally DSA ports would have a single dp->link_dp member,
322c5f51765SVivien Didelot  * and no dst->rtable nor this struct dsa_link would be needed,
323c5f51765SVivien Didelot  * but this would require some more complex tree walking,
324c5f51765SVivien Didelot  * so keep it stupid at the moment and list them all.
325c5f51765SVivien Didelot  */
326c5f51765SVivien Didelot struct dsa_link {
327c5f51765SVivien Didelot 	struct dsa_port *dp;
328c5f51765SVivien Didelot 	struct dsa_port *link_dp;
329c5f51765SVivien Didelot 	struct list_head list;
330c5f51765SVivien Didelot };
331c5f51765SVivien Didelot 
332161ca59dSVladimir Oltean struct dsa_mac_addr {
333161ca59dSVladimir Oltean 	unsigned char addr[ETH_ALEN];
334161ca59dSVladimir Oltean 	u16 vid;
335161ca59dSVladimir Oltean 	refcount_t refcount;
336161ca59dSVladimir Oltean 	struct list_head list;
337161ca59dSVladimir Oltean };
338161ca59dSVladimir Oltean 
339*134ef238SVladimir Oltean struct dsa_vlan {
340*134ef238SVladimir Oltean 	u16 vid;
341*134ef238SVladimir Oltean 	refcount_t refcount;
342*134ef238SVladimir Oltean 	struct list_head list;
343*134ef238SVladimir Oltean };
344*134ef238SVladimir Oltean 
345c8f0b869SBen Hutchings struct dsa_switch {
346c33063d6SAndrew Lunn 	struct device *dev;
347c33063d6SAndrew Lunn 
348c8f0b869SBen Hutchings 	/*
349c8f0b869SBen Hutchings 	 * Parent switch tree, and switch index.
350c8f0b869SBen Hutchings 	 */
351c8f0b869SBen Hutchings 	struct dsa_switch_tree	*dst;
35299feaafcSVivien Didelot 	unsigned int		index;
353c8f0b869SBen Hutchings 
3541b26d364SVladimir Oltean 	/* Warning: the following bit fields are not atomic, and updating them
3551b26d364SVladimir Oltean 	 * can only be done from code paths where concurrency is not possible
3561b26d364SVladimir Oltean 	 * (probe time or under rtnl_lock).
3571b26d364SVladimir Oltean 	 */
35863cfc657SVladimir Oltean 	u32			setup:1;
35963cfc657SVladimir Oltean 
36063cfc657SVladimir Oltean 	/* Disallow bridge core from requesting different VLAN awareness
36163cfc657SVladimir Oltean 	 * settings on ports if not hardware-supported
3627787ff77SVladimir Oltean 	 */
36363cfc657SVladimir Oltean 	u32			vlan_filtering_is_global:1;
36463cfc657SVladimir Oltean 
36563cfc657SVladimir Oltean 	/* Keep VLAN filtering enabled on ports not offloading any upper */
36663cfc657SVladimir Oltean 	u32			needs_standalone_vlan_filtering:1;
36763cfc657SVladimir Oltean 
36863cfc657SVladimir Oltean 	/* Pass .port_vlan_add and .port_vlan_del to drivers even for bridges
36963cfc657SVladimir Oltean 	 * that have vlan_filtering=0. All drivers should ideally set this (and
37063cfc657SVladimir Oltean 	 * then the option would get removed), but it is unknown whether this
3717787ff77SVladimir Oltean 	 * would break things or not.
3727787ff77SVladimir Oltean 	 */
37363cfc657SVladimir Oltean 	u32			configure_vlan_while_not_filtering:1;
37463cfc657SVladimir Oltean 
37563cfc657SVladimir Oltean 	/* If the switch driver always programs the CPU port as egress tagged
37663cfc657SVladimir Oltean 	 * despite the VLAN configuration indicating otherwise, then setting
37763cfc657SVladimir Oltean 	 * @untag_bridge_pvid will force the DSA receive path to pop the
37863cfc657SVladimir Oltean 	 * bridge's default_pvid VLAN tagged frames to offer a consistent
37963cfc657SVladimir Oltean 	 * behavior between a vlan_filtering=0 and vlan_filtering=1 bridge
3807787ff77SVladimir Oltean 	 * device.
3817787ff77SVladimir Oltean 	 */
38263cfc657SVladimir Oltean 	u32			untag_bridge_pvid:1;
38363cfc657SVladimir Oltean 
3847787ff77SVladimir Oltean 	/* Let DSA manage the FDB entries towards the
3857787ff77SVladimir Oltean 	 * CPU, based on the software bridge database.
3867787ff77SVladimir Oltean 	 */
38763cfc657SVladimir Oltean 	u32			assisted_learning_on_cpu_port:1;
38863cfc657SVladimir Oltean 
38963cfc657SVladimir Oltean 	/* In case vlan_filtering_is_global is set, the VLAN awareness state
39063cfc657SVladimir Oltean 	 * should be retrieved from here and not from the per-port settings.
3917787ff77SVladimir Oltean 	 */
39263cfc657SVladimir Oltean 	u32			vlan_filtering:1;
39363cfc657SVladimir Oltean 
39463cfc657SVladimir Oltean 	/* MAC PCS does not provide link state change interrupt, and requires
39563cfc657SVladimir Oltean 	 * polling. Flag passed on to PHYLINK.
3967787ff77SVladimir Oltean 	 */
39763cfc657SVladimir Oltean 	u32			pcs_poll:1;
39863cfc657SVladimir Oltean 
39963cfc657SVladimir Oltean 	/* For switches that only have the MRU configurable. To ensure the
40063cfc657SVladimir Oltean 	 * configured MTU is not exceeded, normalization of MRU on all bridged
40163cfc657SVladimir Oltean 	 * interfaces is needed.
4027787ff77SVladimir Oltean 	 */
40363cfc657SVladimir Oltean 	u32			mtu_enforcement_ingress:1;
4047787ff77SVladimir Oltean 
405f515f192SVivien Didelot 	/* Listener for switch fabric events */
406f515f192SVivien Didelot 	struct notifier_block	nb;
407f515f192SVivien Didelot 
408c8f0b869SBen Hutchings 	/*
4097543a6d5SAndrew Lunn 	 * Give the switch driver somewhere to hang its private data
4107543a6d5SAndrew Lunn 	 * structure.
4117543a6d5SAndrew Lunn 	 */
4127543a6d5SAndrew Lunn 	void *priv;
4137543a6d5SAndrew Lunn 
414dc452a47SVladimir Oltean 	void *tagger_data;
415dc452a47SVladimir Oltean 
4167543a6d5SAndrew Lunn 	/*
417c8f0b869SBen Hutchings 	 * Configuration data for this switch.
418c8f0b869SBen Hutchings 	 */
419ff04955cSAndrew Lunn 	struct dsa_chip_data	*cd;
420c8f0b869SBen Hutchings 
421c8f0b869SBen Hutchings 	/*
4229d490b4eSVivien Didelot 	 * The switch operations.
423c8f0b869SBen Hutchings 	 */
424a82f67afSFlorian Fainelli 	const struct dsa_switch_ops	*ops;
425c8f0b869SBen Hutchings 
42666472fc0SAndrew Lunn 	/*
427c8f0b869SBen Hutchings 	 * Slave mii_bus and devices for the individual ports.
428c8f0b869SBen Hutchings 	 */
4290d8bcdd3SFlorian Fainelli 	u32			phys_mii_mask;
430c8f0b869SBen Hutchings 	struct mii_bus		*slave_mii_bus;
431a0c02161SVivien Didelot 
4320f3da6afSVivien Didelot 	/* Ageing Time limits in msecs */
4330f3da6afSVivien Didelot 	unsigned int ageing_time_min;
4340f3da6afSVivien Didelot 	unsigned int ageing_time_max;
4350f3da6afSVivien Didelot 
436d7b1fd52SVladimir Oltean 	/* Storage for drivers using tag_8021q */
437d7b1fd52SVladimir Oltean 	struct dsa_8021q_context *tag_8021q_ctx;
438d7b1fd52SVladimir Oltean 
43996567d5dSAndrew Lunn 	/* devlink used to represent this switch device */
44096567d5dSAndrew Lunn 	struct devlink		*devlink;
44196567d5dSAndrew Lunn 
44255199df6SFlorian Fainelli 	/* Number of switch port queues */
44355199df6SFlorian Fainelli 	unsigned int		num_tx_queues;
44455199df6SFlorian Fainelli 
445058102a6STobias Waldekranz 	/* Drivers that benefit from having an ID associated with each
446058102a6STobias Waldekranz 	 * offloaded LAG should set this to the maximum number of
447058102a6STobias Waldekranz 	 * supported IDs. DSA will then maintain a mapping of _at
448058102a6STobias Waldekranz 	 * least_ these many IDs, accessible to drivers via
449058102a6STobias Waldekranz 	 * dsa_lag_id().
450058102a6STobias Waldekranz 	 */
451058102a6STobias Waldekranz 	unsigned int		num_lag_ids;
452058102a6STobias Waldekranz 
453947c8746SVladimir Oltean 	/* Drivers that support bridge forwarding offload or FDB isolation
454947c8746SVladimir Oltean 	 * should set this to the maximum number of bridges spanning the same
455947c8746SVladimir Oltean 	 * switch tree (or all trees, in the case of cross-tree bridging
456947c8746SVladimir Oltean 	 * support) that can be offloaded.
457123abc06SVladimir Oltean 	 */
458947c8746SVladimir Oltean 	unsigned int		max_num_bridges;
459123abc06SVladimir Oltean 
460258030acSVladimir Oltean 	unsigned int		num_ports;
461c8f0b869SBen Hutchings };
462c8f0b869SBen Hutchings 
46368bb8ea8SVivien Didelot static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p)
464c38c5a66SVivien Didelot {
465b96ddf25SVivien Didelot 	struct dsa_switch_tree *dst = ds->dst;
466d607525bSVivien Didelot 	struct dsa_port *dp;
467b96ddf25SVivien Didelot 
468b96ddf25SVivien Didelot 	list_for_each_entry(dp, &dst->ports, list)
469b96ddf25SVivien Didelot 		if (dp->ds == ds && dp->index == p)
470b96ddf25SVivien Didelot 			return dp;
471d607525bSVivien Didelot 
472d607525bSVivien Didelot 	return NULL;
473c38c5a66SVivien Didelot }
474c38c5a66SVivien Didelot 
475a8986681SVladimir Oltean static inline bool dsa_port_is_dsa(struct dsa_port *port)
476a8986681SVladimir Oltean {
477a8986681SVladimir Oltean 	return port->type == DSA_PORT_TYPE_DSA;
478a8986681SVladimir Oltean }
479a8986681SVladimir Oltean 
480a8986681SVladimir Oltean static inline bool dsa_port_is_cpu(struct dsa_port *port)
481a8986681SVladimir Oltean {
482a8986681SVladimir Oltean 	return port->type == DSA_PORT_TYPE_CPU;
483a8986681SVladimir Oltean }
484a8986681SVladimir Oltean 
485a8986681SVladimir Oltean static inline bool dsa_port_is_user(struct dsa_port *dp)
486a8986681SVladimir Oltean {
487a8986681SVladimir Oltean 	return dp->type == DSA_PORT_TYPE_USER;
488a8986681SVladimir Oltean }
489a8986681SVladimir Oltean 
490a57d8c21SVladimir Oltean static inline bool dsa_port_is_unused(struct dsa_port *dp)
491a57d8c21SVladimir Oltean {
492a57d8c21SVladimir Oltean 	return dp->type == DSA_PORT_TYPE_UNUSED;
493a57d8c21SVladimir Oltean }
494a57d8c21SVladimir Oltean 
495295ab96fSVladimir Oltean static inline bool dsa_port_master_is_operational(struct dsa_port *dp)
496295ab96fSVladimir Oltean {
497295ab96fSVladimir Oltean 	return dsa_port_is_cpu(dp) && dp->master_admin_up &&
498295ab96fSVladimir Oltean 	       dp->master_oper_up;
499295ab96fSVladimir Oltean }
500295ab96fSVladimir Oltean 
501bff7b688SVivien Didelot static inline bool dsa_is_unused_port(struct dsa_switch *ds, int p)
502bff7b688SVivien Didelot {
503c38c5a66SVivien Didelot 	return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_UNUSED;
504bff7b688SVivien Didelot }
505bff7b688SVivien Didelot 
506c8f0b869SBen Hutchings static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
507c8f0b869SBen Hutchings {
508c38c5a66SVivien Didelot 	return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_CPU;
509c8f0b869SBen Hutchings }
510c8f0b869SBen Hutchings 
51160045cbfSAndrew Lunn static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p)
51260045cbfSAndrew Lunn {
513c38c5a66SVivien Didelot 	return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_DSA;
51460045cbfSAndrew Lunn }
51560045cbfSAndrew Lunn 
5162b3e9891SVivien Didelot static inline bool dsa_is_user_port(struct dsa_switch *ds, int p)
5176cd456f3SVivien Didelot {
518c38c5a66SVivien Didelot 	return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_USER;
5196cd456f3SVivien Didelot }
5206cd456f3SVivien Didelot 
52182b31898SVladimir Oltean #define dsa_tree_for_each_user_port(_dp, _dst) \
52282b31898SVladimir Oltean 	list_for_each_entry((_dp), &(_dst)->ports, list) \
52382b31898SVladimir Oltean 		if (dsa_port_is_user((_dp)))
52482b31898SVladimir Oltean 
52582b31898SVladimir Oltean #define dsa_switch_for_each_port(_dp, _ds) \
52682b31898SVladimir Oltean 	list_for_each_entry((_dp), &(_ds)->dst->ports, list) \
52782b31898SVladimir Oltean 		if ((_dp)->ds == (_ds))
52882b31898SVladimir Oltean 
52982b31898SVladimir Oltean #define dsa_switch_for_each_port_safe(_dp, _next, _ds) \
53082b31898SVladimir Oltean 	list_for_each_entry_safe((_dp), (_next), &(_ds)->dst->ports, list) \
53182b31898SVladimir Oltean 		if ((_dp)->ds == (_ds))
53282b31898SVladimir Oltean 
53382b31898SVladimir Oltean #define dsa_switch_for_each_port_continue_reverse(_dp, _ds) \
53482b31898SVladimir Oltean 	list_for_each_entry_continue_reverse((_dp), &(_ds)->dst->ports, list) \
53582b31898SVladimir Oltean 		if ((_dp)->ds == (_ds))
53682b31898SVladimir Oltean 
53782b31898SVladimir Oltean #define dsa_switch_for_each_available_port(_dp, _ds) \
53882b31898SVladimir Oltean 	dsa_switch_for_each_port((_dp), (_ds)) \
53982b31898SVladimir Oltean 		if (!dsa_port_is_unused((_dp)))
54082b31898SVladimir Oltean 
54182b31898SVladimir Oltean #define dsa_switch_for_each_user_port(_dp, _ds) \
54282b31898SVladimir Oltean 	dsa_switch_for_each_port((_dp), (_ds)) \
54382b31898SVladimir Oltean 		if (dsa_port_is_user((_dp)))
54482b31898SVladimir Oltean 
54582b31898SVladimir Oltean #define dsa_switch_for_each_cpu_port(_dp, _ds) \
54682b31898SVladimir Oltean 	dsa_switch_for_each_port((_dp), (_ds)) \
54782b31898SVladimir Oltean 		if (dsa_port_is_cpu((_dp)))
54882b31898SVladimir Oltean 
54902bc6e54SVivien Didelot static inline u32 dsa_user_ports(struct dsa_switch *ds)
55002bc6e54SVivien Didelot {
551d0004a02SVladimir Oltean 	struct dsa_port *dp;
552c38c5a66SVivien Didelot 	u32 mask = 0;
55302bc6e54SVivien Didelot 
554d0004a02SVladimir Oltean 	dsa_switch_for_each_user_port(dp, ds)
555d0004a02SVladimir Oltean 		mask |= BIT(dp->index);
556c38c5a66SVivien Didelot 
557c38c5a66SVivien Didelot 	return mask;
558c8652c83SVivien Didelot }
559c8652c83SVivien Didelot 
560c5f51765SVivien Didelot /* Return the local port used to reach an arbitrary switch device */
561c5f51765SVivien Didelot static inline unsigned int dsa_routing_port(struct dsa_switch *ds, int device)
562c5f51765SVivien Didelot {
563c5f51765SVivien Didelot 	struct dsa_switch_tree *dst = ds->dst;
564c5f51765SVivien Didelot 	struct dsa_link *dl;
565c5f51765SVivien Didelot 
566c5f51765SVivien Didelot 	list_for_each_entry(dl, &dst->rtable, list)
567c5f51765SVivien Didelot 		if (dl->dp->ds == ds && dl->link_dp->ds->index == device)
568c5f51765SVivien Didelot 			return dl->dp->index;
569c5f51765SVivien Didelot 
570c5f51765SVivien Didelot 	return ds->num_ports;
571c5f51765SVivien Didelot }
572c5f51765SVivien Didelot 
5733b8fac5dSVivien Didelot /* Return the local port used to reach an arbitrary switch port */
5743b8fac5dSVivien Didelot static inline unsigned int dsa_towards_port(struct dsa_switch *ds, int device,
5753b8fac5dSVivien Didelot 					    int port)
5763b8fac5dSVivien Didelot {
5773b8fac5dSVivien Didelot 	if (device == ds->index)
5783b8fac5dSVivien Didelot 		return port;
5793b8fac5dSVivien Didelot 	else
580c5f51765SVivien Didelot 		return dsa_routing_port(ds, device);
5813b8fac5dSVivien Didelot }
5823b8fac5dSVivien Didelot 
5833b8fac5dSVivien Didelot /* Return the local port used to reach the dedicated CPU port */
58407073c79SVivien Didelot static inline unsigned int dsa_upstream_port(struct dsa_switch *ds, int port)
585c8f0b869SBen Hutchings {
58607073c79SVivien Didelot 	const struct dsa_port *dp = dsa_to_port(ds, port);
58707073c79SVivien Didelot 	const struct dsa_port *cpu_dp = dp->cpu_dp;
58807073c79SVivien Didelot 
58907073c79SVivien Didelot 	if (!cpu_dp)
59007073c79SVivien Didelot 		return port;
591c8f0b869SBen Hutchings 
5923b8fac5dSVivien Didelot 	return dsa_towards_port(ds, cpu_dp->ds->index, cpu_dp->index);
593c8f0b869SBen Hutchings }
594c8f0b869SBen Hutchings 
59563609c8fSVladimir Oltean /* Return true if this is the local port used to reach the CPU port */
59663609c8fSVladimir Oltean static inline bool dsa_is_upstream_port(struct dsa_switch *ds, int port)
59763609c8fSVladimir Oltean {
59863609c8fSVladimir Oltean 	if (dsa_is_unused_port(ds, port))
59963609c8fSVladimir Oltean 		return false;
60063609c8fSVladimir Oltean 
60163609c8fSVladimir Oltean 	return port == dsa_upstream_port(ds, port);
60263609c8fSVladimir Oltean }
60363609c8fSVladimir Oltean 
604d352b20fSTobias Waldekranz /* Return true if this is a DSA port leading away from the CPU */
605d352b20fSTobias Waldekranz static inline bool dsa_is_downstream_port(struct dsa_switch *ds, int port)
606d352b20fSTobias Waldekranz {
607d352b20fSTobias Waldekranz 	return dsa_is_dsa_port(ds, port) && !dsa_is_upstream_port(ds, port);
608d352b20fSTobias Waldekranz }
609d352b20fSTobias Waldekranz 
6107af4a361STobias Waldekranz /* Return the local port used to reach the CPU port */
6117af4a361STobias Waldekranz static inline unsigned int dsa_switch_upstream_port(struct dsa_switch *ds)
6127af4a361STobias Waldekranz {
6137af4a361STobias Waldekranz 	struct dsa_port *dp;
6147af4a361STobias Waldekranz 
6157af4a361STobias Waldekranz 	dsa_switch_for_each_available_port(dp, ds) {
6167af4a361STobias Waldekranz 		return dsa_upstream_port(ds, dp->index);
6177af4a361STobias Waldekranz 	}
6187af4a361STobias Waldekranz 
6197af4a361STobias Waldekranz 	return ds->num_ports;
6207af4a361STobias Waldekranz }
6217af4a361STobias Waldekranz 
62263609c8fSVladimir Oltean /* Return true if @upstream_ds is an upstream switch of @downstream_ds, meaning
62363609c8fSVladimir Oltean  * that the routing port from @downstream_ds to @upstream_ds is also the port
62463609c8fSVladimir Oltean  * which @downstream_ds uses to reach its dedicated CPU.
62563609c8fSVladimir Oltean  */
62663609c8fSVladimir Oltean static inline bool dsa_switch_is_upstream_of(struct dsa_switch *upstream_ds,
62763609c8fSVladimir Oltean 					     struct dsa_switch *downstream_ds)
62863609c8fSVladimir Oltean {
62963609c8fSVladimir Oltean 	int routing_port;
63063609c8fSVladimir Oltean 
63163609c8fSVladimir Oltean 	if (upstream_ds == downstream_ds)
63263609c8fSVladimir Oltean 		return true;
63363609c8fSVladimir Oltean 
63463609c8fSVladimir Oltean 	routing_port = dsa_routing_port(downstream_ds, upstream_ds->index);
63563609c8fSVladimir Oltean 
63663609c8fSVladimir Oltean 	return dsa_is_upstream_port(downstream_ds, routing_port);
63763609c8fSVladimir Oltean }
63863609c8fSVladimir Oltean 
639cf2d45f5SVladimir Oltean static inline bool dsa_port_is_vlan_filtering(const struct dsa_port *dp)
640cf2d45f5SVladimir Oltean {
641cf2d45f5SVladimir Oltean 	const struct dsa_switch *ds = dp->ds;
642cf2d45f5SVladimir Oltean 
643cf2d45f5SVladimir Oltean 	if (ds->vlan_filtering_is_global)
644cf2d45f5SVladimir Oltean 		return ds->vlan_filtering;
645cf2d45f5SVladimir Oltean 	else
646cf2d45f5SVladimir Oltean 		return dp->vlan_filtering;
647cf2d45f5SVladimir Oltean }
648cf2d45f5SVladimir Oltean 
649cc76ce9eSTobias Waldekranz static inline
650cc76ce9eSTobias Waldekranz struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp)
651cc76ce9eSTobias Waldekranz {
652d3eed0e5SVladimir Oltean 	if (!dp->bridge)
653cc76ce9eSTobias Waldekranz 		return NULL;
654cc76ce9eSTobias Waldekranz 
655cc76ce9eSTobias Waldekranz 	if (dp->lag_dev)
656cc76ce9eSTobias Waldekranz 		return dp->lag_dev;
657cc76ce9eSTobias Waldekranz 	else if (dp->hsr_dev)
658cc76ce9eSTobias Waldekranz 		return dp->hsr_dev;
659cc76ce9eSTobias Waldekranz 
660cc76ce9eSTobias Waldekranz 	return dp->slave;
661cc76ce9eSTobias Waldekranz }
662cc76ce9eSTobias Waldekranz 
66336cbf39bSVladimir Oltean static inline struct net_device *
66436cbf39bSVladimir Oltean dsa_port_bridge_dev_get(const struct dsa_port *dp)
66536cbf39bSVladimir Oltean {
666d3eed0e5SVladimir Oltean 	return dp->bridge ? dp->bridge->dev : NULL;
66736cbf39bSVladimir Oltean }
66836cbf39bSVladimir Oltean 
66936cbf39bSVladimir Oltean static inline unsigned int dsa_port_bridge_num_get(struct dsa_port *dp)
67036cbf39bSVladimir Oltean {
671d3eed0e5SVladimir Oltean 	return dp->bridge ? dp->bridge->num : 0;
67236cbf39bSVladimir Oltean }
67336cbf39bSVladimir Oltean 
67436cbf39bSVladimir Oltean static inline bool dsa_port_bridge_same(const struct dsa_port *a,
67536cbf39bSVladimir Oltean 					const struct dsa_port *b)
67636cbf39bSVladimir Oltean {
67736cbf39bSVladimir Oltean 	struct net_device *br_a = dsa_port_bridge_dev_get(a);
67836cbf39bSVladimir Oltean 	struct net_device *br_b = dsa_port_bridge_dev_get(b);
67936cbf39bSVladimir Oltean 
68036cbf39bSVladimir Oltean 	/* Standalone ports are not in the same bridge with one another */
68136cbf39bSVladimir Oltean 	return (!br_a || !br_b) ? false : (br_a == br_b);
68236cbf39bSVladimir Oltean }
68336cbf39bSVladimir Oltean 
6846a43cba3SVladimir Oltean static inline bool dsa_port_offloads_bridge_port(struct dsa_port *dp,
6856a43cba3SVladimir Oltean 						 const struct net_device *dev)
6866a43cba3SVladimir Oltean {
6876a43cba3SVladimir Oltean 	return dsa_port_to_bridge_port(dp) == dev;
6886a43cba3SVladimir Oltean }
6896a43cba3SVladimir Oltean 
6906a43cba3SVladimir Oltean static inline bool
6916a43cba3SVladimir Oltean dsa_port_offloads_bridge_dev(struct dsa_port *dp,
6926a43cba3SVladimir Oltean 			     const struct net_device *bridge_dev)
6936a43cba3SVladimir Oltean {
6946a43cba3SVladimir Oltean 	/* DSA ports connected to a bridge, and event was emitted
6956a43cba3SVladimir Oltean 	 * for the bridge.
6966a43cba3SVladimir Oltean 	 */
6976a43cba3SVladimir Oltean 	return dsa_port_bridge_dev_get(dp) == bridge_dev;
6986a43cba3SVladimir Oltean }
6996a43cba3SVladimir Oltean 
700d3eed0e5SVladimir Oltean static inline bool dsa_port_offloads_bridge(struct dsa_port *dp,
701d3eed0e5SVladimir Oltean 					    const struct dsa_bridge *bridge)
702d3eed0e5SVladimir Oltean {
703d3eed0e5SVladimir Oltean 	return dsa_port_bridge_dev_get(dp) == bridge->dev;
704d3eed0e5SVladimir Oltean }
705d3eed0e5SVladimir Oltean 
7066a43cba3SVladimir Oltean /* Returns true if any port of this tree offloads the given net_device */
7076a43cba3SVladimir Oltean static inline bool dsa_tree_offloads_bridge_port(struct dsa_switch_tree *dst,
7086a43cba3SVladimir Oltean 						 const struct net_device *dev)
7096a43cba3SVladimir Oltean {
7106a43cba3SVladimir Oltean 	struct dsa_port *dp;
7116a43cba3SVladimir Oltean 
7126a43cba3SVladimir Oltean 	list_for_each_entry(dp, &dst->ports, list)
7136a43cba3SVladimir Oltean 		if (dsa_port_offloads_bridge_port(dp, dev))
7146a43cba3SVladimir Oltean 			return true;
7156a43cba3SVladimir Oltean 
7166a43cba3SVladimir Oltean 	return false;
7176a43cba3SVladimir Oltean }
7186a43cba3SVladimir Oltean 
7196a43cba3SVladimir Oltean /* Returns true if any port of this tree offloads the given bridge */
7206a43cba3SVladimir Oltean static inline bool
7216a43cba3SVladimir Oltean dsa_tree_offloads_bridge_dev(struct dsa_switch_tree *dst,
7226a43cba3SVladimir Oltean 			     const struct net_device *bridge_dev)
7236a43cba3SVladimir Oltean {
7246a43cba3SVladimir Oltean 	struct dsa_port *dp;
7256a43cba3SVladimir Oltean 
7266a43cba3SVladimir Oltean 	list_for_each_entry(dp, &dst->ports, list)
7276a43cba3SVladimir Oltean 		if (dsa_port_offloads_bridge_dev(dp, bridge_dev))
7286a43cba3SVladimir Oltean 			return true;
7296a43cba3SVladimir Oltean 
7306a43cba3SVladimir Oltean 	return false;
7316a43cba3SVladimir Oltean }
7326a43cba3SVladimir Oltean 
7332bedde1aSArkadi Sharshevsky typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid,
7342bedde1aSArkadi Sharshevsky 			      bool is_static, void *data);
7359d490b4eSVivien Didelot struct dsa_switch_ops {
73653da0ebaSVladimir Oltean 	/*
73753da0ebaSVladimir Oltean 	 * Tagging protocol helpers called for the CPU ports and DSA links.
73853da0ebaSVladimir Oltean 	 * @get_tag_protocol retrieves the initial tagging protocol and is
73953da0ebaSVladimir Oltean 	 * mandatory. Switches which can operate using multiple tagging
74053da0ebaSVladimir Oltean 	 * protocols should implement @change_tag_protocol and report in
74153da0ebaSVladimir Oltean 	 * @get_tag_protocol the tagger in current use.
74253da0ebaSVladimir Oltean 	 */
7435ed4e3ebSFlorian Fainelli 	enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds,
7444d776482SFlorian Fainelli 						  int port,
7454d776482SFlorian Fainelli 						  enum dsa_tag_protocol mprot);
74653da0ebaSVladimir Oltean 	int	(*change_tag_protocol)(struct dsa_switch *ds, int port,
74753da0ebaSVladimir Oltean 				       enum dsa_tag_protocol proto);
748dc452a47SVladimir Oltean 	/*
749dc452a47SVladimir Oltean 	 * Method for switch drivers to connect to the tagging protocol driver
750dc452a47SVladimir Oltean 	 * in current use. The switch driver can provide handlers for certain
751dc452a47SVladimir Oltean 	 * types of packets for switch management.
752dc452a47SVladimir Oltean 	 */
753dc452a47SVladimir Oltean 	int	(*connect_tag_protocol)(struct dsa_switch *ds,
754dc452a47SVladimir Oltean 					enum dsa_tag_protocol proto);
7557b314362SAndrew Lunn 
756fd292c18SVladimir Oltean 	/* Optional switch-wide initialization and destruction methods */
757c8f0b869SBen Hutchings 	int	(*setup)(struct dsa_switch *ds);
7585e3f847aSVladimir Oltean 	void	(*teardown)(struct dsa_switch *ds);
759fd292c18SVladimir Oltean 
760fd292c18SVladimir Oltean 	/* Per-port initialization and destruction methods. Mandatory if the
761fd292c18SVladimir Oltean 	 * driver registers devlink port regions, optional otherwise.
762fd292c18SVladimir Oltean 	 */
763fd292c18SVladimir Oltean 	int	(*port_setup)(struct dsa_switch *ds, int port);
764fd292c18SVladimir Oltean 	void	(*port_teardown)(struct dsa_switch *ds, int port);
765fd292c18SVladimir Oltean 
7666819563eSFlorian Fainelli 	u32	(*get_phy_flags)(struct dsa_switch *ds, int port);
767c8f0b869SBen Hutchings 
768c8f0b869SBen Hutchings 	/*
769c8f0b869SBen Hutchings 	 * Access to the switch's PHY registers.
770c8f0b869SBen Hutchings 	 */
771c8f0b869SBen Hutchings 	int	(*phy_read)(struct dsa_switch *ds, int port, int regnum);
772c8f0b869SBen Hutchings 	int	(*phy_write)(struct dsa_switch *ds, int port,
773c8f0b869SBen Hutchings 			     int regnum, u16 val);
774c8f0b869SBen Hutchings 
775c8f0b869SBen Hutchings 	/*
776ec9436baSFlorian Fainelli 	 * Link state adjustment (called from libphy)
777ec9436baSFlorian Fainelli 	 */
778ec9436baSFlorian Fainelli 	void	(*adjust_link)(struct dsa_switch *ds, int port,
779ec9436baSFlorian Fainelli 				struct phy_device *phydev);
780ce31b31cSFlorian Fainelli 	void	(*fixed_link_update)(struct dsa_switch *ds, int port,
781ce31b31cSFlorian Fainelli 				struct fixed_phy_status *st);
782ec9436baSFlorian Fainelli 
783ec9436baSFlorian Fainelli 	/*
78411d8f3ddSFlorian Fainelli 	 * PHYLINK integration
78511d8f3ddSFlorian Fainelli 	 */
786072eea6cSRussell King (Oracle) 	void	(*phylink_get_caps)(struct dsa_switch *ds, int port,
787072eea6cSRussell King (Oracle) 				    struct phylink_config *config);
78811d8f3ddSFlorian Fainelli 	void	(*phylink_validate)(struct dsa_switch *ds, int port,
78911d8f3ddSFlorian Fainelli 				    unsigned long *supported,
79011d8f3ddSFlorian Fainelli 				    struct phylink_link_state *state);
79111d8f3ddSFlorian Fainelli 	int	(*phylink_mac_link_state)(struct dsa_switch *ds, int port,
79211d8f3ddSFlorian Fainelli 					  struct phylink_link_state *state);
79311d8f3ddSFlorian Fainelli 	void	(*phylink_mac_config)(struct dsa_switch *ds, int port,
79411d8f3ddSFlorian Fainelli 				      unsigned int mode,
79511d8f3ddSFlorian Fainelli 				      const struct phylink_link_state *state);
79611d8f3ddSFlorian Fainelli 	void	(*phylink_mac_an_restart)(struct dsa_switch *ds, int port);
79711d8f3ddSFlorian Fainelli 	void	(*phylink_mac_link_down)(struct dsa_switch *ds, int port,
79811d8f3ddSFlorian Fainelli 					 unsigned int mode,
79911d8f3ddSFlorian Fainelli 					 phy_interface_t interface);
80011d8f3ddSFlorian Fainelli 	void	(*phylink_mac_link_up)(struct dsa_switch *ds, int port,
80111d8f3ddSFlorian Fainelli 				       unsigned int mode,
80211d8f3ddSFlorian Fainelli 				       phy_interface_t interface,
8035b502a7bSRussell King 				       struct phy_device *phydev,
8045b502a7bSRussell King 				       int speed, int duplex,
8055b502a7bSRussell King 				       bool tx_pause, bool rx_pause);
80611d8f3ddSFlorian Fainelli 	void	(*phylink_fixed_state)(struct dsa_switch *ds, int port,
80711d8f3ddSFlorian Fainelli 				       struct phylink_link_state *state);
80811d8f3ddSFlorian Fainelli 	/*
809c2ec5f2eSOleksij Rempel 	 * Port statistics counters.
810c8f0b869SBen Hutchings 	 */
81189f09048SFlorian Fainelli 	void	(*get_strings)(struct dsa_switch *ds, int port,
81289f09048SFlorian Fainelli 			       u32 stringset, uint8_t *data);
813c8f0b869SBen Hutchings 	void	(*get_ethtool_stats)(struct dsa_switch *ds,
814c8f0b869SBen Hutchings 				     int port, uint64_t *data);
81589f09048SFlorian Fainelli 	int	(*get_sset_count)(struct dsa_switch *ds, int port, int sset);
816cf963573SFlorian Fainelli 	void	(*get_ethtool_phy_stats)(struct dsa_switch *ds,
817cf963573SFlorian Fainelli 					 int port, uint64_t *data);
818487d3855SAlvin Šipraga 	void	(*get_eth_phy_stats)(struct dsa_switch *ds, int port,
819487d3855SAlvin Šipraga 				     struct ethtool_eth_phy_stats *phy_stats);
820487d3855SAlvin Šipraga 	void	(*get_eth_mac_stats)(struct dsa_switch *ds, int port,
821487d3855SAlvin Šipraga 				     struct ethtool_eth_mac_stats *mac_stats);
822487d3855SAlvin Šipraga 	void	(*get_eth_ctrl_stats)(struct dsa_switch *ds, int port,
823487d3855SAlvin Šipraga 				      struct ethtool_eth_ctrl_stats *ctrl_stats);
824c2ec5f2eSOleksij Rempel 	void	(*get_stats64)(struct dsa_switch *ds, int port,
825c2ec5f2eSOleksij Rempel 				   struct rtnl_link_stats64 *s);
826a71acad9SOleksij Rempel 	void	(*self_test)(struct dsa_switch *ds, int port,
827a71acad9SOleksij Rempel 			     struct ethtool_test *etest, u64 *data);
82824462549SFlorian Fainelli 
82924462549SFlorian Fainelli 	/*
83019e57c4eSFlorian Fainelli 	 * ethtool Wake-on-LAN
83119e57c4eSFlorian Fainelli 	 */
83219e57c4eSFlorian Fainelli 	void	(*get_wol)(struct dsa_switch *ds, int port,
83319e57c4eSFlorian Fainelli 			   struct ethtool_wolinfo *w);
83419e57c4eSFlorian Fainelli 	int	(*set_wol)(struct dsa_switch *ds, int port,
83519e57c4eSFlorian Fainelli 			   struct ethtool_wolinfo *w);
83619e57c4eSFlorian Fainelli 
83719e57c4eSFlorian Fainelli 	/*
8380336369dSBrandon Streiff 	 * ethtool timestamp info
8390336369dSBrandon Streiff 	 */
8400336369dSBrandon Streiff 	int	(*get_ts_info)(struct dsa_switch *ds, int port,
8410336369dSBrandon Streiff 			       struct ethtool_ts_info *ts);
8420336369dSBrandon Streiff 
8430336369dSBrandon Streiff 	/*
84424462549SFlorian Fainelli 	 * Suspend and resume
84524462549SFlorian Fainelli 	 */
84624462549SFlorian Fainelli 	int	(*suspend)(struct dsa_switch *ds);
84724462549SFlorian Fainelli 	int	(*resume)(struct dsa_switch *ds);
848b2f2af21SFlorian Fainelli 
849b2f2af21SFlorian Fainelli 	/*
850b2f2af21SFlorian Fainelli 	 * Port enable/disable
851b2f2af21SFlorian Fainelli 	 */
852b2f2af21SFlorian Fainelli 	int	(*port_enable)(struct dsa_switch *ds, int port,
853b2f2af21SFlorian Fainelli 			       struct phy_device *phy);
85475104db0SAndrew Lunn 	void	(*port_disable)(struct dsa_switch *ds, int port);
8557905288fSFlorian Fainelli 
8567905288fSFlorian Fainelli 	/*
85708f50061SVivien Didelot 	 * Port's MAC EEE settings
8587905288fSFlorian Fainelli 	 */
85908f50061SVivien Didelot 	int	(*set_mac_eee)(struct dsa_switch *ds, int port,
8607905288fSFlorian Fainelli 			       struct ethtool_eee *e);
86108f50061SVivien Didelot 	int	(*get_mac_eee)(struct dsa_switch *ds, int port,
8627905288fSFlorian Fainelli 			       struct ethtool_eee *e);
86351579c3fSGuenter Roeck 
8646793abb4SGuenter Roeck 	/* EEPROM access */
8656793abb4SGuenter Roeck 	int	(*get_eeprom_len)(struct dsa_switch *ds);
8666793abb4SGuenter Roeck 	int	(*get_eeprom)(struct dsa_switch *ds,
8676793abb4SGuenter Roeck 			      struct ethtool_eeprom *eeprom, u8 *data);
8686793abb4SGuenter Roeck 	int	(*set_eeprom)(struct dsa_switch *ds,
8696793abb4SGuenter Roeck 			      struct ethtool_eeprom *eeprom, u8 *data);
8703d762a0fSGuenter Roeck 
8713d762a0fSGuenter Roeck 	/*
8723d762a0fSGuenter Roeck 	 * Register access.
8733d762a0fSGuenter Roeck 	 */
8743d762a0fSGuenter Roeck 	int	(*get_regs_len)(struct dsa_switch *ds, int port);
8753d762a0fSGuenter Roeck 	void	(*get_regs)(struct dsa_switch *ds, int port,
8763d762a0fSGuenter Roeck 			    struct ethtool_regs *regs, void *p);
877b73adef6SFlorian Fainelli 
878b73adef6SFlorian Fainelli 	/*
879e358bef7SVladimir Oltean 	 * Upper device tracking.
880e358bef7SVladimir Oltean 	 */
881e358bef7SVladimir Oltean 	int	(*port_prechangeupper)(struct dsa_switch *ds, int port,
882e358bef7SVladimir Oltean 				       struct netdev_notifier_changeupper_info *info);
883e358bef7SVladimir Oltean 
884e358bef7SVladimir Oltean 	/*
885b73adef6SFlorian Fainelli 	 * Bridge integration
886b73adef6SFlorian Fainelli 	 */
88734a79f63SVivien Didelot 	int	(*set_ageing_time)(struct dsa_switch *ds, unsigned int msecs);
88871327a4eSVivien Didelot 	int	(*port_bridge_join)(struct dsa_switch *ds, int port,
889b079922bSVladimir Oltean 				    struct dsa_bridge bridge,
890b079922bSVladimir Oltean 				    bool *tx_fwd_offload);
891f123f2fbSVivien Didelot 	void	(*port_bridge_leave)(struct dsa_switch *ds, int port,
892d3eed0e5SVladimir Oltean 				     struct dsa_bridge bridge);
89343c44a9fSVivien Didelot 	void	(*port_stp_state_set)(struct dsa_switch *ds, int port,
894b73adef6SFlorian Fainelli 				      u8 state);
895732f794cSVivien Didelot 	void	(*port_fast_age)(struct dsa_switch *ds, int port);
896a8b659e7SVladimir Oltean 	int	(*port_pre_bridge_flags)(struct dsa_switch *ds, int port,
897a8b659e7SVladimir Oltean 					 struct switchdev_brport_flags flags,
898a8b659e7SVladimir Oltean 					 struct netlink_ext_ack *extack);
899a8b659e7SVladimir Oltean 	int	(*port_bridge_flags)(struct dsa_switch *ds, int port,
900a8b659e7SVladimir Oltean 				     struct switchdev_brport_flags flags,
901a8b659e7SVladimir Oltean 				     struct netlink_ext_ack *extack);
9022a778e1bSVivien Didelot 
9032a778e1bSVivien Didelot 	/*
90411149536SVivien Didelot 	 * VLAN support
90511149536SVivien Didelot 	 */
906fb2dabadSVivien Didelot 	int	(*port_vlan_filtering)(struct dsa_switch *ds, int port,
90789153ed6SVladimir Oltean 				       bool vlan_filtering,
90889153ed6SVladimir Oltean 				       struct netlink_ext_ack *extack);
9091958d581SVladimir Oltean 	int	(*port_vlan_add)(struct dsa_switch *ds, int port,
91031046a5fSVladimir Oltean 				 const struct switchdev_obj_port_vlan *vlan,
91131046a5fSVladimir Oltean 				 struct netlink_ext_ack *extack);
91276e398a6SVivien Didelot 	int	(*port_vlan_del)(struct dsa_switch *ds, int port,
91376e398a6SVivien Didelot 				 const struct switchdev_obj_port_vlan *vlan);
91411149536SVivien Didelot 	/*
9152a778e1bSVivien Didelot 	 * Forwarding database
9162a778e1bSVivien Didelot 	 */
9171b6dd556SArkadi Sharshevsky 	int	(*port_fdb_add)(struct dsa_switch *ds, int port,
9186c2c1dcbSArkadi Sharshevsky 				const unsigned char *addr, u16 vid);
9192a778e1bSVivien Didelot 	int	(*port_fdb_del)(struct dsa_switch *ds, int port,
9206c2c1dcbSArkadi Sharshevsky 				const unsigned char *addr, u16 vid);
921ea70ba98SVivien Didelot 	int	(*port_fdb_dump)(struct dsa_switch *ds, int port,
9222bedde1aSArkadi Sharshevsky 				 dsa_fdb_dump_cb_t *cb, void *data);
9238df30255SVivien Didelot 
9248df30255SVivien Didelot 	/*
9258df30255SVivien Didelot 	 * Multicast database
9268df30255SVivien Didelot 	 */
927a52b2da7SVladimir Oltean 	int	(*port_mdb_add)(struct dsa_switch *ds, int port,
9283709aadcSVivien Didelot 				const struct switchdev_obj_port_mdb *mdb);
9298df30255SVivien Didelot 	int	(*port_mdb_del)(struct dsa_switch *ds, int port,
9308df30255SVivien Didelot 				const struct switchdev_obj_port_mdb *mdb);
931bf9f2648SFlorian Fainelli 	/*
932bf9f2648SFlorian Fainelli 	 * RXNFC
933bf9f2648SFlorian Fainelli 	 */
934bf9f2648SFlorian Fainelli 	int	(*get_rxnfc)(struct dsa_switch *ds, int port,
935bf9f2648SFlorian Fainelli 			     struct ethtool_rxnfc *nfc, u32 *rule_locs);
936bf9f2648SFlorian Fainelli 	int	(*set_rxnfc)(struct dsa_switch *ds, int port,
937bf9f2648SFlorian Fainelli 			     struct ethtool_rxnfc *nfc);
938f50f2127SFlorian Fainelli 
939f50f2127SFlorian Fainelli 	/*
940f50f2127SFlorian Fainelli 	 * TC integration
941f50f2127SFlorian Fainelli 	 */
942ed11bb1fSVladimir Oltean 	int	(*cls_flower_add)(struct dsa_switch *ds, int port,
943ed11bb1fSVladimir Oltean 				  struct flow_cls_offload *cls, bool ingress);
944ed11bb1fSVladimir Oltean 	int	(*cls_flower_del)(struct dsa_switch *ds, int port,
945ed11bb1fSVladimir Oltean 				  struct flow_cls_offload *cls, bool ingress);
946ed11bb1fSVladimir Oltean 	int	(*cls_flower_stats)(struct dsa_switch *ds, int port,
947ed11bb1fSVladimir Oltean 				    struct flow_cls_offload *cls, bool ingress);
948f50f2127SFlorian Fainelli 	int	(*port_mirror_add)(struct dsa_switch *ds, int port,
949f50f2127SFlorian Fainelli 				   struct dsa_mall_mirror_tc_entry *mirror,
950f50f2127SFlorian Fainelli 				   bool ingress);
951f50f2127SFlorian Fainelli 	void	(*port_mirror_del)(struct dsa_switch *ds, int port,
952f50f2127SFlorian Fainelli 				   struct dsa_mall_mirror_tc_entry *mirror);
95334297176SVladimir Oltean 	int	(*port_policer_add)(struct dsa_switch *ds, int port,
95434297176SVladimir Oltean 				    struct dsa_mall_policer_tc_entry *policer);
95534297176SVladimir Oltean 	void	(*port_policer_del)(struct dsa_switch *ds, int port);
95647d23af2SVladimir Oltean 	int	(*port_setup_tc)(struct dsa_switch *ds, int port,
95747d23af2SVladimir Oltean 				 enum tc_setup_type type, void *type_data);
95840ef2c93SVivien Didelot 
95940ef2c93SVivien Didelot 	/*
96040ef2c93SVivien Didelot 	 * Cross-chip operations
96140ef2c93SVivien Didelot 	 */
962f66a6a69SVladimir Oltean 	int	(*crosschip_bridge_join)(struct dsa_switch *ds, int tree_index,
963f66a6a69SVladimir Oltean 					 int sw_index, int port,
964d3eed0e5SVladimir Oltean 					 struct dsa_bridge bridge);
965f66a6a69SVladimir Oltean 	void	(*crosschip_bridge_leave)(struct dsa_switch *ds, int tree_index,
966f66a6a69SVladimir Oltean 					  int sw_index, int port,
967d3eed0e5SVladimir Oltean 					  struct dsa_bridge bridge);
968058102a6STobias Waldekranz 	int	(*crosschip_lag_change)(struct dsa_switch *ds, int sw_index,
969058102a6STobias Waldekranz 					int port);
970058102a6STobias Waldekranz 	int	(*crosschip_lag_join)(struct dsa_switch *ds, int sw_index,
971058102a6STobias Waldekranz 				      int port, struct net_device *lag,
972058102a6STobias Waldekranz 				      struct netdev_lag_upper_info *info);
973058102a6STobias Waldekranz 	int	(*crosschip_lag_leave)(struct dsa_switch *ds, int sw_index,
974058102a6STobias Waldekranz 				       int port, struct net_device *lag);
9750336369dSBrandon Streiff 
9760336369dSBrandon Streiff 	/*
9770336369dSBrandon Streiff 	 * PTP functionality
9780336369dSBrandon Streiff 	 */
9790336369dSBrandon Streiff 	int	(*port_hwtstamp_get)(struct dsa_switch *ds, int port,
9800336369dSBrandon Streiff 				     struct ifreq *ifr);
9810336369dSBrandon Streiff 	int	(*port_hwtstamp_set)(struct dsa_switch *ds, int port,
9820336369dSBrandon Streiff 				     struct ifreq *ifr);
9835c5416f5SYangbo Lu 	void	(*port_txtstamp)(struct dsa_switch *ds, int port,
9845c5416f5SYangbo Lu 				 struct sk_buff *skb);
98590af1059SBrandon Streiff 	bool	(*port_rxtstamp)(struct dsa_switch *ds, int port,
98690af1059SBrandon Streiff 				 struct sk_buff *skb, unsigned int type);
98797a69a0dSVladimir Oltean 
9880f06b855SAndrew Lunn 	/* Devlink parameters, etc */
9896b297524SAndrew Lunn 	int	(*devlink_param_get)(struct dsa_switch *ds, u32 id,
9906b297524SAndrew Lunn 				     struct devlink_param_gset_ctx *ctx);
9916b297524SAndrew Lunn 	int	(*devlink_param_set)(struct dsa_switch *ds, u32 id,
9926b297524SAndrew Lunn 				     struct devlink_param_gset_ctx *ctx);
9930f06b855SAndrew Lunn 	int	(*devlink_info_get)(struct dsa_switch *ds,
9940f06b855SAndrew Lunn 				    struct devlink_info_req *req,
9950f06b855SAndrew Lunn 				    struct netlink_ext_ack *extack);
9962a6ef763SVladimir Oltean 	int	(*devlink_sb_pool_get)(struct dsa_switch *ds,
9972a6ef763SVladimir Oltean 				       unsigned int sb_index, u16 pool_index,
9982a6ef763SVladimir Oltean 				       struct devlink_sb_pool_info *pool_info);
9992a6ef763SVladimir Oltean 	int	(*devlink_sb_pool_set)(struct dsa_switch *ds, unsigned int sb_index,
10002a6ef763SVladimir Oltean 				       u16 pool_index, u32 size,
10012a6ef763SVladimir Oltean 				       enum devlink_sb_threshold_type threshold_type,
10022a6ef763SVladimir Oltean 				       struct netlink_ext_ack *extack);
10032a6ef763SVladimir Oltean 	int	(*devlink_sb_port_pool_get)(struct dsa_switch *ds, int port,
10042a6ef763SVladimir Oltean 					    unsigned int sb_index, u16 pool_index,
10052a6ef763SVladimir Oltean 					    u32 *p_threshold);
10062a6ef763SVladimir Oltean 	int	(*devlink_sb_port_pool_set)(struct dsa_switch *ds, int port,
10072a6ef763SVladimir Oltean 					    unsigned int sb_index, u16 pool_index,
10082a6ef763SVladimir Oltean 					    u32 threshold,
10092a6ef763SVladimir Oltean 					    struct netlink_ext_ack *extack);
10102a6ef763SVladimir Oltean 	int	(*devlink_sb_tc_pool_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 					       u16 *p_pool_index, u32 *p_threshold);
10142a6ef763SVladimir Oltean 	int	(*devlink_sb_tc_pool_bind_set)(struct dsa_switch *ds, int port,
10152a6ef763SVladimir Oltean 					       unsigned int sb_index, u16 tc_index,
10162a6ef763SVladimir Oltean 					       enum devlink_sb_pool_type pool_type,
10172a6ef763SVladimir Oltean 					       u16 pool_index, u32 threshold,
10182a6ef763SVladimir Oltean 					       struct netlink_ext_ack *extack);
10192a6ef763SVladimir Oltean 	int	(*devlink_sb_occ_snapshot)(struct dsa_switch *ds,
10202a6ef763SVladimir Oltean 					   unsigned int sb_index);
10212a6ef763SVladimir Oltean 	int	(*devlink_sb_occ_max_clear)(struct dsa_switch *ds,
10222a6ef763SVladimir Oltean 					    unsigned int sb_index);
10232a6ef763SVladimir Oltean 	int	(*devlink_sb_occ_port_pool_get)(struct dsa_switch *ds, int port,
10242a6ef763SVladimir Oltean 						unsigned int sb_index, u16 pool_index,
10252a6ef763SVladimir Oltean 						u32 *p_cur, u32 *p_max);
10262a6ef763SVladimir Oltean 	int	(*devlink_sb_occ_tc_port_bind_get)(struct dsa_switch *ds, int port,
10272a6ef763SVladimir Oltean 						   unsigned int sb_index, u16 tc_index,
10282a6ef763SVladimir Oltean 						   enum devlink_sb_pool_type pool_type,
10292a6ef763SVladimir Oltean 						   u32 *p_cur, u32 *p_max);
1030bfcb8132SVladimir Oltean 
1031bfcb8132SVladimir Oltean 	/*
1032bfcb8132SVladimir Oltean 	 * MTU change functionality. Switches can also adjust their MRU through
1033bfcb8132SVladimir Oltean 	 * this method. By MTU, one understands the SDU (L2 payload) length.
1034bfcb8132SVladimir Oltean 	 * If the switch needs to account for the DSA tag on the CPU port, this
1035ab88d64aSRandy Dunlap 	 * method needs to do so privately.
1036bfcb8132SVladimir Oltean 	 */
1037bfcb8132SVladimir Oltean 	int	(*port_change_mtu)(struct dsa_switch *ds, int port,
1038bfcb8132SVladimir Oltean 				   int new_mtu);
1039bfcb8132SVladimir Oltean 	int	(*port_max_mtu)(struct dsa_switch *ds, int port);
1040058102a6STobias Waldekranz 
1041058102a6STobias Waldekranz 	/*
1042058102a6STobias Waldekranz 	 * LAG integration
1043058102a6STobias Waldekranz 	 */
1044058102a6STobias Waldekranz 	int	(*port_lag_change)(struct dsa_switch *ds, int port);
1045058102a6STobias Waldekranz 	int	(*port_lag_join)(struct dsa_switch *ds, int port,
1046058102a6STobias Waldekranz 				 struct net_device *lag,
1047058102a6STobias Waldekranz 				 struct netdev_lag_upper_info *info);
1048058102a6STobias Waldekranz 	int	(*port_lag_leave)(struct dsa_switch *ds, int port,
1049058102a6STobias Waldekranz 				  struct net_device *lag);
105018596f50SGeorge McCollister 
105118596f50SGeorge McCollister 	/*
105218596f50SGeorge McCollister 	 * HSR integration
105318596f50SGeorge McCollister 	 */
105418596f50SGeorge McCollister 	int	(*port_hsr_join)(struct dsa_switch *ds, int port,
105518596f50SGeorge McCollister 				 struct net_device *hsr);
105618596f50SGeorge McCollister 	int	(*port_hsr_leave)(struct dsa_switch *ds, int port,
105718596f50SGeorge McCollister 				  struct net_device *hsr);
1058c595c433SHoratiu Vultur 
1059c595c433SHoratiu Vultur 	/*
1060c595c433SHoratiu Vultur 	 * MRP integration
1061c595c433SHoratiu Vultur 	 */
1062c595c433SHoratiu Vultur 	int	(*port_mrp_add)(struct dsa_switch *ds, int port,
1063c595c433SHoratiu Vultur 				const struct switchdev_obj_mrp *mrp);
1064c595c433SHoratiu Vultur 	int	(*port_mrp_del)(struct dsa_switch *ds, int port,
1065c595c433SHoratiu Vultur 				const struct switchdev_obj_mrp *mrp);
1066c595c433SHoratiu Vultur 	int	(*port_mrp_add_ring_role)(struct dsa_switch *ds, int port,
1067c595c433SHoratiu Vultur 					  const struct switchdev_obj_ring_role_mrp *mrp);
1068c595c433SHoratiu Vultur 	int	(*port_mrp_del_ring_role)(struct dsa_switch *ds, int port,
1069c595c433SHoratiu Vultur 					  const struct switchdev_obj_ring_role_mrp *mrp);
10705da11eb4SVladimir Oltean 
10715da11eb4SVladimir Oltean 	/*
10725da11eb4SVladimir Oltean 	 * tag_8021q operations
10735da11eb4SVladimir Oltean 	 */
10745da11eb4SVladimir Oltean 	int	(*tag_8021q_vlan_add)(struct dsa_switch *ds, int port, u16 vid,
10755da11eb4SVladimir Oltean 				      u16 flags);
10765da11eb4SVladimir Oltean 	int	(*tag_8021q_vlan_del)(struct dsa_switch *ds, int port, u16 vid);
1077295ab96fSVladimir Oltean 
1078295ab96fSVladimir Oltean 	/*
1079295ab96fSVladimir Oltean 	 * DSA master tracking operations
1080295ab96fSVladimir Oltean 	 */
1081295ab96fSVladimir Oltean 	void	(*master_state_change)(struct dsa_switch *ds,
1082295ab96fSVladimir Oltean 				       const struct net_device *master,
1083295ab96fSVladimir Oltean 				       bool operational);
10846b297524SAndrew Lunn };
10856b297524SAndrew Lunn 
10866b297524SAndrew Lunn #define DSA_DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes)		\
10876b297524SAndrew Lunn 	DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes,		\
10886b297524SAndrew Lunn 			     dsa_devlink_param_get, dsa_devlink_param_set, NULL)
10896b297524SAndrew Lunn 
10906b297524SAndrew Lunn int dsa_devlink_param_get(struct devlink *dl, u32 id,
10916b297524SAndrew Lunn 			  struct devlink_param_gset_ctx *ctx);
10926b297524SAndrew Lunn int dsa_devlink_param_set(struct devlink *dl, u32 id,
10936b297524SAndrew Lunn 			  struct devlink_param_gset_ctx *ctx);
10946b297524SAndrew Lunn int dsa_devlink_params_register(struct dsa_switch *ds,
10956b297524SAndrew Lunn 				const struct devlink_param *params,
10966b297524SAndrew Lunn 				size_t params_count);
10976b297524SAndrew Lunn void dsa_devlink_params_unregister(struct dsa_switch *ds,
10986b297524SAndrew Lunn 				   const struct devlink_param *params,
10996b297524SAndrew Lunn 				   size_t params_count);
11005cd73fbdSAndrew Lunn int dsa_devlink_resource_register(struct dsa_switch *ds,
11015cd73fbdSAndrew Lunn 				  const char *resource_name,
11025cd73fbdSAndrew Lunn 				  u64 resource_size,
11035cd73fbdSAndrew Lunn 				  u64 resource_id,
11045cd73fbdSAndrew Lunn 				  u64 parent_resource_id,
11055cd73fbdSAndrew Lunn 				  const struct devlink_resource_size_params *size_params);
11065cd73fbdSAndrew Lunn 
11075cd73fbdSAndrew Lunn void dsa_devlink_resources_unregister(struct dsa_switch *ds);
11085cd73fbdSAndrew Lunn 
11095cd73fbdSAndrew Lunn void dsa_devlink_resource_occ_get_register(struct dsa_switch *ds,
11105cd73fbdSAndrew Lunn 					   u64 resource_id,
11115cd73fbdSAndrew Lunn 					   devlink_resource_occ_get_t *occ_get,
11125cd73fbdSAndrew Lunn 					   void *occ_get_priv);
11135cd73fbdSAndrew Lunn void dsa_devlink_resource_occ_get_unregister(struct dsa_switch *ds,
11145cd73fbdSAndrew Lunn 					     u64 resource_id);
111597c82c23SAndrew Lunn struct devlink_region *
111697c82c23SAndrew Lunn dsa_devlink_region_create(struct dsa_switch *ds,
111797c82c23SAndrew Lunn 			  const struct devlink_region_ops *ops,
111897c82c23SAndrew Lunn 			  u32 region_max_snapshots, u64 region_size);
111908156ba4SAndrew Lunn struct devlink_region *
112008156ba4SAndrew Lunn dsa_devlink_port_region_create(struct dsa_switch *ds,
112108156ba4SAndrew Lunn 			       int port,
112208156ba4SAndrew Lunn 			       const struct devlink_port_region_ops *ops,
112308156ba4SAndrew Lunn 			       u32 region_max_snapshots, u64 region_size);
112497c82c23SAndrew Lunn void dsa_devlink_region_destroy(struct devlink_region *region);
112597c82c23SAndrew Lunn 
1126e1eea811SVladimir Oltean struct dsa_port *dsa_port_from_netdev(struct net_device *netdev);
11275cd73fbdSAndrew Lunn 
11286b297524SAndrew Lunn struct dsa_devlink_priv {
11296b297524SAndrew Lunn 	struct dsa_switch *ds;
1130c8f0b869SBen Hutchings };
1131c8f0b869SBen Hutchings 
1132ccc3e6b0SAndrew Lunn static inline struct dsa_switch *dsa_devlink_to_ds(struct devlink *dl)
1133ccc3e6b0SAndrew Lunn {
1134ccc3e6b0SAndrew Lunn 	struct dsa_devlink_priv *dl_priv = devlink_priv(dl);
1135ccc3e6b0SAndrew Lunn 
1136ccc3e6b0SAndrew Lunn 	return dl_priv->ds;
1137ccc3e6b0SAndrew Lunn }
1138ccc3e6b0SAndrew Lunn 
11397d1e2a10SAndrew Lunn static inline
11407d1e2a10SAndrew Lunn struct dsa_switch *dsa_devlink_port_to_ds(struct devlink_port *port)
11417d1e2a10SAndrew Lunn {
11427d1e2a10SAndrew Lunn 	struct devlink *dl = port->devlink;
11437d1e2a10SAndrew Lunn 	struct dsa_devlink_priv *dl_priv = devlink_priv(dl);
11447d1e2a10SAndrew Lunn 
11457d1e2a10SAndrew Lunn 	return dl_priv->ds;
11467d1e2a10SAndrew Lunn }
11477d1e2a10SAndrew Lunn 
11487d1e2a10SAndrew Lunn static inline int dsa_devlink_port_to_port(struct devlink_port *port)
11497d1e2a10SAndrew Lunn {
11507d1e2a10SAndrew Lunn 	return port->index;
11517d1e2a10SAndrew Lunn }
11527d1e2a10SAndrew Lunn 
1153ab3d408dSFlorian Fainelli struct dsa_switch_driver {
1154ab3d408dSFlorian Fainelli 	struct list_head	list;
1155a82f67afSFlorian Fainelli 	const struct dsa_switch_ops *ops;
1156ab3d408dSFlorian Fainelli };
1157ab3d408dSFlorian Fainelli 
115814b89f36SFlorian Fainelli struct net_device *dsa_dev_to_net_device(struct device *dev);
1159c8f0b869SBen Hutchings 
116073a7ece8SVivien Didelot /* Keep inline for faster access in hot path */
11619eb8eff0SVladimir Oltean static inline bool netdev_uses_dsa(const struct net_device *dev)
1162c6e970a0SAndrew Lunn {
1163c6e970a0SAndrew Lunn #if IS_ENABLED(CONFIG_NET_DSA)
1164717ffbfbSVivien Didelot 	return dev->dsa_ptr && dev->dsa_ptr->rcv;
1165c6e970a0SAndrew Lunn #endif
1166c6e970a0SAndrew Lunn 	return false;
1167c6e970a0SAndrew Lunn }
1168c6e970a0SAndrew Lunn 
11699790cf20SVladimir Oltean /* All DSA tags that push the EtherType to the right (basically all except tail
11709790cf20SVladimir Oltean  * tags, which don't break dissection) can be treated the same from the
11719790cf20SVladimir Oltean  * perspective of the flow dissector.
11729790cf20SVladimir Oltean  *
11739790cf20SVladimir Oltean  * We need to return:
11749790cf20SVladimir Oltean  *  - offset: the (B - A) difference between:
11759790cf20SVladimir Oltean  *    A. the position of the real EtherType and
11769790cf20SVladimir Oltean  *    B. the current skb->data (aka ETH_HLEN bytes into the frame, aka 2 bytes
11779790cf20SVladimir Oltean  *       after the normal EtherType was supposed to be)
11789790cf20SVladimir Oltean  *    The offset in bytes is exactly equal to the tagger overhead (and half of
11799790cf20SVladimir Oltean  *    that, in __be16 shorts).
11809790cf20SVladimir Oltean  *
11819790cf20SVladimir Oltean  *  - proto: the value of the real EtherType.
11829790cf20SVladimir Oltean  */
11839790cf20SVladimir Oltean static inline void dsa_tag_generic_flow_dissect(const struct sk_buff *skb,
11849790cf20SVladimir Oltean 						__be16 *proto, int *offset)
11859790cf20SVladimir Oltean {
11869790cf20SVladimir Oltean #if IS_ENABLED(CONFIG_NET_DSA)
11879790cf20SVladimir Oltean 	const struct dsa_device_ops *ops = skb->dev->dsa_ptr->tag_ops;
11884e500251SVladimir Oltean 	int tag_len = ops->needed_headroom;
11899790cf20SVladimir Oltean 
11909790cf20SVladimir Oltean 	*offset = tag_len;
11919790cf20SVladimir Oltean 	*proto = ((__be16 *)skb->data)[(tag_len / 2) - 1];
11929790cf20SVladimir Oltean #endif
11939790cf20SVladimir Oltean }
11949790cf20SVladimir Oltean 
11954cfab356SFlorian Fainelli #if IS_ENABLED(CONFIG_NET_DSA)
11964cfab356SFlorian Fainelli static inline int __dsa_netdevice_ops_check(struct net_device *dev)
11974cfab356SFlorian Fainelli {
11984cfab356SFlorian Fainelli 	int err = -EOPNOTSUPP;
11994cfab356SFlorian Fainelli 
12004cfab356SFlorian Fainelli 	if (!dev->dsa_ptr)
12014cfab356SFlorian Fainelli 		return err;
12024cfab356SFlorian Fainelli 
12034cfab356SFlorian Fainelli 	if (!dev->dsa_ptr->netdev_ops)
12044cfab356SFlorian Fainelli 		return err;
12054cfab356SFlorian Fainelli 
12064cfab356SFlorian Fainelli 	return 0;
12074cfab356SFlorian Fainelli }
12084cfab356SFlorian Fainelli 
1209a7605370SArnd Bergmann static inline int dsa_ndo_eth_ioctl(struct net_device *dev, struct ifreq *ifr,
12104cfab356SFlorian Fainelli 				    int cmd)
12114cfab356SFlorian Fainelli {
12124cfab356SFlorian Fainelli 	const struct dsa_netdevice_ops *ops;
12134cfab356SFlorian Fainelli 	int err;
12144cfab356SFlorian Fainelli 
12154cfab356SFlorian Fainelli 	err = __dsa_netdevice_ops_check(dev);
12164cfab356SFlorian Fainelli 	if (err)
12174cfab356SFlorian Fainelli 		return err;
12184cfab356SFlorian Fainelli 
12194cfab356SFlorian Fainelli 	ops = dev->dsa_ptr->netdev_ops;
12204cfab356SFlorian Fainelli 
1221a7605370SArnd Bergmann 	return ops->ndo_eth_ioctl(dev, ifr, cmd);
12224cfab356SFlorian Fainelli }
12234cfab356SFlorian Fainelli #else
1224a7605370SArnd Bergmann static inline int dsa_ndo_eth_ioctl(struct net_device *dev, struct ifreq *ifr,
12254cfab356SFlorian Fainelli 				    int cmd)
12264cfab356SFlorian Fainelli {
12274cfab356SFlorian Fainelli 	return -EOPNOTSUPP;
12284cfab356SFlorian Fainelli }
12294cfab356SFlorian Fainelli #endif
12304cfab356SFlorian Fainelli 
123183c0afaeSAndrew Lunn void dsa_unregister_switch(struct dsa_switch *ds);
123223c9ee49SVivien Didelot int dsa_register_switch(struct dsa_switch *ds);
12330650bf52SVladimir Oltean void dsa_switch_shutdown(struct dsa_switch *ds);
12343b7bc1f0SVladimir Oltean struct dsa_switch *dsa_switch_find(int tree_index, int sw_index);
1235ea825e70SFlorian Fainelli #ifdef CONFIG_PM_SLEEP
1236ea825e70SFlorian Fainelli int dsa_switch_suspend(struct dsa_switch *ds);
1237ea825e70SFlorian Fainelli int dsa_switch_resume(struct dsa_switch *ds);
1238ea825e70SFlorian Fainelli #else
1239ea825e70SFlorian Fainelli static inline int dsa_switch_suspend(struct dsa_switch *ds)
1240ea825e70SFlorian Fainelli {
1241ea825e70SFlorian Fainelli 	return 0;
1242ea825e70SFlorian Fainelli }
1243ea825e70SFlorian Fainelli static inline int dsa_switch_resume(struct dsa_switch *ds)
1244ea825e70SFlorian Fainelli {
1245ea825e70SFlorian Fainelli 	return 0;
1246ea825e70SFlorian Fainelli }
1247ea825e70SFlorian Fainelli #endif /* CONFIG_PM_SLEEP */
1248ea825e70SFlorian Fainelli 
124960724d4bSFlorian Fainelli #if IS_ENABLED(CONFIG_NET_DSA)
1250a5e3c9baSVladimir Oltean bool dsa_slave_dev_check(const struct net_device *dev);
125160724d4bSFlorian Fainelli #else
1252a5e3c9baSVladimir Oltean static inline bool dsa_slave_dev_check(const struct net_device *dev)
1253a5e3c9baSVladimir Oltean {
1254a5e3c9baSVladimir Oltean 	return false;
1255a5e3c9baSVladimir Oltean }
125660724d4bSFlorian Fainelli #endif
125760724d4bSFlorian Fainelli 
125897a69a0dSVladimir Oltean netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, struct net_device *dev);
1259cf963573SFlorian Fainelli int dsa_port_get_phy_strings(struct dsa_port *dp, uint8_t *data);
1260cf963573SFlorian Fainelli int dsa_port_get_ethtool_phy_stats(struct dsa_port *dp, uint64_t *data);
1261cf963573SFlorian Fainelli int dsa_port_get_phy_sset_count(struct dsa_port *dp);
126211d8f3ddSFlorian Fainelli void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up);
1263cf963573SFlorian Fainelli 
1264d3b8c049SAndrew Lunn struct dsa_tag_driver {
1265d3b8c049SAndrew Lunn 	const struct dsa_device_ops *ops;
1266d3b8c049SAndrew Lunn 	struct list_head list;
1267d3b8c049SAndrew Lunn 	struct module *owner;
1268d3b8c049SAndrew Lunn };
1269d3b8c049SAndrew Lunn 
1270d3b8c049SAndrew Lunn void dsa_tag_drivers_register(struct dsa_tag_driver *dsa_tag_driver_array[],
1271d3b8c049SAndrew Lunn 			      unsigned int count,
1272d3b8c049SAndrew Lunn 			      struct module *owner);
1273d3b8c049SAndrew Lunn void dsa_tag_drivers_unregister(struct dsa_tag_driver *dsa_tag_driver_array[],
1274d3b8c049SAndrew Lunn 				unsigned int count);
1275d3b8c049SAndrew Lunn 
1276d3b8c049SAndrew Lunn #define dsa_tag_driver_module_drivers(__dsa_tag_drivers_array, __count)	\
1277d3b8c049SAndrew Lunn static int __init dsa_tag_driver_module_init(void)			\
1278d3b8c049SAndrew Lunn {									\
1279d3b8c049SAndrew Lunn 	dsa_tag_drivers_register(__dsa_tag_drivers_array, __count,	\
1280d3b8c049SAndrew Lunn 				 THIS_MODULE);				\
1281d3b8c049SAndrew Lunn 	return 0;							\
1282d3b8c049SAndrew Lunn }									\
1283d3b8c049SAndrew Lunn module_init(dsa_tag_driver_module_init);				\
1284d3b8c049SAndrew Lunn 									\
1285d3b8c049SAndrew Lunn static void __exit dsa_tag_driver_module_exit(void)			\
1286d3b8c049SAndrew Lunn {									\
1287d3b8c049SAndrew Lunn 	dsa_tag_drivers_unregister(__dsa_tag_drivers_array, __count);	\
1288d3b8c049SAndrew Lunn }									\
1289d3b8c049SAndrew Lunn module_exit(dsa_tag_driver_module_exit)
1290d3b8c049SAndrew Lunn 
1291d3b8c049SAndrew Lunn /**
1292d3b8c049SAndrew Lunn  * module_dsa_tag_drivers() - Helper macro for registering DSA tag
1293d3b8c049SAndrew Lunn  * drivers
1294c7d9a675SLuiz Angelo Daros de Luca  * @__ops_array: Array of tag driver structures
1295d3b8c049SAndrew Lunn  *
1296d3b8c049SAndrew Lunn  * Helper macro for DSA tag drivers which do not do anything special
1297d3b8c049SAndrew Lunn  * in module init/exit. Each module may only use this macro once, and
1298d3b8c049SAndrew Lunn  * calling it replaces module_init() and module_exit().
1299d3b8c049SAndrew Lunn  */
1300d3b8c049SAndrew Lunn #define module_dsa_tag_drivers(__ops_array)				\
1301d3b8c049SAndrew Lunn dsa_tag_driver_module_drivers(__ops_array, ARRAY_SIZE(__ops_array))
1302d3b8c049SAndrew Lunn 
1303d3b8c049SAndrew Lunn #define DSA_TAG_DRIVER_NAME(__ops) dsa_tag_driver ## _ ## __ops
1304d3b8c049SAndrew Lunn 
1305d3b8c049SAndrew Lunn /* Create a static structure we can build a linked list of dsa_tag
1306d3b8c049SAndrew Lunn  * drivers
1307d3b8c049SAndrew Lunn  */
1308d3b8c049SAndrew Lunn #define DSA_TAG_DRIVER(__ops)						\
1309d3b8c049SAndrew Lunn static struct dsa_tag_driver DSA_TAG_DRIVER_NAME(__ops) = {		\
1310d3b8c049SAndrew Lunn 	.ops = &__ops,							\
1311d3b8c049SAndrew Lunn }
1312d3b8c049SAndrew Lunn 
1313d3b8c049SAndrew Lunn /**
1314d3b8c049SAndrew Lunn  * module_dsa_tag_driver() - Helper macro for registering a single DSA tag
1315d3b8c049SAndrew Lunn  * driver
1316d3b8c049SAndrew Lunn  * @__ops: Single tag driver structures
1317d3b8c049SAndrew Lunn  *
1318d3b8c049SAndrew Lunn  * Helper macro for DSA tag drivers which do not do anything special
1319d3b8c049SAndrew Lunn  * in module init/exit. Each module may only use this macro once, and
1320d3b8c049SAndrew Lunn  * calling it replaces module_init() and module_exit().
1321d3b8c049SAndrew Lunn  */
1322d3b8c049SAndrew Lunn #define module_dsa_tag_driver(__ops)					\
1323d3b8c049SAndrew Lunn DSA_TAG_DRIVER(__ops);							\
1324d3b8c049SAndrew Lunn 									\
1325d3b8c049SAndrew Lunn static struct dsa_tag_driver *dsa_tag_driver_array[] =	{		\
1326d3b8c049SAndrew Lunn 	&DSA_TAG_DRIVER_NAME(__ops)					\
1327d3b8c049SAndrew Lunn };									\
1328d3b8c049SAndrew Lunn module_dsa_tag_drivers(dsa_tag_driver_array)
132991da11f8SLennert Buytenhek #endif
1330d3b8c049SAndrew Lunn 
1331