xref: /openbmc/linux/include/net/dsa.h (revision a86d8bec)
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>
23cf50dcc2SBen Hutchings 
24f50f2127SFlorian Fainelli struct tc_action;
254d56a29fSRussell King struct phy_device;
264d56a29fSRussell King struct fixed_phy_status;
27f50f2127SFlorian Fainelli 
28ac7a04c3SFlorian Fainelli enum dsa_tag_protocol {
29ac7a04c3SFlorian Fainelli 	DSA_TAG_PROTO_NONE = 0,
30ac7a04c3SFlorian Fainelli 	DSA_TAG_PROTO_DSA,
31ac7a04c3SFlorian Fainelli 	DSA_TAG_PROTO_TRAILER,
32ac7a04c3SFlorian Fainelli 	DSA_TAG_PROTO_EDSA,
33ac7a04c3SFlorian Fainelli 	DSA_TAG_PROTO_BRCM,
34cafdc45cSJohn Crispin 	DSA_TAG_PROTO_QCA,
355cd8985aSSean Wang 	DSA_TAG_PROTO_MTK,
3639a7f2a4SAndrew Lunn 	DSA_TAG_LAST,		/* MUST BE LAST */
37ac7a04c3SFlorian Fainelli };
385037d532SFlorian Fainelli 
39e84665c9SLennert Buytenhek #define DSA_MAX_SWITCHES	4
4091da11f8SLennert Buytenhek #define DSA_MAX_PORTS		12
4191da11f8SLennert Buytenhek 
42d390238cSVivien Didelot #define DSA_RTABLE_NONE		-1
43d390238cSVivien Didelot 
44e84665c9SLennert Buytenhek struct dsa_chip_data {
45e84665c9SLennert Buytenhek 	/*
46e84665c9SLennert Buytenhek 	 * How to access the switch configuration registers.
47e84665c9SLennert Buytenhek 	 */
48b4d2394dSAlexander Duyck 	struct device	*host_dev;
49e84665c9SLennert Buytenhek 	int		sw_addr;
50e84665c9SLennert Buytenhek 
5171e0bbdeSFlorian Fainelli 	/*
5271e0bbdeSFlorian Fainelli 	 * Reference to network devices
5371e0bbdeSFlorian Fainelli 	 */
5471e0bbdeSFlorian Fainelli 	struct device	*netdev[DSA_MAX_PORTS];
5571e0bbdeSFlorian Fainelli 
566793abb4SGuenter Roeck 	/* set to size of eeprom if supported by the switch */
576793abb4SGuenter Roeck 	int		eeprom_len;
586793abb4SGuenter Roeck 
59fa981d9aSFlorian Fainelli 	/* Device tree node pointer for this specific switch chip
60fa981d9aSFlorian Fainelli 	 * used during switch setup in case additional properties
61fa981d9aSFlorian Fainelli 	 * and resources needs to be used
62fa981d9aSFlorian Fainelli 	 */
63fa981d9aSFlorian Fainelli 	struct device_node *of_node;
64fa981d9aSFlorian Fainelli 
65e84665c9SLennert Buytenhek 	/*
66e84665c9SLennert Buytenhek 	 * The names of the switch's ports.  Use "cpu" to
67e84665c9SLennert Buytenhek 	 * designate the switch port that the cpu is connected to,
68e84665c9SLennert Buytenhek 	 * "dsa" to indicate that this port is a DSA link to
69e84665c9SLennert Buytenhek 	 * another switch, NULL to indicate the port is unused,
70e84665c9SLennert Buytenhek 	 * or any other string to indicate this is a physical port.
71e84665c9SLennert Buytenhek 	 */
72e84665c9SLennert Buytenhek 	char		*port_names[DSA_MAX_PORTS];
73bd47497aSFlorian Fainelli 	struct device_node *port_dn[DSA_MAX_PORTS];
74e84665c9SLennert Buytenhek 
75e84665c9SLennert Buytenhek 	/*
764a7704ffSAndrew Lunn 	 * An array of which element [a] indicates which port on this
774a7704ffSAndrew Lunn 	 * switch should be used to send packets to that are destined
784a7704ffSAndrew Lunn 	 * for switch a. Can be NULL if there is only one switch chip.
79e84665c9SLennert Buytenhek 	 */
804a7704ffSAndrew Lunn 	s8		rtable[DSA_MAX_SWITCHES];
81e84665c9SLennert Buytenhek };
82e84665c9SLennert Buytenhek 
8391da11f8SLennert Buytenhek struct dsa_platform_data {
8491da11f8SLennert Buytenhek 	/*
8591da11f8SLennert Buytenhek 	 * Reference to a Linux network interface that connects
86e84665c9SLennert Buytenhek 	 * to the root switch chip of the tree.
8791da11f8SLennert Buytenhek 	 */
8891da11f8SLennert Buytenhek 	struct device	*netdev;
89769a0202SFlorian Fainelli 	struct net_device *of_netdev;
9091da11f8SLennert Buytenhek 
9191da11f8SLennert Buytenhek 	/*
92e84665c9SLennert Buytenhek 	 * Info structs describing each of the switch chips
93e84665c9SLennert Buytenhek 	 * connected via this network interface.
9491da11f8SLennert Buytenhek 	 */
95e84665c9SLennert Buytenhek 	int		nr_chips;
96e84665c9SLennert Buytenhek 	struct dsa_chip_data	*chip;
9791da11f8SLennert Buytenhek };
9891da11f8SLennert Buytenhek 
995075314eSAlexander Duyck struct packet_type;
1003e8a72d1SFlorian Fainelli 
101cf50dcc2SBen Hutchings struct dsa_switch_tree {
10283c0afaeSAndrew Lunn 	struct list_head	list;
10383c0afaeSAndrew Lunn 
104f515f192SVivien Didelot 	/* Notifier chain for switch-wide events */
105f515f192SVivien Didelot 	struct raw_notifier_head	nh;
106f515f192SVivien Didelot 
10783c0afaeSAndrew Lunn 	/* Tree identifier */
10883c0afaeSAndrew Lunn 	u32 tree;
10983c0afaeSAndrew Lunn 
11083c0afaeSAndrew Lunn 	/* Number of switches attached to this tree */
11183c0afaeSAndrew Lunn 	struct kref refcount;
11283c0afaeSAndrew Lunn 
11383c0afaeSAndrew Lunn 	/* Has this tree been applied to the hardware? */
11483c0afaeSAndrew Lunn 	bool applied;
11583c0afaeSAndrew Lunn 
116cf50dcc2SBen Hutchings 	/*
117cf50dcc2SBen Hutchings 	 * Configuration data for the platform device that owns
118cf50dcc2SBen Hutchings 	 * this dsa switch tree instance.
119cf50dcc2SBen Hutchings 	 */
120cf50dcc2SBen Hutchings 	struct dsa_platform_data	*pd;
121cf85d08fSLennert Buytenhek 
122cf50dcc2SBen Hutchings 	/*
123cf50dcc2SBen Hutchings 	 * Reference to network device to use, and which tagging
124cf50dcc2SBen Hutchings 	 * protocol to use.
125cf50dcc2SBen Hutchings 	 */
126cf50dcc2SBen Hutchings 	struct net_device	*master_netdev;
127a86d8becSFlorian Fainelli 	struct sk_buff *	(*rcv)(struct sk_buff *skb,
1285075314eSAlexander Duyck 				       struct net_device *dev,
1295075314eSAlexander Duyck 				       struct packet_type *pt,
1305075314eSAlexander Duyck 				       struct net_device *orig_dev);
131cf50dcc2SBen Hutchings 
132cf50dcc2SBen Hutchings 	/*
133badf3adaSFlorian Fainelli 	 * Original copy of the master netdev ethtool_ops
134badf3adaSFlorian Fainelli 	 */
135badf3adaSFlorian Fainelli 	struct ethtool_ops	master_ethtool_ops;
1360c73c523SFlorian Fainelli 	const struct ethtool_ops *master_orig_ethtool_ops;
137badf3adaSFlorian Fainelli 
138badf3adaSFlorian Fainelli 	/*
139cf50dcc2SBen Hutchings 	 * The switch and port to which the CPU is attached.
140cf50dcc2SBen Hutchings 	 */
141b22de490SVivien Didelot 	struct dsa_switch	*cpu_switch;
142cf50dcc2SBen Hutchings 	s8			cpu_port;
143cf50dcc2SBen Hutchings 
144cf50dcc2SBen Hutchings 	/*
145cf50dcc2SBen Hutchings 	 * Data for the individual switch chips.
146cf50dcc2SBen Hutchings 	 */
147cf50dcc2SBen Hutchings 	struct dsa_switch	*ds[DSA_MAX_SWITCHES];
14839a7f2a4SAndrew Lunn 
14939a7f2a4SAndrew Lunn 	/*
15039a7f2a4SAndrew Lunn 	 * Tagging protocol operations for adding and removing an
15139a7f2a4SAndrew Lunn 	 * encapsulation tag.
15239a7f2a4SAndrew Lunn 	 */
15339a7f2a4SAndrew Lunn 	const struct dsa_device_ops *tag_ops;
154cf50dcc2SBen Hutchings };
155cf50dcc2SBen Hutchings 
156f50f2127SFlorian Fainelli /* TC matchall action types, only mirroring for now */
157f50f2127SFlorian Fainelli enum dsa_port_mall_action_type {
158f50f2127SFlorian Fainelli 	DSA_PORT_MALL_MIRROR,
159f50f2127SFlorian Fainelli };
160f50f2127SFlorian Fainelli 
161f50f2127SFlorian Fainelli /* TC mirroring entry */
162f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry {
163f50f2127SFlorian Fainelli 	u8 to_local_port;
164f50f2127SFlorian Fainelli 	bool ingress;
165f50f2127SFlorian Fainelli };
166f50f2127SFlorian Fainelli 
167f50f2127SFlorian Fainelli /* TC matchall entry */
168f50f2127SFlorian Fainelli struct dsa_mall_tc_entry {
169f50f2127SFlorian Fainelli 	struct list_head list;
170f50f2127SFlorian Fainelli 	unsigned long cookie;
171f50f2127SFlorian Fainelli 	enum dsa_port_mall_action_type type;
172f50f2127SFlorian Fainelli 	union {
173f50f2127SFlorian Fainelli 		struct dsa_mall_mirror_tc_entry mirror;
174f50f2127SFlorian Fainelli 	};
175f50f2127SFlorian Fainelli };
176f50f2127SFlorian Fainelli 
177f50f2127SFlorian Fainelli 
178c8b09808SAndrew Lunn struct dsa_port {
179818be848SVivien Didelot 	struct dsa_switch	*ds;
180818be848SVivien Didelot 	unsigned int		index;
18171e0bbdeSFlorian Fainelli 	const char		*name;
182c8b09808SAndrew Lunn 	struct net_device	*netdev;
183189b0d93SAndrew Lunn 	struct device_node	*dn;
18434a79f63SVivien Didelot 	unsigned int		ageing_time;
185732f794cSVivien Didelot 	u8			stp_state;
186a5e9a02eSVivien Didelot 	struct net_device	*bridge_dev;
18796567d5dSAndrew Lunn 	struct devlink_port	devlink_port;
188c8b09808SAndrew Lunn };
189c8b09808SAndrew Lunn 
190c8f0b869SBen Hutchings struct dsa_switch {
191c33063d6SAndrew Lunn 	struct device *dev;
192c33063d6SAndrew Lunn 
193c8f0b869SBen Hutchings 	/*
194c8f0b869SBen Hutchings 	 * Parent switch tree, and switch index.
195c8f0b869SBen Hutchings 	 */
196c8f0b869SBen Hutchings 	struct dsa_switch_tree	*dst;
197c8f0b869SBen Hutchings 	int			index;
198c8f0b869SBen Hutchings 
199f515f192SVivien Didelot 	/* Listener for switch fabric events */
200f515f192SVivien Didelot 	struct notifier_block	nb;
201f515f192SVivien Didelot 
202c8f0b869SBen Hutchings 	/*
2037543a6d5SAndrew Lunn 	 * Give the switch driver somewhere to hang its private data
2047543a6d5SAndrew Lunn 	 * structure.
2057543a6d5SAndrew Lunn 	 */
2067543a6d5SAndrew Lunn 	void *priv;
2077543a6d5SAndrew Lunn 
2087543a6d5SAndrew Lunn 	/*
209c8f0b869SBen Hutchings 	 * Configuration data for this switch.
210c8f0b869SBen Hutchings 	 */
211ff04955cSAndrew Lunn 	struct dsa_chip_data	*cd;
212c8f0b869SBen Hutchings 
213c8f0b869SBen Hutchings 	/*
2149d490b4eSVivien Didelot 	 * The switch operations.
215c8f0b869SBen Hutchings 	 */
216a82f67afSFlorian Fainelli 	const struct dsa_switch_ops	*ops;
217c8f0b869SBen Hutchings 
21866472fc0SAndrew Lunn 	/*
21966472fc0SAndrew Lunn 	 * An array of which element [a] indicates which port on this
22066472fc0SAndrew Lunn 	 * switch should be used to send packets to that are destined
22166472fc0SAndrew Lunn 	 * for switch a. Can be NULL if there is only one switch chip.
22266472fc0SAndrew Lunn 	 */
22366472fc0SAndrew Lunn 	s8		rtable[DSA_MAX_SWITCHES];
22466472fc0SAndrew Lunn 
225c8f0b869SBen Hutchings 	/*
22683c0afaeSAndrew Lunn 	 * The lower device this switch uses to talk to the host
22783c0afaeSAndrew Lunn 	 */
22883c0afaeSAndrew Lunn 	struct net_device *master_netdev;
22983c0afaeSAndrew Lunn 
23083c0afaeSAndrew Lunn 	/*
231c8f0b869SBen Hutchings 	 * Slave mii_bus and devices for the individual ports.
232c8f0b869SBen Hutchings 	 */
233c8f0b869SBen Hutchings 	u32			dsa_port_mask;
23483c0afaeSAndrew Lunn 	u32			cpu_port_mask;
23574c3e2a5SAndrew Lunn 	u32			enabled_port_mask;
2360d8bcdd3SFlorian Fainelli 	u32			phys_mii_mask;
237c8f0b869SBen Hutchings 	struct mii_bus		*slave_mii_bus;
238a0c02161SVivien Didelot 
2390f3da6afSVivien Didelot 	/* Ageing Time limits in msecs */
2400f3da6afSVivien Didelot 	unsigned int ageing_time_min;
2410f3da6afSVivien Didelot 	unsigned int ageing_time_max;
2420f3da6afSVivien Didelot 
24396567d5dSAndrew Lunn 	/* devlink used to represent this switch device */
24496567d5dSAndrew Lunn 	struct devlink		*devlink;
24596567d5dSAndrew Lunn 
246a0c02161SVivien Didelot 	/* Dynamically allocated ports, keep last */
247a0c02161SVivien Didelot 	size_t num_ports;
248a0c02161SVivien Didelot 	struct dsa_port ports[];
249c8f0b869SBen Hutchings };
250c8f0b869SBen Hutchings 
251c8f0b869SBen Hutchings static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
252c8f0b869SBen Hutchings {
253b22de490SVivien Didelot 	return !!(ds == ds->dst->cpu_switch && p == ds->dst->cpu_port);
254c8f0b869SBen Hutchings }
255c8f0b869SBen Hutchings 
25660045cbfSAndrew Lunn static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p)
25760045cbfSAndrew Lunn {
25860045cbfSAndrew Lunn 	return !!((ds->dsa_port_mask) & (1 << p));
25960045cbfSAndrew Lunn }
26060045cbfSAndrew Lunn 
2616cd456f3SVivien Didelot static inline bool dsa_is_normal_port(struct dsa_switch *ds, int p)
2626cd456f3SVivien Didelot {
2636cd456f3SVivien Didelot 	return !dsa_is_cpu_port(ds, p) && !dsa_is_dsa_port(ds, p);
2646cd456f3SVivien Didelot }
2656cd456f3SVivien Didelot 
266d79d2107SGuenter Roeck static inline bool dsa_is_port_initialized(struct dsa_switch *ds, int p)
267d79d2107SGuenter Roeck {
268c8b09808SAndrew Lunn 	return ds->enabled_port_mask & (1 << p) && ds->ports[p].netdev;
269d79d2107SGuenter Roeck }
270d79d2107SGuenter Roeck 
271c8f0b869SBen Hutchings static inline u8 dsa_upstream_port(struct dsa_switch *ds)
272c8f0b869SBen Hutchings {
273c8f0b869SBen Hutchings 	struct dsa_switch_tree *dst = ds->dst;
274c8f0b869SBen Hutchings 
275c8f0b869SBen Hutchings 	/*
276c8f0b869SBen Hutchings 	 * If this is the root switch (i.e. the switch that connects
277c8f0b869SBen Hutchings 	 * to the CPU), return the cpu port number on this switch.
278c8f0b869SBen Hutchings 	 * Else return the (DSA) port number that connects to the
279c8f0b869SBen Hutchings 	 * switch that is one hop closer to the cpu.
280c8f0b869SBen Hutchings 	 */
281b22de490SVivien Didelot 	if (dst->cpu_switch == ds)
282c8f0b869SBen Hutchings 		return dst->cpu_port;
283c8f0b869SBen Hutchings 	else
284b22de490SVivien Didelot 		return ds->rtable[dst->cpu_switch->index];
285c8f0b869SBen Hutchings }
286c8f0b869SBen Hutchings 
287146a3206SVivien Didelot struct switchdev_trans;
288ea70ba98SVivien Didelot struct switchdev_obj;
289146a3206SVivien Didelot struct switchdev_obj_port_fdb;
2908df30255SVivien Didelot struct switchdev_obj_port_mdb;
29176e398a6SVivien Didelot struct switchdev_obj_port_vlan;
292146a3206SVivien Didelot 
29304d3a4c6SVivien Didelot #define DSA_NOTIFIER_BRIDGE_JOIN		1
29404d3a4c6SVivien Didelot #define DSA_NOTIFIER_BRIDGE_LEAVE		2
29504d3a4c6SVivien Didelot 
29604d3a4c6SVivien Didelot /* DSA_NOTIFIER_BRIDGE_* */
29704d3a4c6SVivien Didelot struct dsa_notifier_bridge_info {
29804d3a4c6SVivien Didelot 	struct net_device *br;
29904d3a4c6SVivien Didelot 	int sw_index;
30004d3a4c6SVivien Didelot 	int port;
30104d3a4c6SVivien Didelot };
30204d3a4c6SVivien Didelot 
3039d490b4eSVivien Didelot struct dsa_switch_ops {
304c8f0b869SBen Hutchings 	/*
305c8f0b869SBen Hutchings 	 * Probing and setup.
306c8f0b869SBen Hutchings 	 */
3070209d144SVivien Didelot 	const char	*(*probe)(struct device *dsa_dev,
3080209d144SVivien Didelot 				  struct device *host_dev, int sw_addr,
3090209d144SVivien Didelot 				  void **priv);
3107b314362SAndrew Lunn 
3117b314362SAndrew Lunn 	enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds);
3127b314362SAndrew Lunn 
313c8f0b869SBen Hutchings 	int	(*setup)(struct dsa_switch *ds);
314c8f0b869SBen Hutchings 	int	(*set_addr)(struct dsa_switch *ds, u8 *addr);
3156819563eSFlorian Fainelli 	u32	(*get_phy_flags)(struct dsa_switch *ds, int port);
316c8f0b869SBen Hutchings 
317c8f0b869SBen Hutchings 	/*
318c8f0b869SBen Hutchings 	 * Access to the switch's PHY registers.
319c8f0b869SBen Hutchings 	 */
320c8f0b869SBen Hutchings 	int	(*phy_read)(struct dsa_switch *ds, int port, int regnum);
321c8f0b869SBen Hutchings 	int	(*phy_write)(struct dsa_switch *ds, int port,
322c8f0b869SBen Hutchings 			     int regnum, u16 val);
323c8f0b869SBen Hutchings 
324c8f0b869SBen Hutchings 	/*
325ec9436baSFlorian Fainelli 	 * Link state adjustment (called from libphy)
326ec9436baSFlorian Fainelli 	 */
327ec9436baSFlorian Fainelli 	void	(*adjust_link)(struct dsa_switch *ds, int port,
328ec9436baSFlorian Fainelli 				struct phy_device *phydev);
329ce31b31cSFlorian Fainelli 	void	(*fixed_link_update)(struct dsa_switch *ds, int port,
330ce31b31cSFlorian Fainelli 				struct fixed_phy_status *st);
331ec9436baSFlorian Fainelli 
332ec9436baSFlorian Fainelli 	/*
333c8f0b869SBen Hutchings 	 * ethtool hardware statistics.
334c8f0b869SBen Hutchings 	 */
335c8f0b869SBen Hutchings 	void	(*get_strings)(struct dsa_switch *ds, int port, uint8_t *data);
336c8f0b869SBen Hutchings 	void	(*get_ethtool_stats)(struct dsa_switch *ds,
337c8f0b869SBen Hutchings 				     int port, uint64_t *data);
338c8f0b869SBen Hutchings 	int	(*get_sset_count)(struct dsa_switch *ds);
33924462549SFlorian Fainelli 
34024462549SFlorian Fainelli 	/*
34119e57c4eSFlorian Fainelli 	 * ethtool Wake-on-LAN
34219e57c4eSFlorian Fainelli 	 */
34319e57c4eSFlorian Fainelli 	void	(*get_wol)(struct dsa_switch *ds, int port,
34419e57c4eSFlorian Fainelli 			   struct ethtool_wolinfo *w);
34519e57c4eSFlorian Fainelli 	int	(*set_wol)(struct dsa_switch *ds, int port,
34619e57c4eSFlorian Fainelli 			   struct ethtool_wolinfo *w);
34719e57c4eSFlorian Fainelli 
34819e57c4eSFlorian Fainelli 	/*
34924462549SFlorian Fainelli 	 * Suspend and resume
35024462549SFlorian Fainelli 	 */
35124462549SFlorian Fainelli 	int	(*suspend)(struct dsa_switch *ds);
35224462549SFlorian Fainelli 	int	(*resume)(struct dsa_switch *ds);
353b2f2af21SFlorian Fainelli 
354b2f2af21SFlorian Fainelli 	/*
355b2f2af21SFlorian Fainelli 	 * Port enable/disable
356b2f2af21SFlorian Fainelli 	 */
357b2f2af21SFlorian Fainelli 	int	(*port_enable)(struct dsa_switch *ds, int port,
358b2f2af21SFlorian Fainelli 			       struct phy_device *phy);
359b2f2af21SFlorian Fainelli 	void	(*port_disable)(struct dsa_switch *ds, int port,
360b2f2af21SFlorian Fainelli 				struct phy_device *phy);
3617905288fSFlorian Fainelli 
3627905288fSFlorian Fainelli 	/*
3637905288fSFlorian Fainelli 	 * EEE setttings
3647905288fSFlorian Fainelli 	 */
3657905288fSFlorian Fainelli 	int	(*set_eee)(struct dsa_switch *ds, int port,
3667905288fSFlorian Fainelli 			   struct phy_device *phydev,
3677905288fSFlorian Fainelli 			   struct ethtool_eee *e);
3687905288fSFlorian Fainelli 	int	(*get_eee)(struct dsa_switch *ds, int port,
3697905288fSFlorian Fainelli 			   struct ethtool_eee *e);
37051579c3fSGuenter Roeck 
3716793abb4SGuenter Roeck 	/* EEPROM access */
3726793abb4SGuenter Roeck 	int	(*get_eeprom_len)(struct dsa_switch *ds);
3736793abb4SGuenter Roeck 	int	(*get_eeprom)(struct dsa_switch *ds,
3746793abb4SGuenter Roeck 			      struct ethtool_eeprom *eeprom, u8 *data);
3756793abb4SGuenter Roeck 	int	(*set_eeprom)(struct dsa_switch *ds,
3766793abb4SGuenter Roeck 			      struct ethtool_eeprom *eeprom, u8 *data);
3773d762a0fSGuenter Roeck 
3783d762a0fSGuenter Roeck 	/*
3793d762a0fSGuenter Roeck 	 * Register access.
3803d762a0fSGuenter Roeck 	 */
3813d762a0fSGuenter Roeck 	int	(*get_regs_len)(struct dsa_switch *ds, int port);
3823d762a0fSGuenter Roeck 	void	(*get_regs)(struct dsa_switch *ds, int port,
3833d762a0fSGuenter Roeck 			    struct ethtool_regs *regs, void *p);
384b73adef6SFlorian Fainelli 
385b73adef6SFlorian Fainelli 	/*
386b73adef6SFlorian Fainelli 	 * Bridge integration
387b73adef6SFlorian Fainelli 	 */
38834a79f63SVivien Didelot 	int	(*set_ageing_time)(struct dsa_switch *ds, unsigned int msecs);
38971327a4eSVivien Didelot 	int	(*port_bridge_join)(struct dsa_switch *ds, int port,
390a6692754SVivien Didelot 				    struct net_device *bridge);
391f123f2fbSVivien Didelot 	void	(*port_bridge_leave)(struct dsa_switch *ds, int port,
392f123f2fbSVivien Didelot 				     struct net_device *bridge);
39343c44a9fSVivien Didelot 	void	(*port_stp_state_set)(struct dsa_switch *ds, int port,
394b73adef6SFlorian Fainelli 				      u8 state);
395732f794cSVivien Didelot 	void	(*port_fast_age)(struct dsa_switch *ds, int port);
3962a778e1bSVivien Didelot 
3972a778e1bSVivien Didelot 	/*
39811149536SVivien Didelot 	 * VLAN support
39911149536SVivien Didelot 	 */
400fb2dabadSVivien Didelot 	int	(*port_vlan_filtering)(struct dsa_switch *ds, int port,
401fb2dabadSVivien Didelot 				       bool vlan_filtering);
40276e398a6SVivien Didelot 	int	(*port_vlan_prepare)(struct dsa_switch *ds, int port,
40376e398a6SVivien Didelot 				     const struct switchdev_obj_port_vlan *vlan,
40476e398a6SVivien Didelot 				     struct switchdev_trans *trans);
4054d5770b3SVivien Didelot 	void	(*port_vlan_add)(struct dsa_switch *ds, int port,
40676e398a6SVivien Didelot 				 const struct switchdev_obj_port_vlan *vlan,
40776e398a6SVivien Didelot 				 struct switchdev_trans *trans);
40876e398a6SVivien Didelot 	int	(*port_vlan_del)(struct dsa_switch *ds, int port,
40976e398a6SVivien Didelot 				 const struct switchdev_obj_port_vlan *vlan);
41065aebfc0SVivien Didelot 	int	(*port_vlan_dump)(struct dsa_switch *ds, int port,
41165aebfc0SVivien Didelot 				  struct switchdev_obj_port_vlan *vlan,
41265aebfc0SVivien Didelot 				  int (*cb)(struct switchdev_obj *obj));
41311149536SVivien Didelot 
41411149536SVivien Didelot 	/*
4152a778e1bSVivien Didelot 	 * Forwarding database
4162a778e1bSVivien Didelot 	 */
417146a3206SVivien Didelot 	int	(*port_fdb_prepare)(struct dsa_switch *ds, int port,
418146a3206SVivien Didelot 				    const struct switchdev_obj_port_fdb *fdb,
419146a3206SVivien Didelot 				    struct switchdev_trans *trans);
4208497aa61SVivien Didelot 	void	(*port_fdb_add)(struct dsa_switch *ds, int port,
4211f36faf2SVivien Didelot 				const struct switchdev_obj_port_fdb *fdb,
4221f36faf2SVivien Didelot 				struct switchdev_trans *trans);
4232a778e1bSVivien Didelot 	int	(*port_fdb_del)(struct dsa_switch *ds, int port,
4248057b3e7SVivien Didelot 				const struct switchdev_obj_port_fdb *fdb);
425ea70ba98SVivien Didelot 	int	(*port_fdb_dump)(struct dsa_switch *ds, int port,
426ea70ba98SVivien Didelot 				 struct switchdev_obj_port_fdb *fdb,
427ea70ba98SVivien Didelot 				 int (*cb)(struct switchdev_obj *obj));
4288df30255SVivien Didelot 
4298df30255SVivien Didelot 	/*
4308df30255SVivien Didelot 	 * Multicast database
4318df30255SVivien Didelot 	 */
4328df30255SVivien Didelot 	int	(*port_mdb_prepare)(struct dsa_switch *ds, int port,
4338df30255SVivien Didelot 				    const struct switchdev_obj_port_mdb *mdb,
4348df30255SVivien Didelot 				    struct switchdev_trans *trans);
4358df30255SVivien Didelot 	void	(*port_mdb_add)(struct dsa_switch *ds, int port,
4368df30255SVivien Didelot 				const struct switchdev_obj_port_mdb *mdb,
4378df30255SVivien Didelot 				struct switchdev_trans *trans);
4388df30255SVivien Didelot 	int	(*port_mdb_del)(struct dsa_switch *ds, int port,
4398df30255SVivien Didelot 				const struct switchdev_obj_port_mdb *mdb);
4408df30255SVivien Didelot 	int	(*port_mdb_dump)(struct dsa_switch *ds, int port,
4418df30255SVivien Didelot 				 struct switchdev_obj_port_mdb *mdb,
4428df30255SVivien Didelot 				 int (*cb)(struct switchdev_obj *obj));
443bf9f2648SFlorian Fainelli 
444bf9f2648SFlorian Fainelli 	/*
445bf9f2648SFlorian Fainelli 	 * RXNFC
446bf9f2648SFlorian Fainelli 	 */
447bf9f2648SFlorian Fainelli 	int	(*get_rxnfc)(struct dsa_switch *ds, int port,
448bf9f2648SFlorian Fainelli 			     struct ethtool_rxnfc *nfc, u32 *rule_locs);
449bf9f2648SFlorian Fainelli 	int	(*set_rxnfc)(struct dsa_switch *ds, int port,
450bf9f2648SFlorian Fainelli 			     struct ethtool_rxnfc *nfc);
451f50f2127SFlorian Fainelli 
452f50f2127SFlorian Fainelli 	/*
453f50f2127SFlorian Fainelli 	 * TC integration
454f50f2127SFlorian Fainelli 	 */
455f50f2127SFlorian Fainelli 	int	(*port_mirror_add)(struct dsa_switch *ds, int port,
456f50f2127SFlorian Fainelli 				   struct dsa_mall_mirror_tc_entry *mirror,
457f50f2127SFlorian Fainelli 				   bool ingress);
458f50f2127SFlorian Fainelli 	void	(*port_mirror_del)(struct dsa_switch *ds, int port,
459f50f2127SFlorian Fainelli 				   struct dsa_mall_mirror_tc_entry *mirror);
46040ef2c93SVivien Didelot 
46140ef2c93SVivien Didelot 	/*
46240ef2c93SVivien Didelot 	 * Cross-chip operations
46340ef2c93SVivien Didelot 	 */
46440ef2c93SVivien Didelot 	int	(*crosschip_bridge_join)(struct dsa_switch *ds, int sw_index,
46540ef2c93SVivien Didelot 					 int port, struct net_device *br);
46640ef2c93SVivien Didelot 	void	(*crosschip_bridge_leave)(struct dsa_switch *ds, int sw_index,
46740ef2c93SVivien Didelot 					  int port, struct net_device *br);
468c8f0b869SBen Hutchings };
469c8f0b869SBen Hutchings 
470ab3d408dSFlorian Fainelli struct dsa_switch_driver {
471ab3d408dSFlorian Fainelli 	struct list_head	list;
472a82f67afSFlorian Fainelli 	const struct dsa_switch_ops *ops;
473ab3d408dSFlorian Fainelli };
474ab3d408dSFlorian Fainelli 
475ab3d408dSFlorian Fainelli void register_switch_driver(struct dsa_switch_driver *type);
476ab3d408dSFlorian Fainelli void unregister_switch_driver(struct dsa_switch_driver *type);
477b4d2394dSAlexander Duyck struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev);
47814b89f36SFlorian Fainelli struct net_device *dsa_dev_to_net_device(struct device *dev);
479c8f0b869SBen Hutchings 
4805aed85ceSFlorian Fainelli static inline bool dsa_uses_tagged_protocol(struct dsa_switch_tree *dst)
4815aed85ceSFlorian Fainelli {
4825075314eSAlexander Duyck 	return dst->rcv != NULL;
4835aed85ceSFlorian Fainelli }
48483c0afaeSAndrew Lunn 
485c6e970a0SAndrew Lunn static inline bool netdev_uses_dsa(struct net_device *dev)
486c6e970a0SAndrew Lunn {
487c6e970a0SAndrew Lunn #if IS_ENABLED(CONFIG_NET_DSA)
488c6e970a0SAndrew Lunn 	if (dev->dsa_ptr != NULL)
489c6e970a0SAndrew Lunn 		return dsa_uses_tagged_protocol(dev->dsa_ptr);
490c6e970a0SAndrew Lunn #endif
491c6e970a0SAndrew Lunn 	return false;
492c6e970a0SAndrew Lunn }
493c6e970a0SAndrew Lunn 
494a0c02161SVivien Didelot struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n);
49583c0afaeSAndrew Lunn void dsa_unregister_switch(struct dsa_switch *ds);
49655ed0ce0SFlorian Fainelli int dsa_register_switch(struct dsa_switch *ds, struct device *dev);
497ea825e70SFlorian Fainelli #ifdef CONFIG_PM_SLEEP
498ea825e70SFlorian Fainelli int dsa_switch_suspend(struct dsa_switch *ds);
499ea825e70SFlorian Fainelli int dsa_switch_resume(struct dsa_switch *ds);
500ea825e70SFlorian Fainelli #else
501ea825e70SFlorian Fainelli static inline int dsa_switch_suspend(struct dsa_switch *ds)
502ea825e70SFlorian Fainelli {
503ea825e70SFlorian Fainelli 	return 0;
504ea825e70SFlorian Fainelli }
505ea825e70SFlorian Fainelli static inline int dsa_switch_resume(struct dsa_switch *ds)
506ea825e70SFlorian Fainelli {
507ea825e70SFlorian Fainelli 	return 0;
508ea825e70SFlorian Fainelli }
509ea825e70SFlorian Fainelli #endif /* CONFIG_PM_SLEEP */
510ea825e70SFlorian Fainelli 
51191da11f8SLennert Buytenhek #endif
512