xref: /openbmc/linux/include/net/dsa.h (revision a29342e7)
191da11f8SLennert Buytenhek /*
291da11f8SLennert Buytenhek  * include/net/dsa.h - Driver for Distributed Switch Architecture switch chips
3e84665c9SLennert Buytenhek  * Copyright (c) 2008-2009 Marvell Semiconductor
491da11f8SLennert Buytenhek  *
591da11f8SLennert Buytenhek  * This program is free software; you can redistribute it and/or modify
691da11f8SLennert Buytenhek  * it under the terms of the GNU General Public License as published by
791da11f8SLennert Buytenhek  * the Free Software Foundation; either version 2 of the License, or
891da11f8SLennert Buytenhek  * (at your option) any later version.
991da11f8SLennert Buytenhek  */
1091da11f8SLennert Buytenhek 
1191da11f8SLennert Buytenhek #ifndef __LINUX_NET_DSA_H
1291da11f8SLennert Buytenhek #define __LINUX_NET_DSA_H
1391da11f8SLennert Buytenhek 
144d56a29fSRussell King #include <linux/if.h>
15ea1f51beSAxel Lin #include <linux/if_ether.h>
16c8f0b869SBen Hutchings #include <linux/list.h>
17f515f192SVivien Didelot #include <linux/notifier.h>
18cf50dcc2SBen Hutchings #include <linux/timer.h>
19cf50dcc2SBen Hutchings #include <linux/workqueue.h>
20fa981d9aSFlorian Fainelli #include <linux/of.h>
21a2820543SFlorian Fainelli #include <linux/ethtool.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;
28f50f2127SFlorian Fainelli 
29ac7a04c3SFlorian Fainelli enum dsa_tag_protocol {
30ac7a04c3SFlorian Fainelli 	DSA_TAG_PROTO_NONE = 0,
31ac7a04c3SFlorian Fainelli 	DSA_TAG_PROTO_BRCM,
32eb7b7211SAndrew Lunn 	DSA_TAG_PROTO_DSA,
33eb7b7211SAndrew Lunn 	DSA_TAG_PROTO_EDSA,
348b8010fbSWoojung Huh 	DSA_TAG_PROTO_KSZ,
35e8fe177aSJuergen Beisert 	DSA_TAG_PROTO_LAN9303,
36eb7b7211SAndrew Lunn 	DSA_TAG_PROTO_MTK,
37eb7b7211SAndrew Lunn 	DSA_TAG_PROTO_QCA,
38eb7b7211SAndrew Lunn 	DSA_TAG_PROTO_TRAILER,
3939a7f2a4SAndrew Lunn 	DSA_TAG_LAST,		/* MUST BE LAST */
40ac7a04c3SFlorian Fainelli };
415037d532SFlorian Fainelli 
42e84665c9SLennert Buytenhek #define DSA_MAX_SWITCHES	4
4391da11f8SLennert Buytenhek #define DSA_MAX_PORTS		12
4491da11f8SLennert Buytenhek 
45d390238cSVivien Didelot #define DSA_RTABLE_NONE		-1
46d390238cSVivien Didelot 
47e84665c9SLennert Buytenhek struct dsa_chip_data {
48e84665c9SLennert Buytenhek 	/*
49e84665c9SLennert Buytenhek 	 * How to access the switch configuration registers.
50e84665c9SLennert Buytenhek 	 */
51b4d2394dSAlexander Duyck 	struct device	*host_dev;
52e84665c9SLennert Buytenhek 	int		sw_addr;
53e84665c9SLennert Buytenhek 
5471e0bbdeSFlorian Fainelli 	/*
5571e0bbdeSFlorian Fainelli 	 * Reference to network devices
5671e0bbdeSFlorian Fainelli 	 */
5771e0bbdeSFlorian Fainelli 	struct device	*netdev[DSA_MAX_PORTS];
5871e0bbdeSFlorian Fainelli 
596793abb4SGuenter Roeck 	/* set to size of eeprom if supported by the switch */
606793abb4SGuenter Roeck 	int		eeprom_len;
616793abb4SGuenter Roeck 
62fa981d9aSFlorian Fainelli 	/* Device tree node pointer for this specific switch chip
63fa981d9aSFlorian Fainelli 	 * used during switch setup in case additional properties
64fa981d9aSFlorian Fainelli 	 * and resources needs to be used
65fa981d9aSFlorian Fainelli 	 */
66fa981d9aSFlorian Fainelli 	struct device_node *of_node;
67fa981d9aSFlorian Fainelli 
68e84665c9SLennert Buytenhek 	/*
69e84665c9SLennert Buytenhek 	 * The names of the switch's ports.  Use "cpu" to
70e84665c9SLennert Buytenhek 	 * designate the switch port that the cpu is connected to,
71e84665c9SLennert Buytenhek 	 * "dsa" to indicate that this port is a DSA link to
72e84665c9SLennert Buytenhek 	 * another switch, NULL to indicate the port is unused,
73e84665c9SLennert Buytenhek 	 * or any other string to indicate this is a physical port.
74e84665c9SLennert Buytenhek 	 */
75e84665c9SLennert Buytenhek 	char		*port_names[DSA_MAX_PORTS];
76bd47497aSFlorian Fainelli 	struct device_node *port_dn[DSA_MAX_PORTS];
77e84665c9SLennert Buytenhek 
78e84665c9SLennert Buytenhek 	/*
794a7704ffSAndrew Lunn 	 * An array of which element [a] indicates which port on this
804a7704ffSAndrew Lunn 	 * switch should be used to send packets to that are destined
814a7704ffSAndrew Lunn 	 * for switch a. Can be NULL if there is only one switch chip.
82e84665c9SLennert Buytenhek 	 */
834a7704ffSAndrew Lunn 	s8		rtable[DSA_MAX_SWITCHES];
84e84665c9SLennert Buytenhek };
85e84665c9SLennert Buytenhek 
8691da11f8SLennert Buytenhek struct dsa_platform_data {
8791da11f8SLennert Buytenhek 	/*
8891da11f8SLennert Buytenhek 	 * Reference to a Linux network interface that connects
89e84665c9SLennert Buytenhek 	 * to the root switch chip of the tree.
9091da11f8SLennert Buytenhek 	 */
9191da11f8SLennert Buytenhek 	struct device	*netdev;
92769a0202SFlorian Fainelli 	struct net_device *of_netdev;
9391da11f8SLennert Buytenhek 
9491da11f8SLennert Buytenhek 	/*
95e84665c9SLennert Buytenhek 	 * Info structs describing each of the switch chips
96e84665c9SLennert Buytenhek 	 * connected via this network interface.
9791da11f8SLennert Buytenhek 	 */
98e84665c9SLennert Buytenhek 	int		nr_chips;
99e84665c9SLennert Buytenhek 	struct dsa_chip_data	*chip;
10091da11f8SLennert Buytenhek };
10191da11f8SLennert Buytenhek 
1025075314eSAlexander Duyck struct packet_type;
1033e8a72d1SFlorian Fainelli 
104cf50dcc2SBen Hutchings struct dsa_switch_tree {
10583c0afaeSAndrew Lunn 	struct list_head	list;
10683c0afaeSAndrew Lunn 
107f515f192SVivien Didelot 	/* Notifier chain for switch-wide events */
108f515f192SVivien Didelot 	struct raw_notifier_head	nh;
109f515f192SVivien Didelot 
11083c0afaeSAndrew Lunn 	/* Tree identifier */
11183c0afaeSAndrew Lunn 	u32 tree;
11283c0afaeSAndrew Lunn 
11383c0afaeSAndrew Lunn 	/* Number of switches attached to this tree */
11483c0afaeSAndrew Lunn 	struct kref refcount;
11583c0afaeSAndrew Lunn 
11683c0afaeSAndrew Lunn 	/* Has this tree been applied to the hardware? */
11783c0afaeSAndrew Lunn 	bool applied;
11883c0afaeSAndrew Lunn 
119cf50dcc2SBen Hutchings 	/*
120cf50dcc2SBen Hutchings 	 * Configuration data for the platform device that owns
121cf50dcc2SBen Hutchings 	 * this dsa switch tree instance.
122cf50dcc2SBen Hutchings 	 */
123cf50dcc2SBen Hutchings 	struct dsa_platform_data	*pd;
124cf85d08fSLennert Buytenhek 
12573a7ece8SVivien Didelot 	/* Copy of tag_ops->rcv for faster access in hot path */
126a86d8becSFlorian Fainelli 	struct sk_buff *	(*rcv)(struct sk_buff *skb,
1275075314eSAlexander Duyck 				       struct net_device *dev,
1285075314eSAlexander Duyck 				       struct packet_type *pt,
1295075314eSAlexander Duyck 				       struct net_device *orig_dev);
130cf50dcc2SBen Hutchings 
131cf50dcc2SBen Hutchings 	/*
1328b0d3ea5SVivien Didelot 	 * The switch port to which the CPU is attached.
133cf50dcc2SBen Hutchings 	 */
1348b0d3ea5SVivien Didelot 	struct dsa_port		*cpu_dp;
135cf50dcc2SBen Hutchings 
136cf50dcc2SBen Hutchings 	/*
137cf50dcc2SBen Hutchings 	 * Data for the individual switch chips.
138cf50dcc2SBen Hutchings 	 */
139cf50dcc2SBen Hutchings 	struct dsa_switch	*ds[DSA_MAX_SWITCHES];
14039a7f2a4SAndrew Lunn 
14139a7f2a4SAndrew Lunn 	/*
14239a7f2a4SAndrew Lunn 	 * Tagging protocol operations for adding and removing an
14339a7f2a4SAndrew Lunn 	 * encapsulation tag.
14439a7f2a4SAndrew Lunn 	 */
14539a7f2a4SAndrew Lunn 	const struct dsa_device_ops *tag_ops;
146cf50dcc2SBen Hutchings };
147cf50dcc2SBen Hutchings 
148f50f2127SFlorian Fainelli /* TC matchall action types, only mirroring for now */
149f50f2127SFlorian Fainelli enum dsa_port_mall_action_type {
150f50f2127SFlorian Fainelli 	DSA_PORT_MALL_MIRROR,
151f50f2127SFlorian Fainelli };
152f50f2127SFlorian Fainelli 
153f50f2127SFlorian Fainelli /* TC mirroring entry */
154f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry {
155f50f2127SFlorian Fainelli 	u8 to_local_port;
156f50f2127SFlorian Fainelli 	bool ingress;
157f50f2127SFlorian Fainelli };
158f50f2127SFlorian Fainelli 
159f50f2127SFlorian Fainelli /* TC matchall entry */
160f50f2127SFlorian Fainelli struct dsa_mall_tc_entry {
161f50f2127SFlorian Fainelli 	struct list_head list;
162f50f2127SFlorian Fainelli 	unsigned long cookie;
163f50f2127SFlorian Fainelli 	enum dsa_port_mall_action_type type;
164f50f2127SFlorian Fainelli 	union {
165f50f2127SFlorian Fainelli 		struct dsa_mall_mirror_tc_entry mirror;
166f50f2127SFlorian Fainelli 	};
167f50f2127SFlorian Fainelli };
168f50f2127SFlorian Fainelli 
169f50f2127SFlorian Fainelli 
170c8b09808SAndrew Lunn struct dsa_port {
171818be848SVivien Didelot 	struct dsa_switch	*ds;
172818be848SVivien Didelot 	unsigned int		index;
17371e0bbdeSFlorian Fainelli 	const char		*name;
174a29342e7SFlorian Fainelli 	struct dsa_port		*cpu_dp;
175c8b09808SAndrew Lunn 	struct net_device	*netdev;
176189b0d93SAndrew Lunn 	struct device_node	*dn;
17734a79f63SVivien Didelot 	unsigned int		ageing_time;
178732f794cSVivien Didelot 	u8			stp_state;
179a5e9a02eSVivien Didelot 	struct net_device	*bridge_dev;
18096567d5dSAndrew Lunn 	struct devlink_port	devlink_port;
18167dbb9d4SFlorian Fainelli 	/*
18267dbb9d4SFlorian Fainelli 	 * Original copy of the master netdev ethtool_ops
18367dbb9d4SFlorian Fainelli 	 */
18467dbb9d4SFlorian Fainelli 	struct ethtool_ops	ethtool_ops;
18567dbb9d4SFlorian Fainelli 	const struct ethtool_ops *orig_ethtool_ops;
186c8b09808SAndrew Lunn };
187c8b09808SAndrew Lunn 
188c8f0b869SBen Hutchings struct dsa_switch {
189c33063d6SAndrew Lunn 	struct device *dev;
190c33063d6SAndrew Lunn 
191c8f0b869SBen Hutchings 	/*
192c8f0b869SBen Hutchings 	 * Parent switch tree, and switch index.
193c8f0b869SBen Hutchings 	 */
194c8f0b869SBen Hutchings 	struct dsa_switch_tree	*dst;
195c8f0b869SBen Hutchings 	int			index;
196c8f0b869SBen Hutchings 
197f515f192SVivien Didelot 	/* Listener for switch fabric events */
198f515f192SVivien Didelot 	struct notifier_block	nb;
199f515f192SVivien Didelot 
200c8f0b869SBen Hutchings 	/*
2017543a6d5SAndrew Lunn 	 * Give the switch driver somewhere to hang its private data
2027543a6d5SAndrew Lunn 	 * structure.
2037543a6d5SAndrew Lunn 	 */
2047543a6d5SAndrew Lunn 	void *priv;
2057543a6d5SAndrew Lunn 
2067543a6d5SAndrew Lunn 	/*
207c8f0b869SBen Hutchings 	 * Configuration data for this switch.
208c8f0b869SBen Hutchings 	 */
209ff04955cSAndrew Lunn 	struct dsa_chip_data	*cd;
210c8f0b869SBen Hutchings 
211c8f0b869SBen Hutchings 	/*
2129d490b4eSVivien Didelot 	 * The switch operations.
213c8f0b869SBen Hutchings 	 */
214a82f67afSFlorian Fainelli 	const struct dsa_switch_ops	*ops;
215c8f0b869SBen Hutchings 
21666472fc0SAndrew Lunn 	/*
21766472fc0SAndrew Lunn 	 * An array of which element [a] indicates which port on this
21866472fc0SAndrew Lunn 	 * switch should be used to send packets to that are destined
21966472fc0SAndrew Lunn 	 * for switch a. Can be NULL if there is only one switch chip.
22066472fc0SAndrew Lunn 	 */
22166472fc0SAndrew Lunn 	s8		rtable[DSA_MAX_SWITCHES];
22266472fc0SAndrew Lunn 
223c8f0b869SBen Hutchings 	/*
224c8f0b869SBen Hutchings 	 * Slave mii_bus and devices for the individual ports.
225c8f0b869SBen Hutchings 	 */
226c8f0b869SBen Hutchings 	u32			dsa_port_mask;
22783c0afaeSAndrew Lunn 	u32			cpu_port_mask;
22874c3e2a5SAndrew Lunn 	u32			enabled_port_mask;
2290d8bcdd3SFlorian Fainelli 	u32			phys_mii_mask;
230c8f0b869SBen Hutchings 	struct mii_bus		*slave_mii_bus;
231a0c02161SVivien Didelot 
2320f3da6afSVivien Didelot 	/* Ageing Time limits in msecs */
2330f3da6afSVivien Didelot 	unsigned int ageing_time_min;
2340f3da6afSVivien Didelot 	unsigned int ageing_time_max;
2350f3da6afSVivien Didelot 
23696567d5dSAndrew Lunn 	/* devlink used to represent this switch device */
23796567d5dSAndrew Lunn 	struct devlink		*devlink;
23896567d5dSAndrew Lunn 
239a0c02161SVivien Didelot 	/* Dynamically allocated ports, keep last */
240a0c02161SVivien Didelot 	size_t num_ports;
241a0c02161SVivien Didelot 	struct dsa_port ports[];
242c8f0b869SBen Hutchings };
243c8f0b869SBen Hutchings 
244c8f0b869SBen Hutchings static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
245c8f0b869SBen Hutchings {
24614be36c2SFlorian Fainelli 	return !!(ds->cpu_port_mask & (1 << p));
247c8f0b869SBen Hutchings }
248c8f0b869SBen Hutchings 
24960045cbfSAndrew Lunn static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p)
25060045cbfSAndrew Lunn {
25160045cbfSAndrew Lunn 	return !!((ds->dsa_port_mask) & (1 << p));
25260045cbfSAndrew Lunn }
25360045cbfSAndrew Lunn 
2546cd456f3SVivien Didelot static inline bool dsa_is_normal_port(struct dsa_switch *ds, int p)
2556cd456f3SVivien Didelot {
2566cd456f3SVivien Didelot 	return !dsa_is_cpu_port(ds, p) && !dsa_is_dsa_port(ds, p);
2576cd456f3SVivien Didelot }
2586cd456f3SVivien Didelot 
259d79d2107SGuenter Roeck static inline bool dsa_is_port_initialized(struct dsa_switch *ds, int p)
260d79d2107SGuenter Roeck {
261c8b09808SAndrew Lunn 	return ds->enabled_port_mask & (1 << p) && ds->ports[p].netdev;
262d79d2107SGuenter Roeck }
263d79d2107SGuenter Roeck 
264c8f0b869SBen Hutchings static inline u8 dsa_upstream_port(struct dsa_switch *ds)
265c8f0b869SBen Hutchings {
266c8f0b869SBen Hutchings 	struct dsa_switch_tree *dst = ds->dst;
267c8f0b869SBen Hutchings 
268c8f0b869SBen Hutchings 	/*
269c8f0b869SBen Hutchings 	 * If this is the root switch (i.e. the switch that connects
270c8f0b869SBen Hutchings 	 * to the CPU), return the cpu port number on this switch.
271c8f0b869SBen Hutchings 	 * Else return the (DSA) port number that connects to the
272c8f0b869SBen Hutchings 	 * switch that is one hop closer to the cpu.
273c8f0b869SBen Hutchings 	 */
2748b0d3ea5SVivien Didelot 	if (dst->cpu_dp->ds == ds)
2758b0d3ea5SVivien Didelot 		return dst->cpu_dp->index;
276c8f0b869SBen Hutchings 	else
2778b0d3ea5SVivien Didelot 		return ds->rtable[dst->cpu_dp->ds->index];
278c8f0b869SBen Hutchings }
279c8f0b869SBen Hutchings 
2809d490b4eSVivien Didelot struct dsa_switch_ops {
281c8f0b869SBen Hutchings 	/*
282a6a71f19SVivien Didelot 	 * Legacy probing.
283c8f0b869SBen Hutchings 	 */
2840209d144SVivien Didelot 	const char	*(*probe)(struct device *dsa_dev,
2850209d144SVivien Didelot 				  struct device *host_dev, int sw_addr,
2860209d144SVivien Didelot 				  void **priv);
2877b314362SAndrew Lunn 
2887b314362SAndrew Lunn 	enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds);
2897b314362SAndrew Lunn 
290c8f0b869SBen Hutchings 	int	(*setup)(struct dsa_switch *ds);
291c8f0b869SBen Hutchings 	int	(*set_addr)(struct dsa_switch *ds, u8 *addr);
2926819563eSFlorian Fainelli 	u32	(*get_phy_flags)(struct dsa_switch *ds, int port);
293c8f0b869SBen Hutchings 
294c8f0b869SBen Hutchings 	/*
295c8f0b869SBen Hutchings 	 * Access to the switch's PHY registers.
296c8f0b869SBen Hutchings 	 */
297c8f0b869SBen Hutchings 	int	(*phy_read)(struct dsa_switch *ds, int port, int regnum);
298c8f0b869SBen Hutchings 	int	(*phy_write)(struct dsa_switch *ds, int port,
299c8f0b869SBen Hutchings 			     int regnum, u16 val);
300c8f0b869SBen Hutchings 
301c8f0b869SBen Hutchings 	/*
302ec9436baSFlorian Fainelli 	 * Link state adjustment (called from libphy)
303ec9436baSFlorian Fainelli 	 */
304ec9436baSFlorian Fainelli 	void	(*adjust_link)(struct dsa_switch *ds, int port,
305ec9436baSFlorian Fainelli 				struct phy_device *phydev);
306ce31b31cSFlorian Fainelli 	void	(*fixed_link_update)(struct dsa_switch *ds, int port,
307ce31b31cSFlorian Fainelli 				struct fixed_phy_status *st);
308ec9436baSFlorian Fainelli 
309ec9436baSFlorian Fainelli 	/*
310c8f0b869SBen Hutchings 	 * ethtool hardware statistics.
311c8f0b869SBen Hutchings 	 */
312c8f0b869SBen Hutchings 	void	(*get_strings)(struct dsa_switch *ds, int port, uint8_t *data);
313c8f0b869SBen Hutchings 	void	(*get_ethtool_stats)(struct dsa_switch *ds,
314c8f0b869SBen Hutchings 				     int port, uint64_t *data);
315c8f0b869SBen Hutchings 	int	(*get_sset_count)(struct dsa_switch *ds);
31624462549SFlorian Fainelli 
31724462549SFlorian Fainelli 	/*
31819e57c4eSFlorian Fainelli 	 * ethtool Wake-on-LAN
31919e57c4eSFlorian Fainelli 	 */
32019e57c4eSFlorian Fainelli 	void	(*get_wol)(struct dsa_switch *ds, int port,
32119e57c4eSFlorian Fainelli 			   struct ethtool_wolinfo *w);
32219e57c4eSFlorian Fainelli 	int	(*set_wol)(struct dsa_switch *ds, int port,
32319e57c4eSFlorian Fainelli 			   struct ethtool_wolinfo *w);
32419e57c4eSFlorian Fainelli 
32519e57c4eSFlorian Fainelli 	/*
32624462549SFlorian Fainelli 	 * Suspend and resume
32724462549SFlorian Fainelli 	 */
32824462549SFlorian Fainelli 	int	(*suspend)(struct dsa_switch *ds);
32924462549SFlorian Fainelli 	int	(*resume)(struct dsa_switch *ds);
330b2f2af21SFlorian Fainelli 
331b2f2af21SFlorian Fainelli 	/*
332b2f2af21SFlorian Fainelli 	 * Port enable/disable
333b2f2af21SFlorian Fainelli 	 */
334b2f2af21SFlorian Fainelli 	int	(*port_enable)(struct dsa_switch *ds, int port,
335b2f2af21SFlorian Fainelli 			       struct phy_device *phy);
336b2f2af21SFlorian Fainelli 	void	(*port_disable)(struct dsa_switch *ds, int port,
337b2f2af21SFlorian Fainelli 				struct phy_device *phy);
3387905288fSFlorian Fainelli 
3397905288fSFlorian Fainelli 	/*
3407905288fSFlorian Fainelli 	 * EEE setttings
3417905288fSFlorian Fainelli 	 */
3427905288fSFlorian Fainelli 	int	(*set_eee)(struct dsa_switch *ds, int port,
3437905288fSFlorian Fainelli 			   struct phy_device *phydev,
3447905288fSFlorian Fainelli 			   struct ethtool_eee *e);
3457905288fSFlorian Fainelli 	int	(*get_eee)(struct dsa_switch *ds, int port,
3467905288fSFlorian Fainelli 			   struct ethtool_eee *e);
34751579c3fSGuenter Roeck 
3486793abb4SGuenter Roeck 	/* EEPROM access */
3496793abb4SGuenter Roeck 	int	(*get_eeprom_len)(struct dsa_switch *ds);
3506793abb4SGuenter Roeck 	int	(*get_eeprom)(struct dsa_switch *ds,
3516793abb4SGuenter Roeck 			      struct ethtool_eeprom *eeprom, u8 *data);
3526793abb4SGuenter Roeck 	int	(*set_eeprom)(struct dsa_switch *ds,
3536793abb4SGuenter Roeck 			      struct ethtool_eeprom *eeprom, u8 *data);
3543d762a0fSGuenter Roeck 
3553d762a0fSGuenter Roeck 	/*
3563d762a0fSGuenter Roeck 	 * Register access.
3573d762a0fSGuenter Roeck 	 */
3583d762a0fSGuenter Roeck 	int	(*get_regs_len)(struct dsa_switch *ds, int port);
3593d762a0fSGuenter Roeck 	void	(*get_regs)(struct dsa_switch *ds, int port,
3603d762a0fSGuenter Roeck 			    struct ethtool_regs *regs, void *p);
361b73adef6SFlorian Fainelli 
362b73adef6SFlorian Fainelli 	/*
363b73adef6SFlorian Fainelli 	 * Bridge integration
364b73adef6SFlorian Fainelli 	 */
36534a79f63SVivien Didelot 	int	(*set_ageing_time)(struct dsa_switch *ds, unsigned int msecs);
36671327a4eSVivien Didelot 	int	(*port_bridge_join)(struct dsa_switch *ds, int port,
367a6692754SVivien Didelot 				    struct net_device *bridge);
368f123f2fbSVivien Didelot 	void	(*port_bridge_leave)(struct dsa_switch *ds, int port,
369f123f2fbSVivien Didelot 				     struct net_device *bridge);
37043c44a9fSVivien Didelot 	void	(*port_stp_state_set)(struct dsa_switch *ds, int port,
371b73adef6SFlorian Fainelli 				      u8 state);
372732f794cSVivien Didelot 	void	(*port_fast_age)(struct dsa_switch *ds, int port);
3732a778e1bSVivien Didelot 
3742a778e1bSVivien Didelot 	/*
37511149536SVivien Didelot 	 * VLAN support
37611149536SVivien Didelot 	 */
377fb2dabadSVivien Didelot 	int	(*port_vlan_filtering)(struct dsa_switch *ds, int port,
378fb2dabadSVivien Didelot 				       bool vlan_filtering);
37976e398a6SVivien Didelot 	int	(*port_vlan_prepare)(struct dsa_switch *ds, int port,
38076e398a6SVivien Didelot 				     const struct switchdev_obj_port_vlan *vlan,
38176e398a6SVivien Didelot 				     struct switchdev_trans *trans);
3824d5770b3SVivien Didelot 	void	(*port_vlan_add)(struct dsa_switch *ds, int port,
38376e398a6SVivien Didelot 				 const struct switchdev_obj_port_vlan *vlan,
38476e398a6SVivien Didelot 				 struct switchdev_trans *trans);
38576e398a6SVivien Didelot 	int	(*port_vlan_del)(struct dsa_switch *ds, int port,
38676e398a6SVivien Didelot 				 const struct switchdev_obj_port_vlan *vlan);
38765aebfc0SVivien Didelot 	int	(*port_vlan_dump)(struct dsa_switch *ds, int port,
38865aebfc0SVivien Didelot 				  struct switchdev_obj_port_vlan *vlan,
389438ff537SVivien Didelot 				  switchdev_obj_dump_cb_t *cb);
39011149536SVivien Didelot 
39111149536SVivien Didelot 	/*
3922a778e1bSVivien Didelot 	 * Forwarding database
3932a778e1bSVivien Didelot 	 */
394146a3206SVivien Didelot 	int	(*port_fdb_prepare)(struct dsa_switch *ds, int port,
395146a3206SVivien Didelot 				    const struct switchdev_obj_port_fdb *fdb,
396146a3206SVivien Didelot 				    struct switchdev_trans *trans);
3978497aa61SVivien Didelot 	void	(*port_fdb_add)(struct dsa_switch *ds, int port,
3981f36faf2SVivien Didelot 				const struct switchdev_obj_port_fdb *fdb,
3991f36faf2SVivien Didelot 				struct switchdev_trans *trans);
4002a778e1bSVivien Didelot 	int	(*port_fdb_del)(struct dsa_switch *ds, int port,
4018057b3e7SVivien Didelot 				const struct switchdev_obj_port_fdb *fdb);
402ea70ba98SVivien Didelot 	int	(*port_fdb_dump)(struct dsa_switch *ds, int port,
403ea70ba98SVivien Didelot 				 struct switchdev_obj_port_fdb *fdb,
404438ff537SVivien Didelot 				  switchdev_obj_dump_cb_t *cb);
4058df30255SVivien Didelot 
4068df30255SVivien Didelot 	/*
4078df30255SVivien Didelot 	 * Multicast database
4088df30255SVivien Didelot 	 */
4098df30255SVivien Didelot 	int	(*port_mdb_prepare)(struct dsa_switch *ds, int port,
4108df30255SVivien Didelot 				    const struct switchdev_obj_port_mdb *mdb,
4118df30255SVivien Didelot 				    struct switchdev_trans *trans);
4128df30255SVivien Didelot 	void	(*port_mdb_add)(struct dsa_switch *ds, int port,
4138df30255SVivien Didelot 				const struct switchdev_obj_port_mdb *mdb,
4148df30255SVivien Didelot 				struct switchdev_trans *trans);
4158df30255SVivien Didelot 	int	(*port_mdb_del)(struct dsa_switch *ds, int port,
4168df30255SVivien Didelot 				const struct switchdev_obj_port_mdb *mdb);
4178df30255SVivien Didelot 	int	(*port_mdb_dump)(struct dsa_switch *ds, int port,
4188df30255SVivien Didelot 				 struct switchdev_obj_port_mdb *mdb,
419438ff537SVivien Didelot 				  switchdev_obj_dump_cb_t *cb);
420bf9f2648SFlorian Fainelli 
421bf9f2648SFlorian Fainelli 	/*
422bf9f2648SFlorian Fainelli 	 * RXNFC
423bf9f2648SFlorian Fainelli 	 */
424bf9f2648SFlorian Fainelli 	int	(*get_rxnfc)(struct dsa_switch *ds, int port,
425bf9f2648SFlorian Fainelli 			     struct ethtool_rxnfc *nfc, u32 *rule_locs);
426bf9f2648SFlorian Fainelli 	int	(*set_rxnfc)(struct dsa_switch *ds, int port,
427bf9f2648SFlorian Fainelli 			     struct ethtool_rxnfc *nfc);
428f50f2127SFlorian Fainelli 
429f50f2127SFlorian Fainelli 	/*
430f50f2127SFlorian Fainelli 	 * TC integration
431f50f2127SFlorian Fainelli 	 */
432f50f2127SFlorian Fainelli 	int	(*port_mirror_add)(struct dsa_switch *ds, int port,
433f50f2127SFlorian Fainelli 				   struct dsa_mall_mirror_tc_entry *mirror,
434f50f2127SFlorian Fainelli 				   bool ingress);
435f50f2127SFlorian Fainelli 	void	(*port_mirror_del)(struct dsa_switch *ds, int port,
436f50f2127SFlorian Fainelli 				   struct dsa_mall_mirror_tc_entry *mirror);
43740ef2c93SVivien Didelot 
43840ef2c93SVivien Didelot 	/*
43940ef2c93SVivien Didelot 	 * Cross-chip operations
44040ef2c93SVivien Didelot 	 */
44140ef2c93SVivien Didelot 	int	(*crosschip_bridge_join)(struct dsa_switch *ds, int sw_index,
44240ef2c93SVivien Didelot 					 int port, struct net_device *br);
44340ef2c93SVivien Didelot 	void	(*crosschip_bridge_leave)(struct dsa_switch *ds, int sw_index,
44440ef2c93SVivien Didelot 					  int port, struct net_device *br);
445c8f0b869SBen Hutchings };
446c8f0b869SBen Hutchings 
447ab3d408dSFlorian Fainelli struct dsa_switch_driver {
448ab3d408dSFlorian Fainelli 	struct list_head	list;
449a82f67afSFlorian Fainelli 	const struct dsa_switch_ops *ops;
450ab3d408dSFlorian Fainelli };
451ab3d408dSFlorian Fainelli 
452a6a71f19SVivien Didelot /* Legacy driver registration */
453ab3d408dSFlorian Fainelli void register_switch_driver(struct dsa_switch_driver *type);
454ab3d408dSFlorian Fainelli void unregister_switch_driver(struct dsa_switch_driver *type);
455b4d2394dSAlexander Duyck struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev);
456a6a71f19SVivien Didelot 
45714b89f36SFlorian Fainelli struct net_device *dsa_dev_to_net_device(struct device *dev);
458c8f0b869SBen Hutchings 
45973a7ece8SVivien Didelot /* Keep inline for faster access in hot path */
460c6e970a0SAndrew Lunn static inline bool netdev_uses_dsa(struct net_device *dev)
461c6e970a0SAndrew Lunn {
462c6e970a0SAndrew Lunn #if IS_ENABLED(CONFIG_NET_DSA)
463717ffbfbSVivien Didelot 	return dev->dsa_ptr && dev->dsa_ptr->rcv;
464c6e970a0SAndrew Lunn #endif
465c6e970a0SAndrew Lunn 	return false;
466c6e970a0SAndrew Lunn }
467c6e970a0SAndrew Lunn 
468a0c02161SVivien Didelot struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n);
46983c0afaeSAndrew Lunn void dsa_unregister_switch(struct dsa_switch *ds);
47023c9ee49SVivien Didelot int dsa_register_switch(struct dsa_switch *ds);
471ea825e70SFlorian Fainelli #ifdef CONFIG_PM_SLEEP
472ea825e70SFlorian Fainelli int dsa_switch_suspend(struct dsa_switch *ds);
473ea825e70SFlorian Fainelli int dsa_switch_resume(struct dsa_switch *ds);
474ea825e70SFlorian Fainelli #else
475ea825e70SFlorian Fainelli static inline int dsa_switch_suspend(struct dsa_switch *ds)
476ea825e70SFlorian Fainelli {
477ea825e70SFlorian Fainelli 	return 0;
478ea825e70SFlorian Fainelli }
479ea825e70SFlorian Fainelli static inline int dsa_switch_resume(struct dsa_switch *ds)
480ea825e70SFlorian Fainelli {
481ea825e70SFlorian Fainelli 	return 0;
482ea825e70SFlorian Fainelli }
483ea825e70SFlorian Fainelli #endif /* CONFIG_PM_SLEEP */
484ea825e70SFlorian Fainelli 
48591da11f8SLennert Buytenhek #endif
486