12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
291da11f8SLennert Buytenhek /*
391da11f8SLennert Buytenhek * include/net/dsa.h - Driver for Distributed Switch Architecture switch chips
4e84665c9SLennert Buytenhek * Copyright (c) 2008-2009 Marvell Semiconductor
591da11f8SLennert Buytenhek */
691da11f8SLennert Buytenhek
791da11f8SLennert Buytenhek #ifndef __LINUX_NET_DSA_H
891da11f8SLennert Buytenhek #define __LINUX_NET_DSA_H
991da11f8SLennert Buytenhek
104d56a29fSRussell King #include <linux/if.h>
11ea1f51beSAxel Lin #include <linux/if_ether.h>
12c8f0b869SBen Hutchings #include <linux/list.h>
13f515f192SVivien Didelot #include <linux/notifier.h>
14cf50dcc2SBen Hutchings #include <linux/timer.h>
15cf50dcc2SBen Hutchings #include <linux/workqueue.h>
16fa981d9aSFlorian Fainelli #include <linux/of.h>
17a2820543SFlorian Fainelli #include <linux/ethtool.h>
180336369dSBrandon Streiff #include <linux/net_tstamp.h>
1911d8f3ddSFlorian Fainelli #include <linux/phy.h>
20ecfc9372SFlorian Fainelli #include <linux/platform_data/dsa.h>
2144cc27e4SIoana Ciornei #include <linux/phylink.h>
2296567d5dSAndrew Lunn #include <net/devlink.h>
23f0c24ccfSVivien Didelot #include <net/switchdev.h>
24cf50dcc2SBen Hutchings
2519d05ea7SVladimir Oltean struct dsa_8021q_context;
26f50f2127SFlorian Fainelli struct tc_action;
27f50f2127SFlorian Fainelli
280b42f033SAndrew Lunn #define DSA_TAG_PROTO_NONE_VALUE 0
290b42f033SAndrew Lunn #define DSA_TAG_PROTO_BRCM_VALUE 1
300b42f033SAndrew Lunn #define DSA_TAG_PROTO_BRCM_PREPEND_VALUE 2
310b42f033SAndrew Lunn #define DSA_TAG_PROTO_DSA_VALUE 3
320b42f033SAndrew Lunn #define DSA_TAG_PROTO_EDSA_VALUE 4
330b42f033SAndrew Lunn #define DSA_TAG_PROTO_GSWIP_VALUE 5
340b42f033SAndrew Lunn #define DSA_TAG_PROTO_KSZ9477_VALUE 6
350b42f033SAndrew Lunn #define DSA_TAG_PROTO_KSZ9893_VALUE 7
360b42f033SAndrew Lunn #define DSA_TAG_PROTO_LAN9303_VALUE 8
370b42f033SAndrew Lunn #define DSA_TAG_PROTO_MTK_VALUE 9
380b42f033SAndrew Lunn #define DSA_TAG_PROTO_QCA_VALUE 10
390b42f033SAndrew Lunn #define DSA_TAG_PROTO_TRAILER_VALUE 11
40f9bbe447SVladimir Oltean #define DSA_TAG_PROTO_8021Q_VALUE 12
41227d07a0SVladimir Oltean #define DSA_TAG_PROTO_SJA1105_VALUE 13
42016e43a2STristram Ha #define DSA_TAG_PROTO_KSZ8795_VALUE 14
438dce89aaSVladimir Oltean #define DSA_TAG_PROTO_OCELOT_VALUE 15
4448fda74fSOleksij Rempel #define DSA_TAG_PROTO_AR9331_VALUE 16
45efd7fe68SLinus Walleij #define DSA_TAG_PROTO_RTL4_A_VALUE 17
4601ef09caSKurt Kanzenbach #define DSA_TAG_PROTO_HELLCREEK_VALUE 18
4754a52823SGeorge McCollister #define DSA_TAG_PROTO_XRS700X_VALUE 19
487c83a7c5SVladimir Oltean #define DSA_TAG_PROTO_OCELOT_8021Q_VALUE 20
497c4bb540SVladimir Oltean #define DSA_TAG_PROTO_SEVILLE_VALUE 21
50964dbf18SÁlvaro Fernández Rojas #define DSA_TAG_PROTO_BRCM_LEGACY_VALUE 22
514913b8ebSVladimir Oltean #define DSA_TAG_PROTO_SJA1110_VALUE 23
521521d5adSAlvin Šipraga #define DSA_TAG_PROTO_RTL8_4_VALUE 24
53cd87fecdSLuiz Angelo Daros de Luca #define DSA_TAG_PROTO_RTL8_4T_VALUE 25
54a08d6a6dSClément Léger #define DSA_TAG_PROTO_RZN1_A5PSW_VALUE 26
55092f8751SPrasanna Vengateshan #define DSA_TAG_PROTO_LAN937X_VALUE 27
566c87e1a4SPawel Dembicki #define DSA_TAG_PROTO_VSC73XX_8021Q_VALUE 28
570b42f033SAndrew Lunn
58ac7a04c3SFlorian Fainelli enum dsa_tag_protocol {
590b42f033SAndrew Lunn DSA_TAG_PROTO_NONE = DSA_TAG_PROTO_NONE_VALUE,
600b42f033SAndrew Lunn DSA_TAG_PROTO_BRCM = DSA_TAG_PROTO_BRCM_VALUE,
61964dbf18SÁlvaro Fernández Rojas DSA_TAG_PROTO_BRCM_LEGACY = DSA_TAG_PROTO_BRCM_LEGACY_VALUE,
620b42f033SAndrew Lunn DSA_TAG_PROTO_BRCM_PREPEND = DSA_TAG_PROTO_BRCM_PREPEND_VALUE,
630b42f033SAndrew Lunn DSA_TAG_PROTO_DSA = DSA_TAG_PROTO_DSA_VALUE,
640b42f033SAndrew Lunn DSA_TAG_PROTO_EDSA = DSA_TAG_PROTO_EDSA_VALUE,
650b42f033SAndrew Lunn DSA_TAG_PROTO_GSWIP = DSA_TAG_PROTO_GSWIP_VALUE,
660b42f033SAndrew Lunn DSA_TAG_PROTO_KSZ9477 = DSA_TAG_PROTO_KSZ9477_VALUE,
670b42f033SAndrew Lunn DSA_TAG_PROTO_KSZ9893 = DSA_TAG_PROTO_KSZ9893_VALUE,
680b42f033SAndrew Lunn DSA_TAG_PROTO_LAN9303 = DSA_TAG_PROTO_LAN9303_VALUE,
690b42f033SAndrew Lunn DSA_TAG_PROTO_MTK = DSA_TAG_PROTO_MTK_VALUE,
700b42f033SAndrew Lunn DSA_TAG_PROTO_QCA = DSA_TAG_PROTO_QCA_VALUE,
710b42f033SAndrew Lunn DSA_TAG_PROTO_TRAILER = DSA_TAG_PROTO_TRAILER_VALUE,
72f9bbe447SVladimir Oltean DSA_TAG_PROTO_8021Q = DSA_TAG_PROTO_8021Q_VALUE,
73227d07a0SVladimir Oltean DSA_TAG_PROTO_SJA1105 = DSA_TAG_PROTO_SJA1105_VALUE,
74016e43a2STristram Ha DSA_TAG_PROTO_KSZ8795 = DSA_TAG_PROTO_KSZ8795_VALUE,
758dce89aaSVladimir Oltean DSA_TAG_PROTO_OCELOT = DSA_TAG_PROTO_OCELOT_VALUE,
7648fda74fSOleksij Rempel DSA_TAG_PROTO_AR9331 = DSA_TAG_PROTO_AR9331_VALUE,
77efd7fe68SLinus Walleij DSA_TAG_PROTO_RTL4_A = DSA_TAG_PROTO_RTL4_A_VALUE,
7801ef09caSKurt Kanzenbach DSA_TAG_PROTO_HELLCREEK = DSA_TAG_PROTO_HELLCREEK_VALUE,
7954a52823SGeorge McCollister DSA_TAG_PROTO_XRS700X = DSA_TAG_PROTO_XRS700X_VALUE,
807c83a7c5SVladimir Oltean DSA_TAG_PROTO_OCELOT_8021Q = DSA_TAG_PROTO_OCELOT_8021Q_VALUE,
817c4bb540SVladimir Oltean DSA_TAG_PROTO_SEVILLE = DSA_TAG_PROTO_SEVILLE_VALUE,
824913b8ebSVladimir Oltean DSA_TAG_PROTO_SJA1110 = DSA_TAG_PROTO_SJA1110_VALUE,
831521d5adSAlvin Šipraga DSA_TAG_PROTO_RTL8_4 = DSA_TAG_PROTO_RTL8_4_VALUE,
84cd87fecdSLuiz Angelo Daros de Luca DSA_TAG_PROTO_RTL8_4T = DSA_TAG_PROTO_RTL8_4T_VALUE,
85a08d6a6dSClément Léger DSA_TAG_PROTO_RZN1_A5PSW = DSA_TAG_PROTO_RZN1_A5PSW_VALUE,
86092f8751SPrasanna Vengateshan DSA_TAG_PROTO_LAN937X = DSA_TAG_PROTO_LAN937X_VALUE,
876c87e1a4SPawel Dembicki DSA_TAG_PROTO_VSC73XX_8021Q = DSA_TAG_PROTO_VSC73XX_8021Q_VALUE,
88ac7a04c3SFlorian Fainelli };
895037d532SFlorian Fainelli
9090af1059SBrandon Streiff struct dsa_switch;
913e8a72d1SFlorian Fainelli
9268277a2cSJohn Crispin struct dsa_device_ops {
9368277a2cSJohn Crispin struct sk_buff *(*xmit)(struct sk_buff *skb, struct net_device *dev);
9429a097b7SVladimir Oltean struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev);
952e8cb1b3SVladimir Oltean void (*flow_dissect)(const struct sk_buff *skb, __be16 *proto,
96598a9680SJohn Crispin int *offset);
977f297314SVladimir Oltean int (*connect)(struct dsa_switch *ds);
987f297314SVladimir Oltean void (*disconnect)(struct dsa_switch *ds);
994e500251SVladimir Oltean unsigned int needed_headroom;
1004e500251SVladimir Oltean unsigned int needed_tailroom;
101875138f8SAndrew Lunn const char *name;
102056eed2fSAndrew Lunn enum dsa_tag_protocol proto;
103c3975400SVladimir Oltean /* Some tagging protocols either mangle or shift the destination MAC
1046ca80638SFlorian Fainelli * address, in which case the DSA conduit would drop packets on ingress
105c3975400SVladimir Oltean * if what it understands out of the destination MAC address is not in
106c3975400SVladimir Oltean * its RX filter.
107c3975400SVladimir Oltean */
1086ca80638SFlorian Fainelli bool promisc_on_conduit;
10968277a2cSJohn Crispin };
11068277a2cSJohn Crispin
111dedd6a00SVladimir Oltean struct dsa_lag {
112dedd6a00SVladimir Oltean struct net_device *dev;
113dedd6a00SVladimir Oltean unsigned int id;
114e212fa7cSVladimir Oltean struct mutex fdb_lock;
115e212fa7cSVladimir Oltean struct list_head fdbs;
116dedd6a00SVladimir Oltean refcount_t refcount;
117dedd6a00SVladimir Oltean };
118dedd6a00SVladimir Oltean
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 */
137dedd6a00SVladimir Oltean struct dsa_lag **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
1663d4a0a2aSVladimir Oltean /* LAG IDs are one-based, the dst->lags array is zero-based */
167058102a6STobias Waldekranz #define dsa_lags_foreach_id(_id, _dst) \
1683d4a0a2aSVladimir Oltean for ((_id) = 1; (_id) <= (_dst)->lags_len; (_id)++) \
1693d4a0a2aSVladimir Oltean if ((_dst)->lags[(_id) - 1])
170058102a6STobias Waldekranz
171058102a6STobias Waldekranz #define dsa_lag_foreach_port(_dp, _dst, _lag) \
172058102a6STobias Waldekranz list_for_each_entry((_dp), &(_dst)->ports, list) \
173dedd6a00SVladimir Oltean if (dsa_port_offloads_lag((_dp), (_lag)))
174058102a6STobias Waldekranz
17518596f50SGeorge McCollister #define dsa_hsr_foreach_port(_dp, _ds, _hsr) \
17618596f50SGeorge McCollister list_for_each_entry((_dp), &(_ds)->dst->ports, list) \
17718596f50SGeorge McCollister if ((_dp)->ds == (_ds) && (_dp)->hsr_dev == (_hsr))
17818596f50SGeorge McCollister
dsa_lag_by_id(struct dsa_switch_tree * dst,unsigned int id)179dedd6a00SVladimir Oltean static inline struct dsa_lag *dsa_lag_by_id(struct dsa_switch_tree *dst,
180058102a6STobias Waldekranz unsigned int id)
181058102a6STobias Waldekranz {
1823d4a0a2aSVladimir Oltean /* DSA LAG IDs are one-based, dst->lags is zero-based */
1833d4a0a2aSVladimir Oltean return dst->lags[id - 1];
184058102a6STobias Waldekranz }
185058102a6STobias Waldekranz
dsa_lag_id(struct dsa_switch_tree * dst,struct net_device * lag_dev)186058102a6STobias Waldekranz static inline int dsa_lag_id(struct dsa_switch_tree *dst,
18746a76724SVladimir Oltean struct net_device *lag_dev)
188058102a6STobias Waldekranz {
189058102a6STobias Waldekranz unsigned int id;
190058102a6STobias Waldekranz
191058102a6STobias Waldekranz dsa_lags_foreach_id(id, dst) {
192dedd6a00SVladimir Oltean struct dsa_lag *lag = dsa_lag_by_id(dst, id);
193dedd6a00SVladimir Oltean
194dedd6a00SVladimir Oltean if (lag->dev == lag_dev)
195dedd6a00SVladimir Oltean return lag->id;
196058102a6STobias Waldekranz }
197058102a6STobias Waldekranz
198058102a6STobias Waldekranz return -ENODEV;
199058102a6STobias Waldekranz }
200058102a6STobias Waldekranz
20134297176SVladimir Oltean /* TC matchall action types */
202f50f2127SFlorian Fainelli enum dsa_port_mall_action_type {
203f50f2127SFlorian Fainelli DSA_PORT_MALL_MIRROR,
20434297176SVladimir Oltean DSA_PORT_MALL_POLICER,
205f50f2127SFlorian Fainelli };
206f50f2127SFlorian Fainelli
207f50f2127SFlorian Fainelli /* TC mirroring entry */
208f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry {
209f50f2127SFlorian Fainelli u8 to_local_port;
210f50f2127SFlorian Fainelli bool ingress;
211f50f2127SFlorian Fainelli };
212f50f2127SFlorian Fainelli
21334297176SVladimir Oltean /* TC port policer entry */
21434297176SVladimir Oltean struct dsa_mall_policer_tc_entry {
2155f035af7SPo Liu u32 burst;
21634297176SVladimir Oltean u64 rate_bytes_per_sec;
21734297176SVladimir Oltean };
21834297176SVladimir Oltean
219f50f2127SFlorian Fainelli /* TC matchall entry */
220f50f2127SFlorian Fainelli struct dsa_mall_tc_entry {
221f50f2127SFlorian Fainelli struct list_head list;
222f50f2127SFlorian Fainelli unsigned long cookie;
223f50f2127SFlorian Fainelli enum dsa_port_mall_action_type type;
224f50f2127SFlorian Fainelli union {
225f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry mirror;
22634297176SVladimir Oltean struct dsa_mall_policer_tc_entry policer;
227f50f2127SFlorian Fainelli };
228f50f2127SFlorian Fainelli };
229f50f2127SFlorian Fainelli
230d3eed0e5SVladimir Oltean struct dsa_bridge {
231d3eed0e5SVladimir Oltean struct net_device *dev;
232d3eed0e5SVladimir Oltean unsigned int num;
233857fdd74SVladimir Oltean bool tx_fwd_offload;
234d3eed0e5SVladimir Oltean refcount_t refcount;
235d3eed0e5SVladimir Oltean };
236f50f2127SFlorian Fainelli
237c8b09808SAndrew Lunn struct dsa_port {
2386ca80638SFlorian Fainelli /* A CPU port is physically connected to a conduit device. A user port
2396ca80638SFlorian Fainelli * exposes a network device to user-space, called 'user' here.
240f8b8b1cdSVivien Didelot */
241f8b8b1cdSVivien Didelot union {
2426ca80638SFlorian Fainelli struct net_device *conduit;
2436ca80638SFlorian Fainelli struct net_device *user;
244f8b8b1cdSVivien Didelot };
245f8b8b1cdSVivien Didelot
246357f203bSVladimir Oltean /* Copy of the tagging protocol operations, for quicker access
247357f203bSVladimir Oltean * in the data path. Valid only for the CPU ports.
248357f203bSVladimir Oltean */
24915240248SVivien Didelot const struct dsa_device_ops *tag_ops;
25015240248SVivien Didelot
2516ca80638SFlorian Fainelli /* Copies for faster access in conduit receive hot path */
2523e41f93bSVivien Didelot struct dsa_switch_tree *dst;
25329a097b7SVladimir Oltean struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev);
2543e41f93bSVivien Didelot
25506251258SVladimir Oltean struct dsa_switch *ds;
25606251258SVladimir Oltean
25706251258SVladimir Oltean unsigned int index;
25806251258SVladimir Oltean
259057cad2cSVivien Didelot enum {
260057cad2cSVivien Didelot DSA_PORT_TYPE_UNUSED = 0,
261057cad2cSVivien Didelot DSA_PORT_TYPE_CPU,
262057cad2cSVivien Didelot DSA_PORT_TYPE_DSA,
263057cad2cSVivien Didelot DSA_PORT_TYPE_USER,
264057cad2cSVivien Didelot } type;
265057cad2cSVivien Didelot
26671e0bbdeSFlorian Fainelli const char *name;
26768b2d4a8SVivien Didelot struct dsa_port *cpu_dp;
26883216e39SMichael Walle u8 mac[ETH_ALEN];
269b08db33dSVladimir Oltean
270b08db33dSVladimir Oltean u8 stp_state;
271b08db33dSVladimir Oltean
2721b26d364SVladimir Oltean /* Warning: the following bit fields are not atomic, and updating them
2731b26d364SVladimir Oltean * can only be done from code paths where concurrency is not possible
2741b26d364SVladimir Oltean * (probe time or under rtnl_lock).
2751b26d364SVladimir Oltean */
27663cfc657SVladimir Oltean u8 vlan_filtering:1;
27763cfc657SVladimir Oltean
27863cfc657SVladimir Oltean /* Managed by DSA on user ports and by drivers on CPU and DSA ports */
27963cfc657SVladimir Oltean u8 learning:1;
28063cfc657SVladimir Oltean
28163cfc657SVladimir Oltean u8 lag_tx_enabled:1;
28263cfc657SVladimir Oltean
2836ca80638SFlorian Fainelli /* conduit state bits, valid only on CPU ports */
2846ca80638SFlorian Fainelli u8 conduit_admin_up:1;
2856ca80638SFlorian Fainelli u8 conduit_oper_up:1;
286295ab96fSVladimir Oltean
287acc43b7bSVladimir Oltean /* Valid only on user ports */
288acc43b7bSVladimir Oltean u8 cpu_port_in_lag:1;
289acc43b7bSVladimir Oltean
29063cfc657SVladimir Oltean u8 setup:1;
291bde82f38SVladimir Oltean
292189b0d93SAndrew Lunn struct device_node *dn;
29334a79f63SVivien Didelot unsigned int ageing_time;
294bde82f38SVladimir Oltean
295d3eed0e5SVladimir Oltean struct dsa_bridge *bridge;
29696567d5dSAndrew Lunn struct devlink_port devlink_port;
297aab9c406SFlorian Fainelli struct phylink *pl;
29844cc27e4SIoana Ciornei struct phylink_config pl_config;
299dedd6a00SVladimir Oltean struct dsa_lag *lag;
30018596f50SGeorge McCollister struct net_device *hsr_dev;
30197a69a0dSVladimir Oltean
302ab8ccae1SVivien Didelot struct list_head list;
303ab8ccae1SVivien Didelot
30467dbb9d4SFlorian Fainelli /*
3056ca80638SFlorian Fainelli * Original copy of the conduit netdev ethtool_ops
30667dbb9d4SFlorian Fainelli */
30767dbb9d4SFlorian Fainelli const struct ethtool_ops *orig_ethtool_ops;
308da7b9e9bSFlorian Fainelli
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;
315134ef238SVladimir Oltean
316134ef238SVladimir Oltean struct mutex vlans_lock;
317d06f925fSVladimir Oltean union {
318d06f925fSVladimir Oltean /* List of VLANs that CPU and DSA ports are members of.
319d06f925fSVladimir Oltean * Access to this is serialized by the sleepable @vlans_lock.
320d06f925fSVladimir Oltean */
321134ef238SVladimir Oltean struct list_head vlans;
322d06f925fSVladimir Oltean /* List of VLANs that user ports are members of.
323d06f925fSVladimir Oltean * Access to this is serialized by netif_addr_lock_bh().
324d06f925fSVladimir Oltean */
325d06f925fSVladimir Oltean struct list_head user_vlans;
326d06f925fSVladimir Oltean };
327c8b09808SAndrew Lunn };
328c8b09808SAndrew Lunn
329dd0c9855SRussell King (Oracle) static inline struct dsa_port *
dsa_phylink_to_port(struct phylink_config * config)330dd0c9855SRussell King (Oracle) dsa_phylink_to_port(struct phylink_config *config)
331dd0c9855SRussell King (Oracle) {
332dd0c9855SRussell King (Oracle) return container_of(config, struct dsa_port, pl_config);
333dd0c9855SRussell King (Oracle) }
334dd0c9855SRussell King (Oracle)
335c5f51765SVivien Didelot /* TODO: ideally DSA ports would have a single dp->link_dp member,
336c5f51765SVivien Didelot * and no dst->rtable nor this struct dsa_link would be needed,
337c5f51765SVivien Didelot * but this would require some more complex tree walking,
338c5f51765SVivien Didelot * so keep it stupid at the moment and list them all.
339c5f51765SVivien Didelot */
340c5f51765SVivien Didelot struct dsa_link {
341c5f51765SVivien Didelot struct dsa_port *dp;
342c5f51765SVivien Didelot struct dsa_port *link_dp;
343c5f51765SVivien Didelot struct list_head list;
344c5f51765SVivien Didelot };
345c5f51765SVivien Didelot
346c2693363SVladimir Oltean enum dsa_db_type {
347c2693363SVladimir Oltean DSA_DB_PORT,
348c2693363SVladimir Oltean DSA_DB_LAG,
349c2693363SVladimir Oltean DSA_DB_BRIDGE,
350c2693363SVladimir Oltean };
351c2693363SVladimir Oltean
352c2693363SVladimir Oltean struct dsa_db {
353c2693363SVladimir Oltean enum dsa_db_type type;
354c2693363SVladimir Oltean
355c2693363SVladimir Oltean union {
356c2693363SVladimir Oltean const struct dsa_port *dp;
357c2693363SVladimir Oltean struct dsa_lag lag;
358c2693363SVladimir Oltean struct dsa_bridge bridge;
359c2693363SVladimir Oltean };
360c2693363SVladimir Oltean };
361c2693363SVladimir Oltean
362161ca59dSVladimir Oltean struct dsa_mac_addr {
363161ca59dSVladimir Oltean unsigned char addr[ETH_ALEN];
364161ca59dSVladimir Oltean u16 vid;
365161ca59dSVladimir Oltean refcount_t refcount;
366161ca59dSVladimir Oltean struct list_head list;
367c2693363SVladimir Oltean struct dsa_db db;
368161ca59dSVladimir Oltean };
369161ca59dSVladimir Oltean
370134ef238SVladimir Oltean struct dsa_vlan {
371134ef238SVladimir Oltean u16 vid;
372134ef238SVladimir Oltean refcount_t refcount;
373134ef238SVladimir Oltean struct list_head list;
374134ef238SVladimir Oltean };
375134ef238SVladimir Oltean
376c8f0b869SBen Hutchings struct dsa_switch {
377c33063d6SAndrew Lunn struct device *dev;
378c33063d6SAndrew Lunn
379c8f0b869SBen Hutchings /*
380c8f0b869SBen Hutchings * Parent switch tree, and switch index.
381c8f0b869SBen Hutchings */
382c8f0b869SBen Hutchings struct dsa_switch_tree *dst;
38399feaafcSVivien Didelot unsigned int index;
384c8f0b869SBen Hutchings
3851b26d364SVladimir Oltean /* Warning: the following bit fields are not atomic, and updating them
3861b26d364SVladimir Oltean * can only be done from code paths where concurrency is not possible
3871b26d364SVladimir Oltean * (probe time or under rtnl_lock).
3881b26d364SVladimir Oltean */
38963cfc657SVladimir Oltean u32 setup:1;
39063cfc657SVladimir Oltean
39163cfc657SVladimir Oltean /* Disallow bridge core from requesting different VLAN awareness
39263cfc657SVladimir Oltean * settings on ports if not hardware-supported
3937787ff77SVladimir Oltean */
39463cfc657SVladimir Oltean u32 vlan_filtering_is_global:1;
39563cfc657SVladimir Oltean
39663cfc657SVladimir Oltean /* Keep VLAN filtering enabled on ports not offloading any upper */
39763cfc657SVladimir Oltean u32 needs_standalone_vlan_filtering:1;
39863cfc657SVladimir Oltean
39963cfc657SVladimir Oltean /* Pass .port_vlan_add and .port_vlan_del to drivers even for bridges
40063cfc657SVladimir Oltean * that have vlan_filtering=0. All drivers should ideally set this (and
40163cfc657SVladimir Oltean * then the option would get removed), but it is unknown whether this
4027787ff77SVladimir Oltean * would break things or not.
4037787ff77SVladimir Oltean */
40463cfc657SVladimir Oltean u32 configure_vlan_while_not_filtering:1;
40563cfc657SVladimir Oltean
406*93e4649eSVladimir Oltean /* Pop the default_pvid of VLAN-unaware bridge ports from tagged frames.
407*93e4649eSVladimir Oltean * DEPRECATED: Do NOT set this field in new drivers. Instead look at
408*93e4649eSVladimir Oltean * the dsa_software_vlan_untag() comments.
4097787ff77SVladimir Oltean */
41063cfc657SVladimir Oltean u32 untag_bridge_pvid:1;
411*93e4649eSVladimir Oltean /* Pop the default_pvid of VLAN-aware bridge ports from tagged frames.
412*93e4649eSVladimir Oltean * Useful if the switch cannot preserve the VLAN tag as seen on the
413*93e4649eSVladimir Oltean * wire for user port ingress, and chooses to send all frames as
414*93e4649eSVladimir Oltean * VLAN-tagged to the CPU, including those which were originally
415*93e4649eSVladimir Oltean * untagged.
416*93e4649eSVladimir Oltean */
417*93e4649eSVladimir Oltean u32 untag_vlan_aware_bridge_pvid:1;
41863cfc657SVladimir Oltean
4197787ff77SVladimir Oltean /* Let DSA manage the FDB entries towards the
4207787ff77SVladimir Oltean * CPU, based on the software bridge database.
4217787ff77SVladimir Oltean */
42263cfc657SVladimir Oltean u32 assisted_learning_on_cpu_port:1;
42363cfc657SVladimir Oltean
42463cfc657SVladimir Oltean /* In case vlan_filtering_is_global is set, the VLAN awareness state
42563cfc657SVladimir Oltean * should be retrieved from here and not from the per-port settings.
4267787ff77SVladimir Oltean */
42763cfc657SVladimir Oltean u32 vlan_filtering:1;
42863cfc657SVladimir Oltean
42963cfc657SVladimir Oltean /* For switches that only have the MRU configurable. To ensure the
43063cfc657SVladimir Oltean * configured MTU is not exceeded, normalization of MRU on all bridged
43163cfc657SVladimir Oltean * interfaces is needed.
4327787ff77SVladimir Oltean */
43363cfc657SVladimir Oltean u32 mtu_enforcement_ingress:1;
4347787ff77SVladimir Oltean
435c2693363SVladimir Oltean /* Drivers that isolate the FDBs of multiple bridges must set this
436c2693363SVladimir Oltean * to true to receive the bridge as an argument in .port_fdb_{add,del}
437c2693363SVladimir Oltean * and .port_mdb_{add,del}. Otherwise, the bridge.num will always be
438c2693363SVladimir Oltean * passed as zero.
439c2693363SVladimir Oltean */
440c2693363SVladimir Oltean u32 fdb_isolation:1;
441c2693363SVladimir Oltean
4425f5109afSOleksij Rempel /* Drivers that have global DSCP mapping settings must set this to
4435f5109afSOleksij Rempel * true to automatically apply the settings to all ports.
4445f5109afSOleksij Rempel */
4455f5109afSOleksij Rempel u32 dscp_prio_mapping_is_global:1;
4465f5109afSOleksij Rempel
447f515f192SVivien Didelot /* Listener for switch fabric events */
448f515f192SVivien Didelot struct notifier_block nb;
449f515f192SVivien Didelot
450c8f0b869SBen Hutchings /*
4517543a6d5SAndrew Lunn * Give the switch driver somewhere to hang its private data
4527543a6d5SAndrew Lunn * structure.
4537543a6d5SAndrew Lunn */
4547543a6d5SAndrew Lunn void *priv;
4557543a6d5SAndrew Lunn
456dc452a47SVladimir Oltean void *tagger_data;
457dc452a47SVladimir Oltean
4587543a6d5SAndrew Lunn /*
459c8f0b869SBen Hutchings * Configuration data for this switch.
460c8f0b869SBen Hutchings */
461ff04955cSAndrew Lunn struct dsa_chip_data *cd;
462c8f0b869SBen Hutchings
463c8f0b869SBen Hutchings /*
4649d490b4eSVivien Didelot * The switch operations.
465c8f0b869SBen Hutchings */
466a82f67afSFlorian Fainelli const struct dsa_switch_ops *ops;
467c8f0b869SBen Hutchings
46866472fc0SAndrew Lunn /*
469cae425cbSRussell King (Oracle) * Allow a DSA switch driver to override the phylink MAC ops
470cae425cbSRussell King (Oracle) */
471cae425cbSRussell King (Oracle) const struct phylink_mac_ops *phylink_mac_ops;
472cae425cbSRussell King (Oracle)
473cae425cbSRussell King (Oracle) /*
4746ca80638SFlorian Fainelli * User mii_bus and devices for the individual ports.
475c8f0b869SBen Hutchings */
4760d8bcdd3SFlorian Fainelli u32 phys_mii_mask;
4776ca80638SFlorian Fainelli struct mii_bus *user_mii_bus;
478a0c02161SVivien Didelot
4790f3da6afSVivien Didelot /* Ageing Time limits in msecs */
4800f3da6afSVivien Didelot unsigned int ageing_time_min;
4810f3da6afSVivien Didelot unsigned int ageing_time_max;
4820f3da6afSVivien Didelot
483d7b1fd52SVladimir Oltean /* Storage for drivers using tag_8021q */
484d7b1fd52SVladimir Oltean struct dsa_8021q_context *tag_8021q_ctx;
485d7b1fd52SVladimir Oltean
48696567d5dSAndrew Lunn /* devlink used to represent this switch device */
48796567d5dSAndrew Lunn struct devlink *devlink;
48896567d5dSAndrew Lunn
48955199df6SFlorian Fainelli /* Number of switch port queues */
49055199df6SFlorian Fainelli unsigned int num_tx_queues;
49155199df6SFlorian Fainelli
492058102a6STobias Waldekranz /* Drivers that benefit from having an ID associated with each
493058102a6STobias Waldekranz * offloaded LAG should set this to the maximum number of
494058102a6STobias Waldekranz * supported IDs. DSA will then maintain a mapping of _at
495058102a6STobias Waldekranz * least_ these many IDs, accessible to drivers via
496058102a6STobias Waldekranz * dsa_lag_id().
497058102a6STobias Waldekranz */
498058102a6STobias Waldekranz unsigned int num_lag_ids;
499058102a6STobias Waldekranz
500947c8746SVladimir Oltean /* Drivers that support bridge forwarding offload or FDB isolation
501947c8746SVladimir Oltean * should set this to the maximum number of bridges spanning the same
502947c8746SVladimir Oltean * switch tree (or all trees, in the case of cross-tree bridging
503947c8746SVladimir Oltean * support) that can be offloaded.
504123abc06SVladimir Oltean */
505947c8746SVladimir Oltean unsigned int max_num_bridges;
506123abc06SVladimir Oltean
507258030acSVladimir Oltean unsigned int num_ports;
508c8f0b869SBen Hutchings };
509c8f0b869SBen Hutchings
dsa_to_port(struct dsa_switch * ds,int p)51068bb8ea8SVivien Didelot static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p)
511c38c5a66SVivien Didelot {
512b96ddf25SVivien Didelot struct dsa_switch_tree *dst = ds->dst;
513d607525bSVivien Didelot struct dsa_port *dp;
514b96ddf25SVivien Didelot
515b96ddf25SVivien Didelot list_for_each_entry(dp, &dst->ports, list)
516b96ddf25SVivien Didelot if (dp->ds == ds && dp->index == p)
517b96ddf25SVivien Didelot return dp;
518d607525bSVivien Didelot
519d607525bSVivien Didelot return NULL;
520c38c5a66SVivien Didelot }
521c38c5a66SVivien Didelot
dsa_port_is_dsa(struct dsa_port * port)522a8986681SVladimir Oltean static inline bool dsa_port_is_dsa(struct dsa_port *port)
523a8986681SVladimir Oltean {
524a8986681SVladimir Oltean return port->type == DSA_PORT_TYPE_DSA;
525a8986681SVladimir Oltean }
526a8986681SVladimir Oltean
dsa_port_is_cpu(struct dsa_port * port)527a8986681SVladimir Oltean static inline bool dsa_port_is_cpu(struct dsa_port *port)
528a8986681SVladimir Oltean {
529a8986681SVladimir Oltean return port->type == DSA_PORT_TYPE_CPU;
530a8986681SVladimir Oltean }
531a8986681SVladimir Oltean
dsa_port_is_user(struct dsa_port * dp)532a8986681SVladimir Oltean static inline bool dsa_port_is_user(struct dsa_port *dp)
533a8986681SVladimir Oltean {
534a8986681SVladimir Oltean return dp->type == DSA_PORT_TYPE_USER;
535a8986681SVladimir Oltean }
536a8986681SVladimir Oltean
dsa_port_is_unused(struct dsa_port * dp)537a57d8c21SVladimir Oltean static inline bool dsa_port_is_unused(struct dsa_port *dp)
538a57d8c21SVladimir Oltean {
539a57d8c21SVladimir Oltean return dp->type == DSA_PORT_TYPE_UNUSED;
540a57d8c21SVladimir Oltean }
541a57d8c21SVladimir Oltean
dsa_port_conduit_is_operational(struct dsa_port * dp)5426ca80638SFlorian Fainelli static inline bool dsa_port_conduit_is_operational(struct dsa_port *dp)
543295ab96fSVladimir Oltean {
5446ca80638SFlorian Fainelli return dsa_port_is_cpu(dp) && dp->conduit_admin_up &&
5456ca80638SFlorian Fainelli dp->conduit_oper_up;
546295ab96fSVladimir Oltean }
547295ab96fSVladimir Oltean
dsa_is_unused_port(struct dsa_switch * ds,int p)548bff7b688SVivien Didelot static inline bool dsa_is_unused_port(struct dsa_switch *ds, int p)
549bff7b688SVivien Didelot {
550c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_UNUSED;
551bff7b688SVivien Didelot }
552bff7b688SVivien Didelot
dsa_is_cpu_port(struct dsa_switch * ds,int p)553c8f0b869SBen Hutchings static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
554c8f0b869SBen Hutchings {
555c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_CPU;
556c8f0b869SBen Hutchings }
557c8f0b869SBen Hutchings
dsa_is_dsa_port(struct dsa_switch * ds,int p)55860045cbfSAndrew Lunn static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p)
55960045cbfSAndrew Lunn {
560c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_DSA;
56160045cbfSAndrew Lunn }
56260045cbfSAndrew Lunn
dsa_is_user_port(struct dsa_switch * ds,int p)5632b3e9891SVivien Didelot static inline bool dsa_is_user_port(struct dsa_switch *ds, int p)
5646cd456f3SVivien Didelot {
565c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_USER;
5666cd456f3SVivien Didelot }
5676cd456f3SVivien Didelot
56882b31898SVladimir Oltean #define dsa_tree_for_each_user_port(_dp, _dst) \
56982b31898SVladimir Oltean list_for_each_entry((_dp), &(_dst)->ports, list) \
57082b31898SVladimir Oltean if (dsa_port_is_user((_dp)))
57182b31898SVladimir Oltean
57295f510d0SVladimir Oltean #define dsa_tree_for_each_user_port_continue_reverse(_dp, _dst) \
57395f510d0SVladimir Oltean list_for_each_entry_continue_reverse((_dp), &(_dst)->ports, list) \
57495f510d0SVladimir Oltean if (dsa_port_is_user((_dp)))
57595f510d0SVladimir Oltean
5765dc760d1SVladimir Oltean #define dsa_tree_for_each_cpu_port(_dp, _dst) \
5775dc760d1SVladimir Oltean list_for_each_entry((_dp), &(_dst)->ports, list) \
5785dc760d1SVladimir Oltean if (dsa_port_is_cpu((_dp)))
5795dc760d1SVladimir Oltean
58082b31898SVladimir Oltean #define dsa_switch_for_each_port(_dp, _ds) \
58182b31898SVladimir Oltean list_for_each_entry((_dp), &(_ds)->dst->ports, list) \
58282b31898SVladimir Oltean if ((_dp)->ds == (_ds))
58382b31898SVladimir Oltean
58482b31898SVladimir Oltean #define dsa_switch_for_each_port_safe(_dp, _next, _ds) \
58582b31898SVladimir Oltean list_for_each_entry_safe((_dp), (_next), &(_ds)->dst->ports, list) \
58682b31898SVladimir Oltean if ((_dp)->ds == (_ds))
58782b31898SVladimir Oltean
58882b31898SVladimir Oltean #define dsa_switch_for_each_port_continue_reverse(_dp, _ds) \
58982b31898SVladimir Oltean list_for_each_entry_continue_reverse((_dp), &(_ds)->dst->ports, list) \
59082b31898SVladimir Oltean if ((_dp)->ds == (_ds))
59182b31898SVladimir Oltean
59282b31898SVladimir Oltean #define dsa_switch_for_each_available_port(_dp, _ds) \
59382b31898SVladimir Oltean dsa_switch_for_each_port((_dp), (_ds)) \
59482b31898SVladimir Oltean if (!dsa_port_is_unused((_dp)))
59582b31898SVladimir Oltean
59682b31898SVladimir Oltean #define dsa_switch_for_each_user_port(_dp, _ds) \
59782b31898SVladimir Oltean dsa_switch_for_each_port((_dp), (_ds)) \
59882b31898SVladimir Oltean if (dsa_port_is_user((_dp)))
59982b31898SVladimir Oltean
6005f5109afSOleksij Rempel #define dsa_switch_for_each_user_port_continue_reverse(_dp, _ds) \
6015f5109afSOleksij Rempel dsa_switch_for_each_port_continue_reverse((_dp), (_ds)) \
6025f5109afSOleksij Rempel if (dsa_port_is_user((_dp)))
6035f5109afSOleksij Rempel
60482b31898SVladimir Oltean #define dsa_switch_for_each_cpu_port(_dp, _ds) \
60582b31898SVladimir Oltean dsa_switch_for_each_port((_dp), (_ds)) \
60682b31898SVladimir Oltean if (dsa_port_is_cpu((_dp)))
60782b31898SVladimir Oltean
608bacf93b0SVladimir Oltean #define dsa_switch_for_each_cpu_port_continue_reverse(_dp, _ds) \
609bacf93b0SVladimir Oltean dsa_switch_for_each_port_continue_reverse((_dp), (_ds)) \
610bacf93b0SVladimir Oltean if (dsa_port_is_cpu((_dp)))
611bacf93b0SVladimir Oltean
dsa_user_ports(struct dsa_switch * ds)61202bc6e54SVivien Didelot static inline u32 dsa_user_ports(struct dsa_switch *ds)
61302bc6e54SVivien Didelot {
614d0004a02SVladimir Oltean struct dsa_port *dp;
615c38c5a66SVivien Didelot u32 mask = 0;
61602bc6e54SVivien Didelot
617d0004a02SVladimir Oltean dsa_switch_for_each_user_port(dp, ds)
618d0004a02SVladimir Oltean mask |= BIT(dp->index);
619c38c5a66SVivien Didelot
620c38c5a66SVivien Didelot return mask;
621c8652c83SVivien Didelot }
622c8652c83SVivien Didelot
dsa_cpu_ports(struct dsa_switch * ds)623465c3de4SVladimir Oltean static inline u32 dsa_cpu_ports(struct dsa_switch *ds)
624465c3de4SVladimir Oltean {
625465c3de4SVladimir Oltean struct dsa_port *cpu_dp;
626465c3de4SVladimir Oltean u32 mask = 0;
627465c3de4SVladimir Oltean
628465c3de4SVladimir Oltean dsa_switch_for_each_cpu_port(cpu_dp, ds)
629465c3de4SVladimir Oltean mask |= BIT(cpu_dp->index);
630465c3de4SVladimir Oltean
631465c3de4SVladimir Oltean return mask;
632465c3de4SVladimir Oltean }
633465c3de4SVladimir Oltean
634c5f51765SVivien Didelot /* Return the local port used to reach an arbitrary switch device */
dsa_routing_port(struct dsa_switch * ds,int device)635c5f51765SVivien Didelot static inline unsigned int dsa_routing_port(struct dsa_switch *ds, int device)
636c5f51765SVivien Didelot {
637c5f51765SVivien Didelot struct dsa_switch_tree *dst = ds->dst;
638c5f51765SVivien Didelot struct dsa_link *dl;
639c5f51765SVivien Didelot
640c5f51765SVivien Didelot list_for_each_entry(dl, &dst->rtable, list)
641c5f51765SVivien Didelot if (dl->dp->ds == ds && dl->link_dp->ds->index == device)
642c5f51765SVivien Didelot return dl->dp->index;
643c5f51765SVivien Didelot
644c5f51765SVivien Didelot return ds->num_ports;
645c5f51765SVivien Didelot }
646c5f51765SVivien Didelot
6473b8fac5dSVivien Didelot /* Return the local port used to reach an arbitrary switch port */
dsa_towards_port(struct dsa_switch * ds,int device,int port)6483b8fac5dSVivien Didelot static inline unsigned int dsa_towards_port(struct dsa_switch *ds, int device,
6493b8fac5dSVivien Didelot int port)
6503b8fac5dSVivien Didelot {
6513b8fac5dSVivien Didelot if (device == ds->index)
6523b8fac5dSVivien Didelot return port;
6533b8fac5dSVivien Didelot else
654c5f51765SVivien Didelot return dsa_routing_port(ds, device);
6553b8fac5dSVivien Didelot }
6563b8fac5dSVivien Didelot
6573b8fac5dSVivien Didelot /* Return the local port used to reach the dedicated CPU port */
dsa_upstream_port(struct dsa_switch * ds,int port)65807073c79SVivien Didelot static inline unsigned int dsa_upstream_port(struct dsa_switch *ds, int port)
659c8f0b869SBen Hutchings {
66007073c79SVivien Didelot const struct dsa_port *dp = dsa_to_port(ds, port);
66107073c79SVivien Didelot const struct dsa_port *cpu_dp = dp->cpu_dp;
66207073c79SVivien Didelot
66307073c79SVivien Didelot if (!cpu_dp)
66407073c79SVivien Didelot return port;
665c8f0b869SBen Hutchings
6663b8fac5dSVivien Didelot return dsa_towards_port(ds, cpu_dp->ds->index, cpu_dp->index);
667c8f0b869SBen Hutchings }
668c8f0b869SBen Hutchings
66963609c8fSVladimir Oltean /* Return true if this is the local port used to reach the CPU port */
dsa_is_upstream_port(struct dsa_switch * ds,int port)67063609c8fSVladimir Oltean static inline bool dsa_is_upstream_port(struct dsa_switch *ds, int port)
67163609c8fSVladimir Oltean {
67263609c8fSVladimir Oltean if (dsa_is_unused_port(ds, port))
67363609c8fSVladimir Oltean return false;
67463609c8fSVladimir Oltean
67563609c8fSVladimir Oltean return port == dsa_upstream_port(ds, port);
67663609c8fSVladimir Oltean }
67763609c8fSVladimir Oltean
678d352b20fSTobias Waldekranz /* Return true if this is a DSA port leading away from the CPU */
dsa_is_downstream_port(struct dsa_switch * ds,int port)679d352b20fSTobias Waldekranz static inline bool dsa_is_downstream_port(struct dsa_switch *ds, int port)
680d352b20fSTobias Waldekranz {
681d352b20fSTobias Waldekranz return dsa_is_dsa_port(ds, port) && !dsa_is_upstream_port(ds, port);
682d352b20fSTobias Waldekranz }
683d352b20fSTobias Waldekranz
6847af4a361STobias Waldekranz /* Return the local port used to reach the CPU port */
dsa_switch_upstream_port(struct dsa_switch * ds)6857af4a361STobias Waldekranz static inline unsigned int dsa_switch_upstream_port(struct dsa_switch *ds)
6867af4a361STobias Waldekranz {
6877af4a361STobias Waldekranz struct dsa_port *dp;
6887af4a361STobias Waldekranz
6897af4a361STobias Waldekranz dsa_switch_for_each_available_port(dp, ds) {
6907af4a361STobias Waldekranz return dsa_upstream_port(ds, dp->index);
6917af4a361STobias Waldekranz }
6927af4a361STobias Waldekranz
6937af4a361STobias Waldekranz return ds->num_ports;
6947af4a361STobias Waldekranz }
6957af4a361STobias Waldekranz
69663609c8fSVladimir Oltean /* Return true if @upstream_ds is an upstream switch of @downstream_ds, meaning
69763609c8fSVladimir Oltean * that the routing port from @downstream_ds to @upstream_ds is also the port
69863609c8fSVladimir Oltean * which @downstream_ds uses to reach its dedicated CPU.
69963609c8fSVladimir Oltean */
dsa_switch_is_upstream_of(struct dsa_switch * upstream_ds,struct dsa_switch * downstream_ds)70063609c8fSVladimir Oltean static inline bool dsa_switch_is_upstream_of(struct dsa_switch *upstream_ds,
70163609c8fSVladimir Oltean struct dsa_switch *downstream_ds)
70263609c8fSVladimir Oltean {
70363609c8fSVladimir Oltean int routing_port;
70463609c8fSVladimir Oltean
70563609c8fSVladimir Oltean if (upstream_ds == downstream_ds)
70663609c8fSVladimir Oltean return true;
70763609c8fSVladimir Oltean
70863609c8fSVladimir Oltean routing_port = dsa_routing_port(downstream_ds, upstream_ds->index);
70963609c8fSVladimir Oltean
71063609c8fSVladimir Oltean return dsa_is_upstream_port(downstream_ds, routing_port);
71163609c8fSVladimir Oltean }
71263609c8fSVladimir Oltean
dsa_port_is_vlan_filtering(const struct dsa_port * dp)713cf2d45f5SVladimir Oltean static inline bool dsa_port_is_vlan_filtering(const struct dsa_port *dp)
714cf2d45f5SVladimir Oltean {
715cf2d45f5SVladimir Oltean const struct dsa_switch *ds = dp->ds;
716cf2d45f5SVladimir Oltean
717cf2d45f5SVladimir Oltean if (ds->vlan_filtering_is_global)
718cf2d45f5SVladimir Oltean return ds->vlan_filtering;
719cf2d45f5SVladimir Oltean else
720cf2d45f5SVladimir Oltean return dp->vlan_filtering;
721cf2d45f5SVladimir Oltean }
722cf2d45f5SVladimir Oltean
dsa_port_lag_id_get(struct dsa_port * dp)723dedd6a00SVladimir Oltean static inline unsigned int dsa_port_lag_id_get(struct dsa_port *dp)
724dedd6a00SVladimir Oltean {
725dedd6a00SVladimir Oltean return dp->lag ? dp->lag->id : 0;
726dedd6a00SVladimir Oltean }
727dedd6a00SVladimir Oltean
dsa_port_lag_dev_get(struct dsa_port * dp)728dedd6a00SVladimir Oltean static inline struct net_device *dsa_port_lag_dev_get(struct dsa_port *dp)
729dedd6a00SVladimir Oltean {
730dedd6a00SVladimir Oltean return dp->lag ? dp->lag->dev : NULL;
731dedd6a00SVladimir Oltean }
732dedd6a00SVladimir Oltean
dsa_port_offloads_lag(struct dsa_port * dp,const struct dsa_lag * lag)733dedd6a00SVladimir Oltean static inline bool dsa_port_offloads_lag(struct dsa_port *dp,
734dedd6a00SVladimir Oltean const struct dsa_lag *lag)
735dedd6a00SVladimir Oltean {
736dedd6a00SVladimir Oltean return dsa_port_lag_dev_get(dp) == lag->dev;
737dedd6a00SVladimir Oltean }
738dedd6a00SVladimir Oltean
dsa_port_to_conduit(const struct dsa_port * dp)7396ca80638SFlorian Fainelli static inline struct net_device *dsa_port_to_conduit(const struct dsa_port *dp)
7408f6a19c0SVladimir Oltean {
741acc43b7bSVladimir Oltean if (dp->cpu_port_in_lag)
742acc43b7bSVladimir Oltean return dsa_port_lag_dev_get(dp->cpu_dp);
743acc43b7bSVladimir Oltean
7446ca80638SFlorian Fainelli return dp->cpu_dp->conduit;
7458f6a19c0SVladimir Oltean }
7468f6a19c0SVladimir Oltean
747cc76ce9eSTobias Waldekranz static inline
dsa_port_to_bridge_port(const struct dsa_port * dp)748cc76ce9eSTobias Waldekranz struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp)
749cc76ce9eSTobias Waldekranz {
750d3eed0e5SVladimir Oltean if (!dp->bridge)
751cc76ce9eSTobias Waldekranz return NULL;
752cc76ce9eSTobias Waldekranz
753dedd6a00SVladimir Oltean if (dp->lag)
754dedd6a00SVladimir Oltean return dp->lag->dev;
755cc76ce9eSTobias Waldekranz else if (dp->hsr_dev)
756cc76ce9eSTobias Waldekranz return dp->hsr_dev;
757cc76ce9eSTobias Waldekranz
7586ca80638SFlorian Fainelli return dp->user;
759cc76ce9eSTobias Waldekranz }
760cc76ce9eSTobias Waldekranz
76136cbf39bSVladimir Oltean static inline struct net_device *
dsa_port_bridge_dev_get(const struct dsa_port * dp)76236cbf39bSVladimir Oltean dsa_port_bridge_dev_get(const struct dsa_port *dp)
76336cbf39bSVladimir Oltean {
764d3eed0e5SVladimir Oltean return dp->bridge ? dp->bridge->dev : NULL;
76536cbf39bSVladimir Oltean }
76636cbf39bSVladimir Oltean
dsa_port_bridge_num_get(struct dsa_port * dp)76736cbf39bSVladimir Oltean static inline unsigned int dsa_port_bridge_num_get(struct dsa_port *dp)
76836cbf39bSVladimir Oltean {
769d3eed0e5SVladimir Oltean return dp->bridge ? dp->bridge->num : 0;
77036cbf39bSVladimir Oltean }
77136cbf39bSVladimir Oltean
dsa_port_bridge_same(const struct dsa_port * a,const struct dsa_port * b)77236cbf39bSVladimir Oltean static inline bool dsa_port_bridge_same(const struct dsa_port *a,
77336cbf39bSVladimir Oltean const struct dsa_port *b)
77436cbf39bSVladimir Oltean {
77536cbf39bSVladimir Oltean struct net_device *br_a = dsa_port_bridge_dev_get(a);
77636cbf39bSVladimir Oltean struct net_device *br_b = dsa_port_bridge_dev_get(b);
77736cbf39bSVladimir Oltean
77836cbf39bSVladimir Oltean /* Standalone ports are not in the same bridge with one another */
77936cbf39bSVladimir Oltean return (!br_a || !br_b) ? false : (br_a == br_b);
78036cbf39bSVladimir Oltean }
78136cbf39bSVladimir Oltean
dsa_port_offloads_bridge_port(struct dsa_port * dp,const struct net_device * dev)7826a43cba3SVladimir Oltean static inline bool dsa_port_offloads_bridge_port(struct dsa_port *dp,
7836a43cba3SVladimir Oltean const struct net_device *dev)
7846a43cba3SVladimir Oltean {
7856a43cba3SVladimir Oltean return dsa_port_to_bridge_port(dp) == dev;
7866a43cba3SVladimir Oltean }
7876a43cba3SVladimir Oltean
7886a43cba3SVladimir Oltean static inline bool
dsa_port_offloads_bridge_dev(struct dsa_port * dp,const struct net_device * bridge_dev)7896a43cba3SVladimir Oltean dsa_port_offloads_bridge_dev(struct dsa_port *dp,
7906a43cba3SVladimir Oltean const struct net_device *bridge_dev)
7916a43cba3SVladimir Oltean {
7926a43cba3SVladimir Oltean /* DSA ports connected to a bridge, and event was emitted
7936a43cba3SVladimir Oltean * for the bridge.
7946a43cba3SVladimir Oltean */
7956a43cba3SVladimir Oltean return dsa_port_bridge_dev_get(dp) == bridge_dev;
7966a43cba3SVladimir Oltean }
7976a43cba3SVladimir Oltean
dsa_port_offloads_bridge(struct dsa_port * dp,const struct dsa_bridge * bridge)798d3eed0e5SVladimir Oltean static inline bool dsa_port_offloads_bridge(struct dsa_port *dp,
799d3eed0e5SVladimir Oltean const struct dsa_bridge *bridge)
800d3eed0e5SVladimir Oltean {
801d3eed0e5SVladimir Oltean return dsa_port_bridge_dev_get(dp) == bridge->dev;
802d3eed0e5SVladimir Oltean }
803d3eed0e5SVladimir Oltean
8046a43cba3SVladimir Oltean /* Returns true if any port of this tree offloads the given net_device */
dsa_tree_offloads_bridge_port(struct dsa_switch_tree * dst,const struct net_device * dev)8056a43cba3SVladimir Oltean static inline bool dsa_tree_offloads_bridge_port(struct dsa_switch_tree *dst,
8066a43cba3SVladimir Oltean const struct net_device *dev)
8076a43cba3SVladimir Oltean {
8086a43cba3SVladimir Oltean struct dsa_port *dp;
8096a43cba3SVladimir Oltean
8106a43cba3SVladimir Oltean list_for_each_entry(dp, &dst->ports, list)
8116a43cba3SVladimir Oltean if (dsa_port_offloads_bridge_port(dp, dev))
8126a43cba3SVladimir Oltean return true;
8136a43cba3SVladimir Oltean
8146a43cba3SVladimir Oltean return false;
8156a43cba3SVladimir Oltean }
8166a43cba3SVladimir Oltean
8176a43cba3SVladimir Oltean /* Returns true if any port of this tree offloads the given bridge */
8186a43cba3SVladimir Oltean static inline bool
dsa_tree_offloads_bridge_dev(struct dsa_switch_tree * dst,const struct net_device * bridge_dev)8196a43cba3SVladimir Oltean dsa_tree_offloads_bridge_dev(struct dsa_switch_tree *dst,
8206a43cba3SVladimir Oltean const struct net_device *bridge_dev)
8216a43cba3SVladimir Oltean {
8226a43cba3SVladimir Oltean struct dsa_port *dp;
8236a43cba3SVladimir Oltean
8246a43cba3SVladimir Oltean list_for_each_entry(dp, &dst->ports, list)
8256a43cba3SVladimir Oltean if (dsa_port_offloads_bridge_dev(dp, bridge_dev))
8266a43cba3SVladimir Oltean return true;
8276a43cba3SVladimir Oltean
8286a43cba3SVladimir Oltean return false;
8296a43cba3SVladimir Oltean }
8306a43cba3SVladimir Oltean
dsa_port_tree_same(const struct dsa_port * a,const struct dsa_port * b)831acc43b7bSVladimir Oltean static inline bool dsa_port_tree_same(const struct dsa_port *a,
832acc43b7bSVladimir Oltean const struct dsa_port *b)
833acc43b7bSVladimir Oltean {
834acc43b7bSVladimir Oltean return a->ds->dst == b->ds->dst;
835acc43b7bSVladimir Oltean }
836acc43b7bSVladimir Oltean
8372bedde1aSArkadi Sharshevsky typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid,
8382bedde1aSArkadi Sharshevsky bool is_static, void *data);
8399d490b4eSVivien Didelot struct dsa_switch_ops {
84053da0ebaSVladimir Oltean /*
84153da0ebaSVladimir Oltean * Tagging protocol helpers called for the CPU ports and DSA links.
84253da0ebaSVladimir Oltean * @get_tag_protocol retrieves the initial tagging protocol and is
84353da0ebaSVladimir Oltean * mandatory. Switches which can operate using multiple tagging
84453da0ebaSVladimir Oltean * protocols should implement @change_tag_protocol and report in
84553da0ebaSVladimir Oltean * @get_tag_protocol the tagger in current use.
84653da0ebaSVladimir Oltean */
8475ed4e3ebSFlorian Fainelli enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds,
8484d776482SFlorian Fainelli int port,
8494d776482SFlorian Fainelli enum dsa_tag_protocol mprot);
850bacf93b0SVladimir Oltean int (*change_tag_protocol)(struct dsa_switch *ds,
85153da0ebaSVladimir Oltean enum dsa_tag_protocol proto);
852dc452a47SVladimir Oltean /*
853dc452a47SVladimir Oltean * Method for switch drivers to connect to the tagging protocol driver
854dc452a47SVladimir Oltean * in current use. The switch driver can provide handlers for certain
855dc452a47SVladimir Oltean * types of packets for switch management.
856dc452a47SVladimir Oltean */
857dc452a47SVladimir Oltean int (*connect_tag_protocol)(struct dsa_switch *ds,
858dc452a47SVladimir Oltean enum dsa_tag_protocol proto);
8597b314362SAndrew Lunn
8606ca80638SFlorian Fainelli int (*port_change_conduit)(struct dsa_switch *ds, int port,
8616ca80638SFlorian Fainelli struct net_device *conduit,
86295f510d0SVladimir Oltean struct netlink_ext_ack *extack);
86395f510d0SVladimir Oltean
864fd292c18SVladimir Oltean /* Optional switch-wide initialization and destruction methods */
865c8f0b869SBen Hutchings int (*setup)(struct dsa_switch *ds);
8665e3f847aSVladimir Oltean void (*teardown)(struct dsa_switch *ds);
867fd292c18SVladimir Oltean
868fd292c18SVladimir Oltean /* Per-port initialization and destruction methods. Mandatory if the
869fd292c18SVladimir Oltean * driver registers devlink port regions, optional otherwise.
870fd292c18SVladimir Oltean */
871fd292c18SVladimir Oltean int (*port_setup)(struct dsa_switch *ds, int port);
872fd292c18SVladimir Oltean void (*port_teardown)(struct dsa_switch *ds, int port);
873fd292c18SVladimir Oltean
8746819563eSFlorian Fainelli u32 (*get_phy_flags)(struct dsa_switch *ds, int port);
875c8f0b869SBen Hutchings
876c8f0b869SBen Hutchings /*
877c8f0b869SBen Hutchings * Access to the switch's PHY registers.
878c8f0b869SBen Hutchings */
879c8f0b869SBen Hutchings int (*phy_read)(struct dsa_switch *ds, int port, int regnum);
880c8f0b869SBen Hutchings int (*phy_write)(struct dsa_switch *ds, int port,
881c8f0b869SBen Hutchings int regnum, u16 val);
882c8f0b869SBen Hutchings
883c8f0b869SBen Hutchings /*
88411d8f3ddSFlorian Fainelli * PHYLINK integration
88511d8f3ddSFlorian Fainelli */
886072eea6cSRussell King (Oracle) void (*phylink_get_caps)(struct dsa_switch *ds, int port,
887072eea6cSRussell King (Oracle) struct phylink_config *config);
888bde01822SRussell King (Oracle) struct phylink_pcs *(*phylink_mac_select_pcs)(struct dsa_switch *ds,
889bde01822SRussell King (Oracle) int port,
890bde01822SRussell King (Oracle) phy_interface_t iface);
89111d8f3ddSFlorian Fainelli void (*phylink_mac_config)(struct dsa_switch *ds, int port,
89211d8f3ddSFlorian Fainelli unsigned int mode,
89311d8f3ddSFlorian Fainelli const struct phylink_link_state *state);
89411d8f3ddSFlorian Fainelli void (*phylink_mac_link_down)(struct dsa_switch *ds, int port,
89511d8f3ddSFlorian Fainelli unsigned int mode,
89611d8f3ddSFlorian Fainelli phy_interface_t interface);
89711d8f3ddSFlorian Fainelli void (*phylink_mac_link_up)(struct dsa_switch *ds, int port,
89811d8f3ddSFlorian Fainelli unsigned int mode,
89911d8f3ddSFlorian Fainelli phy_interface_t interface,
9005b502a7bSRussell King struct phy_device *phydev,
9015b502a7bSRussell King int speed, int duplex,
9025b502a7bSRussell King bool tx_pause, bool rx_pause);
90311d8f3ddSFlorian Fainelli void (*phylink_fixed_state)(struct dsa_switch *ds, int port,
90411d8f3ddSFlorian Fainelli struct phylink_link_state *state);
90511d8f3ddSFlorian Fainelli /*
906c2ec5f2eSOleksij Rempel * Port statistics counters.
907c8f0b869SBen Hutchings */
90889f09048SFlorian Fainelli void (*get_strings)(struct dsa_switch *ds, int port,
90989f09048SFlorian Fainelli u32 stringset, uint8_t *data);
910c8f0b869SBen Hutchings void (*get_ethtool_stats)(struct dsa_switch *ds,
911c8f0b869SBen Hutchings int port, uint64_t *data);
91289f09048SFlorian Fainelli int (*get_sset_count)(struct dsa_switch *ds, int port, int sset);
913cf963573SFlorian Fainelli void (*get_ethtool_phy_stats)(struct dsa_switch *ds,
914cf963573SFlorian Fainelli int port, uint64_t *data);
915487d3855SAlvin Šipraga void (*get_eth_phy_stats)(struct dsa_switch *ds, int port,
916487d3855SAlvin Šipraga struct ethtool_eth_phy_stats *phy_stats);
917487d3855SAlvin Šipraga void (*get_eth_mac_stats)(struct dsa_switch *ds, int port,
918487d3855SAlvin Šipraga struct ethtool_eth_mac_stats *mac_stats);
919487d3855SAlvin Šipraga void (*get_eth_ctrl_stats)(struct dsa_switch *ds, int port,
920487d3855SAlvin Šipraga struct ethtool_eth_ctrl_stats *ctrl_stats);
92167f38b1cSClément Léger void (*get_rmon_stats)(struct dsa_switch *ds, int port,
92267f38b1cSClément Léger struct ethtool_rmon_stats *rmon_stats,
92367f38b1cSClément Léger const struct ethtool_rmon_hist_range **ranges);
924c2ec5f2eSOleksij Rempel void (*get_stats64)(struct dsa_switch *ds, int port,
925c2ec5f2eSOleksij Rempel struct rtnl_link_stats64 *s);
9263d410403SOleksij Rempel void (*get_pause_stats)(struct dsa_switch *ds, int port,
9273d410403SOleksij Rempel struct ethtool_pause_stats *pause_stats);
928a71acad9SOleksij Rempel void (*self_test)(struct dsa_switch *ds, int port,
929a71acad9SOleksij Rempel struct ethtool_test *etest, u64 *data);
93024462549SFlorian Fainelli
93124462549SFlorian Fainelli /*
93219e57c4eSFlorian Fainelli * ethtool Wake-on-LAN
93319e57c4eSFlorian Fainelli */
93419e57c4eSFlorian Fainelli void (*get_wol)(struct dsa_switch *ds, int port,
93519e57c4eSFlorian Fainelli struct ethtool_wolinfo *w);
93619e57c4eSFlorian Fainelli int (*set_wol)(struct dsa_switch *ds, int port,
93719e57c4eSFlorian Fainelli struct ethtool_wolinfo *w);
93819e57c4eSFlorian Fainelli
93919e57c4eSFlorian Fainelli /*
9400336369dSBrandon Streiff * ethtool timestamp info
9410336369dSBrandon Streiff */
9420336369dSBrandon Streiff int (*get_ts_info)(struct dsa_switch *ds, int port,
9432111375bSKory Maincent struct kernel_ethtool_ts_info *ts);
9440336369dSBrandon Streiff
9450336369dSBrandon Streiff /*
9465f6c2d49SVladimir Oltean * ethtool MAC merge layer
9475f6c2d49SVladimir Oltean */
9485f6c2d49SVladimir Oltean int (*get_mm)(struct dsa_switch *ds, int port,
9495f6c2d49SVladimir Oltean struct ethtool_mm_state *state);
9505f6c2d49SVladimir Oltean int (*set_mm)(struct dsa_switch *ds, int port,
9515f6c2d49SVladimir Oltean struct ethtool_mm_cfg *cfg,
9525f6c2d49SVladimir Oltean struct netlink_ext_ack *extack);
9535f6c2d49SVladimir Oltean void (*get_mm_stats)(struct dsa_switch *ds, int port,
9545f6c2d49SVladimir Oltean struct ethtool_mm_stats *stats);
9555f6c2d49SVladimir Oltean
9565f6c2d49SVladimir Oltean /*
957d538eca8SVladimir Oltean * DCB ops
958d538eca8SVladimir Oltean */
959d538eca8SVladimir Oltean int (*port_get_default_prio)(struct dsa_switch *ds, int port);
960d538eca8SVladimir Oltean int (*port_set_default_prio)(struct dsa_switch *ds, int port,
961d538eca8SVladimir Oltean u8 prio);
96247d75f78SVladimir Oltean int (*port_get_dscp_prio)(struct dsa_switch *ds, int port, u8 dscp);
96347d75f78SVladimir Oltean int (*port_add_dscp_prio)(struct dsa_switch *ds, int port, u8 dscp,
96447d75f78SVladimir Oltean u8 prio);
96547d75f78SVladimir Oltean int (*port_del_dscp_prio)(struct dsa_switch *ds, int port, u8 dscp,
96647d75f78SVladimir Oltean u8 prio);
96796c6f337SOleksij Rempel int (*port_set_apptrust)(struct dsa_switch *ds, int port,
96896c6f337SOleksij Rempel const u8 *sel, int nsel);
96996c6f337SOleksij Rempel int (*port_get_apptrust)(struct dsa_switch *ds, int port, u8 *sel,
97096c6f337SOleksij Rempel int *nsel);
971d538eca8SVladimir Oltean
972d538eca8SVladimir Oltean /*
97324462549SFlorian Fainelli * Suspend and resume
97424462549SFlorian Fainelli */
97524462549SFlorian Fainelli int (*suspend)(struct dsa_switch *ds);
97624462549SFlorian Fainelli int (*resume)(struct dsa_switch *ds);
977b2f2af21SFlorian Fainelli
978b2f2af21SFlorian Fainelli /*
979b2f2af21SFlorian Fainelli * Port enable/disable
980b2f2af21SFlorian Fainelli */
981b2f2af21SFlorian Fainelli int (*port_enable)(struct dsa_switch *ds, int port,
982b2f2af21SFlorian Fainelli struct phy_device *phy);
98375104db0SAndrew Lunn void (*port_disable)(struct dsa_switch *ds, int port);
9847905288fSFlorian Fainelli
9856715042cSVladimir Oltean
9866715042cSVladimir Oltean /*
9876715042cSVladimir Oltean * Notification for MAC address changes on user ports. Drivers can
9886715042cSVladimir Oltean * currently only veto operations. They should not use the method to
9896715042cSVladimir Oltean * program the hardware, since the operation is not rolled back in case
9906715042cSVladimir Oltean * of other errors.
9916715042cSVladimir Oltean */
9926715042cSVladimir Oltean int (*port_set_mac_address)(struct dsa_switch *ds, int port,
9936715042cSVladimir Oltean const unsigned char *addr);
9946715042cSVladimir Oltean
9957905288fSFlorian Fainelli /*
996b79d7c14SVladimir Oltean * Compatibility between device trees defining multiple CPU ports and
997b79d7c14SVladimir Oltean * drivers which are not OK to use by default the numerically smallest
998b79d7c14SVladimir Oltean * CPU port of a switch for its local ports. This can return NULL,
999b79d7c14SVladimir Oltean * meaning "don't know/don't care".
1000b79d7c14SVladimir Oltean */
1001b79d7c14SVladimir Oltean struct dsa_port *(*preferred_default_local_cpu_port)(struct dsa_switch *ds);
1002b79d7c14SVladimir Oltean
1003b79d7c14SVladimir Oltean /*
100408f50061SVivien Didelot * Port's MAC EEE settings
10057905288fSFlorian Fainelli */
100608f50061SVivien Didelot int (*set_mac_eee)(struct dsa_switch *ds, int port,
1007d80a5233SHeiner Kallweit struct ethtool_keee *e);
100808f50061SVivien Didelot int (*get_mac_eee)(struct dsa_switch *ds, int port,
1009d80a5233SHeiner Kallweit struct ethtool_keee *e);
101051579c3fSGuenter Roeck
10116793abb4SGuenter Roeck /* EEPROM access */
10126793abb4SGuenter Roeck int (*get_eeprom_len)(struct dsa_switch *ds);
10136793abb4SGuenter Roeck int (*get_eeprom)(struct dsa_switch *ds,
10146793abb4SGuenter Roeck struct ethtool_eeprom *eeprom, u8 *data);
10156793abb4SGuenter Roeck int (*set_eeprom)(struct dsa_switch *ds,
10166793abb4SGuenter Roeck struct ethtool_eeprom *eeprom, u8 *data);
10173d762a0fSGuenter Roeck
10183d762a0fSGuenter Roeck /*
10193d762a0fSGuenter Roeck * Register access.
10203d762a0fSGuenter Roeck */
10213d762a0fSGuenter Roeck int (*get_regs_len)(struct dsa_switch *ds, int port);
10223d762a0fSGuenter Roeck void (*get_regs)(struct dsa_switch *ds, int port,
10233d762a0fSGuenter Roeck struct ethtool_regs *regs, void *p);
1024b73adef6SFlorian Fainelli
1025b73adef6SFlorian Fainelli /*
1026e358bef7SVladimir Oltean * Upper device tracking.
1027e358bef7SVladimir Oltean */
1028e358bef7SVladimir Oltean int (*port_prechangeupper)(struct dsa_switch *ds, int port,
1029e358bef7SVladimir Oltean struct netdev_notifier_changeupper_info *info);
1030e358bef7SVladimir Oltean
1031e358bef7SVladimir Oltean /*
1032b73adef6SFlorian Fainelli * Bridge integration
1033b73adef6SFlorian Fainelli */
103434a79f63SVivien Didelot int (*set_ageing_time)(struct dsa_switch *ds, unsigned int msecs);
103571327a4eSVivien Didelot int (*port_bridge_join)(struct dsa_switch *ds, int port,
1036b079922bSVladimir Oltean struct dsa_bridge bridge,
103706b9cce4SVladimir Oltean bool *tx_fwd_offload,
103806b9cce4SVladimir Oltean struct netlink_ext_ack *extack);
1039f123f2fbSVivien Didelot void (*port_bridge_leave)(struct dsa_switch *ds, int port,
1040d3eed0e5SVladimir Oltean struct dsa_bridge bridge);
104143c44a9fSVivien Didelot void (*port_stp_state_set)(struct dsa_switch *ds, int port,
1042b73adef6SFlorian Fainelli u8 state);
10437414af30STobias Waldekranz int (*port_mst_state_set)(struct dsa_switch *ds, int port,
10447414af30STobias Waldekranz const struct switchdev_mst_state *state);
1045732f794cSVivien Didelot void (*port_fast_age)(struct dsa_switch *ds, int port);
10467414af30STobias Waldekranz int (*port_vlan_fast_age)(struct dsa_switch *ds, int port, u16 vid);
1047a8b659e7SVladimir Oltean int (*port_pre_bridge_flags)(struct dsa_switch *ds, int port,
1048a8b659e7SVladimir Oltean struct switchdev_brport_flags flags,
1049a8b659e7SVladimir Oltean struct netlink_ext_ack *extack);
1050a8b659e7SVladimir Oltean int (*port_bridge_flags)(struct dsa_switch *ds, int port,
1051a8b659e7SVladimir Oltean struct switchdev_brport_flags flags,
1052a8b659e7SVladimir Oltean struct netlink_ext_ack *extack);
105372c3b0c7SVladimir Oltean void (*port_set_host_flood)(struct dsa_switch *ds, int port,
105472c3b0c7SVladimir Oltean bool uc, bool mc);
10552a778e1bSVivien Didelot
10562a778e1bSVivien Didelot /*
105711149536SVivien Didelot * VLAN support
105811149536SVivien Didelot */
1059fb2dabadSVivien Didelot int (*port_vlan_filtering)(struct dsa_switch *ds, int port,
106089153ed6SVladimir Oltean bool vlan_filtering,
106189153ed6SVladimir Oltean struct netlink_ext_ack *extack);
10621958d581SVladimir Oltean int (*port_vlan_add)(struct dsa_switch *ds, int port,
106331046a5fSVladimir Oltean const struct switchdev_obj_port_vlan *vlan,
106431046a5fSVladimir Oltean struct netlink_ext_ack *extack);
106576e398a6SVivien Didelot int (*port_vlan_del)(struct dsa_switch *ds, int port,
106676e398a6SVivien Didelot const struct switchdev_obj_port_vlan *vlan);
10678e6598a7STobias Waldekranz int (*vlan_msti_set)(struct dsa_switch *ds, struct dsa_bridge bridge,
10688e6598a7STobias Waldekranz const struct switchdev_vlan_msti *msti);
10698e6598a7STobias Waldekranz
107011149536SVivien Didelot /*
10712a778e1bSVivien Didelot * Forwarding database
10722a778e1bSVivien Didelot */
10731b6dd556SArkadi Sharshevsky int (*port_fdb_add)(struct dsa_switch *ds, int port,
1074c2693363SVladimir Oltean const unsigned char *addr, u16 vid,
1075c2693363SVladimir Oltean struct dsa_db db);
10762a778e1bSVivien Didelot int (*port_fdb_del)(struct dsa_switch *ds, int port,
1077c2693363SVladimir Oltean const unsigned char *addr, u16 vid,
1078c2693363SVladimir Oltean struct dsa_db db);
1079ea70ba98SVivien Didelot int (*port_fdb_dump)(struct dsa_switch *ds, int port,
10802bedde1aSArkadi Sharshevsky dsa_fdb_dump_cb_t *cb, void *data);
1081e212fa7cSVladimir Oltean int (*lag_fdb_add)(struct dsa_switch *ds, struct dsa_lag lag,
1082c2693363SVladimir Oltean const unsigned char *addr, u16 vid,
1083c2693363SVladimir Oltean struct dsa_db db);
1084e212fa7cSVladimir Oltean int (*lag_fdb_del)(struct dsa_switch *ds, struct dsa_lag lag,
1085c2693363SVladimir Oltean const unsigned char *addr, u16 vid,
1086c2693363SVladimir Oltean struct dsa_db db);
10878df30255SVivien Didelot
10888df30255SVivien Didelot /*
10898df30255SVivien Didelot * Multicast database
10908df30255SVivien Didelot */
1091a52b2da7SVladimir Oltean int (*port_mdb_add)(struct dsa_switch *ds, int port,
1092c2693363SVladimir Oltean const struct switchdev_obj_port_mdb *mdb,
1093c2693363SVladimir Oltean struct dsa_db db);
10948df30255SVivien Didelot int (*port_mdb_del)(struct dsa_switch *ds, int port,
1095c2693363SVladimir Oltean const struct switchdev_obj_port_mdb *mdb,
1096c2693363SVladimir Oltean struct dsa_db db);
1097bf9f2648SFlorian Fainelli /*
1098bf9f2648SFlorian Fainelli * RXNFC
1099bf9f2648SFlorian Fainelli */
1100bf9f2648SFlorian Fainelli int (*get_rxnfc)(struct dsa_switch *ds, int port,
1101bf9f2648SFlorian Fainelli struct ethtool_rxnfc *nfc, u32 *rule_locs);
1102bf9f2648SFlorian Fainelli int (*set_rxnfc)(struct dsa_switch *ds, int port,
1103bf9f2648SFlorian Fainelli struct ethtool_rxnfc *nfc);
1104f50f2127SFlorian Fainelli
1105f50f2127SFlorian Fainelli /*
1106f50f2127SFlorian Fainelli * TC integration
1107f50f2127SFlorian Fainelli */
1108ed11bb1fSVladimir Oltean int (*cls_flower_add)(struct dsa_switch *ds, int port,
1109ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, bool ingress);
1110ed11bb1fSVladimir Oltean int (*cls_flower_del)(struct dsa_switch *ds, int port,
1111ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, bool ingress);
1112ed11bb1fSVladimir Oltean int (*cls_flower_stats)(struct dsa_switch *ds, int port,
1113ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, bool ingress);
1114f50f2127SFlorian Fainelli int (*port_mirror_add)(struct dsa_switch *ds, int port,
1115f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror,
11160148bb50SVladimir Oltean bool ingress, struct netlink_ext_ack *extack);
1117f50f2127SFlorian Fainelli void (*port_mirror_del)(struct dsa_switch *ds, int port,
1118f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror);
111934297176SVladimir Oltean int (*port_policer_add)(struct dsa_switch *ds, int port,
112034297176SVladimir Oltean struct dsa_mall_policer_tc_entry *policer);
112134297176SVladimir Oltean void (*port_policer_del)(struct dsa_switch *ds, int port);
112247d23af2SVladimir Oltean int (*port_setup_tc)(struct dsa_switch *ds, int port,
112347d23af2SVladimir Oltean enum tc_setup_type type, void *type_data);
112440ef2c93SVivien Didelot
112540ef2c93SVivien Didelot /*
112640ef2c93SVivien Didelot * Cross-chip operations
112740ef2c93SVivien Didelot */
1128f66a6a69SVladimir Oltean int (*crosschip_bridge_join)(struct dsa_switch *ds, int tree_index,
1129f66a6a69SVladimir Oltean int sw_index, int port,
113006b9cce4SVladimir Oltean struct dsa_bridge bridge,
113106b9cce4SVladimir Oltean struct netlink_ext_ack *extack);
1132f66a6a69SVladimir Oltean void (*crosschip_bridge_leave)(struct dsa_switch *ds, int tree_index,
1133f66a6a69SVladimir Oltean int sw_index, int port,
1134d3eed0e5SVladimir Oltean struct dsa_bridge bridge);
1135058102a6STobias Waldekranz int (*crosschip_lag_change)(struct dsa_switch *ds, int sw_index,
1136058102a6STobias Waldekranz int port);
1137058102a6STobias Waldekranz int (*crosschip_lag_join)(struct dsa_switch *ds, int sw_index,
1138dedd6a00SVladimir Oltean int port, struct dsa_lag lag,
11392e359b00SVladimir Oltean struct netdev_lag_upper_info *info,
11402e359b00SVladimir Oltean struct netlink_ext_ack *extack);
1141058102a6STobias Waldekranz int (*crosschip_lag_leave)(struct dsa_switch *ds, int sw_index,
1142dedd6a00SVladimir Oltean int port, struct dsa_lag lag);
11430336369dSBrandon Streiff
11440336369dSBrandon Streiff /*
11450336369dSBrandon Streiff * PTP functionality
11460336369dSBrandon Streiff */
11470336369dSBrandon Streiff int (*port_hwtstamp_get)(struct dsa_switch *ds, int port,
11480336369dSBrandon Streiff struct ifreq *ifr);
11490336369dSBrandon Streiff int (*port_hwtstamp_set)(struct dsa_switch *ds, int port,
11500336369dSBrandon Streiff struct ifreq *ifr);
11515c5416f5SYangbo Lu void (*port_txtstamp)(struct dsa_switch *ds, int port,
11525c5416f5SYangbo Lu struct sk_buff *skb);
115390af1059SBrandon Streiff bool (*port_rxtstamp)(struct dsa_switch *ds, int port,
115490af1059SBrandon Streiff struct sk_buff *skb, unsigned int type);
115597a69a0dSVladimir Oltean
11560f06b855SAndrew Lunn /* Devlink parameters, etc */
11576b297524SAndrew Lunn int (*devlink_param_get)(struct dsa_switch *ds, u32 id,
11586b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx);
11596b297524SAndrew Lunn int (*devlink_param_set)(struct dsa_switch *ds, u32 id,
11606b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx);
11610f06b855SAndrew Lunn int (*devlink_info_get)(struct dsa_switch *ds,
11620f06b855SAndrew Lunn struct devlink_info_req *req,
11630f06b855SAndrew Lunn struct netlink_ext_ack *extack);
11642a6ef763SVladimir Oltean int (*devlink_sb_pool_get)(struct dsa_switch *ds,
11652a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index,
11662a6ef763SVladimir Oltean struct devlink_sb_pool_info *pool_info);
11672a6ef763SVladimir Oltean int (*devlink_sb_pool_set)(struct dsa_switch *ds, unsigned int sb_index,
11682a6ef763SVladimir Oltean u16 pool_index, u32 size,
11692a6ef763SVladimir Oltean enum devlink_sb_threshold_type threshold_type,
11702a6ef763SVladimir Oltean struct netlink_ext_ack *extack);
11712a6ef763SVladimir Oltean int (*devlink_sb_port_pool_get)(struct dsa_switch *ds, int port,
11722a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index,
11732a6ef763SVladimir Oltean u32 *p_threshold);
11742a6ef763SVladimir Oltean int (*devlink_sb_port_pool_set)(struct dsa_switch *ds, int port,
11752a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index,
11762a6ef763SVladimir Oltean u32 threshold,
11772a6ef763SVladimir Oltean struct netlink_ext_ack *extack);
11782a6ef763SVladimir Oltean int (*devlink_sb_tc_pool_bind_get)(struct dsa_switch *ds, int port,
11792a6ef763SVladimir Oltean unsigned int sb_index, u16 tc_index,
11802a6ef763SVladimir Oltean enum devlink_sb_pool_type pool_type,
11812a6ef763SVladimir Oltean u16 *p_pool_index, u32 *p_threshold);
11822a6ef763SVladimir Oltean int (*devlink_sb_tc_pool_bind_set)(struct dsa_switch *ds, int port,
11832a6ef763SVladimir Oltean unsigned int sb_index, u16 tc_index,
11842a6ef763SVladimir Oltean enum devlink_sb_pool_type pool_type,
11852a6ef763SVladimir Oltean u16 pool_index, u32 threshold,
11862a6ef763SVladimir Oltean struct netlink_ext_ack *extack);
11872a6ef763SVladimir Oltean int (*devlink_sb_occ_snapshot)(struct dsa_switch *ds,
11882a6ef763SVladimir Oltean unsigned int sb_index);
11892a6ef763SVladimir Oltean int (*devlink_sb_occ_max_clear)(struct dsa_switch *ds,
11902a6ef763SVladimir Oltean unsigned int sb_index);
11912a6ef763SVladimir Oltean int (*devlink_sb_occ_port_pool_get)(struct dsa_switch *ds, int port,
11922a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index,
11932a6ef763SVladimir Oltean u32 *p_cur, u32 *p_max);
11942a6ef763SVladimir Oltean int (*devlink_sb_occ_tc_port_bind_get)(struct dsa_switch *ds, int port,
11952a6ef763SVladimir Oltean unsigned int sb_index, u16 tc_index,
11962a6ef763SVladimir Oltean enum devlink_sb_pool_type pool_type,
11972a6ef763SVladimir Oltean u32 *p_cur, u32 *p_max);
1198bfcb8132SVladimir Oltean
1199bfcb8132SVladimir Oltean /*
1200bfcb8132SVladimir Oltean * MTU change functionality. Switches can also adjust their MRU through
1201bfcb8132SVladimir Oltean * this method. By MTU, one understands the SDU (L2 payload) length.
1202bfcb8132SVladimir Oltean * If the switch needs to account for the DSA tag on the CPU port, this
1203ab88d64aSRandy Dunlap * method needs to do so privately.
1204bfcb8132SVladimir Oltean */
1205bfcb8132SVladimir Oltean int (*port_change_mtu)(struct dsa_switch *ds, int port,
1206bfcb8132SVladimir Oltean int new_mtu);
1207bfcb8132SVladimir Oltean int (*port_max_mtu)(struct dsa_switch *ds, int port);
1208058102a6STobias Waldekranz
1209058102a6STobias Waldekranz /*
1210058102a6STobias Waldekranz * LAG integration
1211058102a6STobias Waldekranz */
1212058102a6STobias Waldekranz int (*port_lag_change)(struct dsa_switch *ds, int port);
1213058102a6STobias Waldekranz int (*port_lag_join)(struct dsa_switch *ds, int port,
1214dedd6a00SVladimir Oltean struct dsa_lag lag,
12152e359b00SVladimir Oltean struct netdev_lag_upper_info *info,
12162e359b00SVladimir Oltean struct netlink_ext_ack *extack);
1217058102a6STobias Waldekranz int (*port_lag_leave)(struct dsa_switch *ds, int port,
1218dedd6a00SVladimir Oltean struct dsa_lag lag);
121918596f50SGeorge McCollister
122018596f50SGeorge McCollister /*
122118596f50SGeorge McCollister * HSR integration
122218596f50SGeorge McCollister */
122318596f50SGeorge McCollister int (*port_hsr_join)(struct dsa_switch *ds, int port,
1224fefe5dc4SVladimir Oltean struct net_device *hsr,
1225fefe5dc4SVladimir Oltean struct netlink_ext_ack *extack);
122618596f50SGeorge McCollister int (*port_hsr_leave)(struct dsa_switch *ds, int port,
122718596f50SGeorge McCollister struct net_device *hsr);
1228c595c433SHoratiu Vultur
1229c595c433SHoratiu Vultur /*
1230c595c433SHoratiu Vultur * MRP integration
1231c595c433SHoratiu Vultur */
1232c595c433SHoratiu Vultur int (*port_mrp_add)(struct dsa_switch *ds, int port,
1233c595c433SHoratiu Vultur const struct switchdev_obj_mrp *mrp);
1234c595c433SHoratiu Vultur int (*port_mrp_del)(struct dsa_switch *ds, int port,
1235c595c433SHoratiu Vultur const struct switchdev_obj_mrp *mrp);
1236c595c433SHoratiu Vultur int (*port_mrp_add_ring_role)(struct dsa_switch *ds, int port,
1237c595c433SHoratiu Vultur const struct switchdev_obj_ring_role_mrp *mrp);
1238c595c433SHoratiu Vultur int (*port_mrp_del_ring_role)(struct dsa_switch *ds, int port,
1239c595c433SHoratiu Vultur const struct switchdev_obj_ring_role_mrp *mrp);
12405da11eb4SVladimir Oltean
12415da11eb4SVladimir Oltean /*
12425da11eb4SVladimir Oltean * tag_8021q operations
12435da11eb4SVladimir Oltean */
12445da11eb4SVladimir Oltean int (*tag_8021q_vlan_add)(struct dsa_switch *ds, int port, u16 vid,
12455da11eb4SVladimir Oltean u16 flags);
12465da11eb4SVladimir Oltean int (*tag_8021q_vlan_del)(struct dsa_switch *ds, int port, u16 vid);
1247295ab96fSVladimir Oltean
1248295ab96fSVladimir Oltean /*
12496ca80638SFlorian Fainelli * DSA conduit tracking operations
1250295ab96fSVladimir Oltean */
12516ca80638SFlorian Fainelli void (*conduit_state_change)(struct dsa_switch *ds,
12526ca80638SFlorian Fainelli const struct net_device *conduit,
1253295ab96fSVladimir Oltean bool operational);
12546b297524SAndrew Lunn };
12556b297524SAndrew Lunn
12566b297524SAndrew Lunn #define DSA_DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes) \
12576b297524SAndrew Lunn DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, \
12586b297524SAndrew Lunn dsa_devlink_param_get, dsa_devlink_param_set, NULL)
12596b297524SAndrew Lunn
12606b297524SAndrew Lunn int dsa_devlink_param_get(struct devlink *dl, u32 id,
12616b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx);
12626b297524SAndrew Lunn int dsa_devlink_param_set(struct devlink *dl, u32 id,
12635625ca56SMateusz Polchlopek struct devlink_param_gset_ctx *ctx,
12645625ca56SMateusz Polchlopek struct netlink_ext_ack *extack);
12656b297524SAndrew Lunn int dsa_devlink_params_register(struct dsa_switch *ds,
12666b297524SAndrew Lunn const struct devlink_param *params,
12676b297524SAndrew Lunn size_t params_count);
12686b297524SAndrew Lunn void dsa_devlink_params_unregister(struct dsa_switch *ds,
12696b297524SAndrew Lunn const struct devlink_param *params,
12706b297524SAndrew Lunn size_t params_count);
12715cd73fbdSAndrew Lunn int dsa_devlink_resource_register(struct dsa_switch *ds,
12725cd73fbdSAndrew Lunn const char *resource_name,
12735cd73fbdSAndrew Lunn u64 resource_size,
12745cd73fbdSAndrew Lunn u64 resource_id,
12755cd73fbdSAndrew Lunn u64 parent_resource_id,
12765cd73fbdSAndrew Lunn const struct devlink_resource_size_params *size_params);
12775cd73fbdSAndrew Lunn
12785cd73fbdSAndrew Lunn void dsa_devlink_resources_unregister(struct dsa_switch *ds);
12795cd73fbdSAndrew Lunn
12805cd73fbdSAndrew Lunn void dsa_devlink_resource_occ_get_register(struct dsa_switch *ds,
12815cd73fbdSAndrew Lunn u64 resource_id,
12825cd73fbdSAndrew Lunn devlink_resource_occ_get_t *occ_get,
12835cd73fbdSAndrew Lunn void *occ_get_priv);
12845cd73fbdSAndrew Lunn void dsa_devlink_resource_occ_get_unregister(struct dsa_switch *ds,
12855cd73fbdSAndrew Lunn u64 resource_id);
128697c82c23SAndrew Lunn struct devlink_region *
128797c82c23SAndrew Lunn dsa_devlink_region_create(struct dsa_switch *ds,
128897c82c23SAndrew Lunn const struct devlink_region_ops *ops,
128997c82c23SAndrew Lunn u32 region_max_snapshots, u64 region_size);
129008156ba4SAndrew Lunn struct devlink_region *
129108156ba4SAndrew Lunn dsa_devlink_port_region_create(struct dsa_switch *ds,
129208156ba4SAndrew Lunn int port,
129308156ba4SAndrew Lunn const struct devlink_port_region_ops *ops,
129408156ba4SAndrew Lunn u32 region_max_snapshots, u64 region_size);
129597c82c23SAndrew Lunn void dsa_devlink_region_destroy(struct devlink_region *region);
129697c82c23SAndrew Lunn
1297e1eea811SVladimir Oltean struct dsa_port *dsa_port_from_netdev(struct net_device *netdev);
12985cd73fbdSAndrew Lunn
12996b297524SAndrew Lunn struct dsa_devlink_priv {
13006b297524SAndrew Lunn struct dsa_switch *ds;
1301c8f0b869SBen Hutchings };
1302c8f0b869SBen Hutchings
dsa_devlink_to_ds(struct devlink * dl)1303ccc3e6b0SAndrew Lunn static inline struct dsa_switch *dsa_devlink_to_ds(struct devlink *dl)
1304ccc3e6b0SAndrew Lunn {
1305ccc3e6b0SAndrew Lunn struct dsa_devlink_priv *dl_priv = devlink_priv(dl);
1306ccc3e6b0SAndrew Lunn
1307ccc3e6b0SAndrew Lunn return dl_priv->ds;
1308ccc3e6b0SAndrew Lunn }
1309ccc3e6b0SAndrew Lunn
13107d1e2a10SAndrew Lunn static inline
dsa_devlink_port_to_ds(struct devlink_port * port)13117d1e2a10SAndrew Lunn struct dsa_switch *dsa_devlink_port_to_ds(struct devlink_port *port)
13127d1e2a10SAndrew Lunn {
13137d1e2a10SAndrew Lunn struct devlink *dl = port->devlink;
13147d1e2a10SAndrew Lunn struct dsa_devlink_priv *dl_priv = devlink_priv(dl);
13157d1e2a10SAndrew Lunn
13167d1e2a10SAndrew Lunn return dl_priv->ds;
13177d1e2a10SAndrew Lunn }
13187d1e2a10SAndrew Lunn
dsa_devlink_port_to_port(struct devlink_port * port)13197d1e2a10SAndrew Lunn static inline int dsa_devlink_port_to_port(struct devlink_port *port)
13207d1e2a10SAndrew Lunn {
13217d1e2a10SAndrew Lunn return port->index;
13227d1e2a10SAndrew Lunn }
13237d1e2a10SAndrew Lunn
1324ab3d408dSFlorian Fainelli struct dsa_switch_driver {
1325ab3d408dSFlorian Fainelli struct list_head list;
1326a82f67afSFlorian Fainelli const struct dsa_switch_ops *ops;
1327ab3d408dSFlorian Fainelli };
1328ab3d408dSFlorian Fainelli
13297e580490SVladimir Oltean bool dsa_fdb_present_in_other_db(struct dsa_switch *ds, int port,
13307e580490SVladimir Oltean const unsigned char *addr, u16 vid,
13317e580490SVladimir Oltean struct dsa_db db);
13327e580490SVladimir Oltean bool dsa_mdb_present_in_other_db(struct dsa_switch *ds, int port,
13337e580490SVladimir Oltean const struct switchdev_obj_port_mdb *mdb,
13347e580490SVladimir Oltean struct dsa_db db);
1335f9cef64fSVladimir Oltean
133673a7ece8SVivien Didelot /* Keep inline for faster access in hot path */
netdev_uses_dsa(const struct net_device * dev)13379eb8eff0SVladimir Oltean static inline bool netdev_uses_dsa(const struct net_device *dev)
1338c6e970a0SAndrew Lunn {
1339c6e970a0SAndrew Lunn #if IS_ENABLED(CONFIG_NET_DSA)
1340717ffbfbSVivien Didelot return dev->dsa_ptr && dev->dsa_ptr->rcv;
1341c6e970a0SAndrew Lunn #endif
1342c6e970a0SAndrew Lunn return false;
1343c6e970a0SAndrew Lunn }
1344c6e970a0SAndrew Lunn
13459790cf20SVladimir Oltean /* All DSA tags that push the EtherType to the right (basically all except tail
13469790cf20SVladimir Oltean * tags, which don't break dissection) can be treated the same from the
13479790cf20SVladimir Oltean * perspective of the flow dissector.
13489790cf20SVladimir Oltean *
13499790cf20SVladimir Oltean * We need to return:
13509790cf20SVladimir Oltean * - offset: the (B - A) difference between:
13519790cf20SVladimir Oltean * A. the position of the real EtherType and
13529790cf20SVladimir Oltean * B. the current skb->data (aka ETH_HLEN bytes into the frame, aka 2 bytes
13539790cf20SVladimir Oltean * after the normal EtherType was supposed to be)
13549790cf20SVladimir Oltean * The offset in bytes is exactly equal to the tagger overhead (and half of
13559790cf20SVladimir Oltean * that, in __be16 shorts).
13569790cf20SVladimir Oltean *
13579790cf20SVladimir Oltean * - proto: the value of the real EtherType.
13589790cf20SVladimir Oltean */
dsa_tag_generic_flow_dissect(const struct sk_buff * skb,__be16 * proto,int * offset)13599790cf20SVladimir Oltean static inline void dsa_tag_generic_flow_dissect(const struct sk_buff *skb,
13609790cf20SVladimir Oltean __be16 *proto, int *offset)
13619790cf20SVladimir Oltean {
13629790cf20SVladimir Oltean #if IS_ENABLED(CONFIG_NET_DSA)
13639790cf20SVladimir Oltean const struct dsa_device_ops *ops = skb->dev->dsa_ptr->tag_ops;
13644e500251SVladimir Oltean int tag_len = ops->needed_headroom;
13659790cf20SVladimir Oltean
13669790cf20SVladimir Oltean *offset = tag_len;
13679790cf20SVladimir Oltean *proto = ((__be16 *)skb->data)[(tag_len / 2) - 1];
13689790cf20SVladimir Oltean #endif
13699790cf20SVladimir Oltean }
13709790cf20SVladimir Oltean
137183c0afaeSAndrew Lunn void dsa_unregister_switch(struct dsa_switch *ds);
137223c9ee49SVivien Didelot int dsa_register_switch(struct dsa_switch *ds);
13730650bf52SVladimir Oltean void dsa_switch_shutdown(struct dsa_switch *ds);
13743b7bc1f0SVladimir Oltean struct dsa_switch *dsa_switch_find(int tree_index, int sw_index);
1375a2614140SVladimir Oltean void dsa_flush_workqueue(void);
1376ea825e70SFlorian Fainelli #ifdef CONFIG_PM_SLEEP
1377ea825e70SFlorian Fainelli int dsa_switch_suspend(struct dsa_switch *ds);
1378ea825e70SFlorian Fainelli int dsa_switch_resume(struct dsa_switch *ds);
1379ea825e70SFlorian Fainelli #else
dsa_switch_suspend(struct dsa_switch * ds)1380ea825e70SFlorian Fainelli static inline int dsa_switch_suspend(struct dsa_switch *ds)
1381ea825e70SFlorian Fainelli {
1382ea825e70SFlorian Fainelli return 0;
1383ea825e70SFlorian Fainelli }
dsa_switch_resume(struct dsa_switch * ds)1384ea825e70SFlorian Fainelli static inline int dsa_switch_resume(struct dsa_switch *ds)
1385ea825e70SFlorian Fainelli {
1386ea825e70SFlorian Fainelli return 0;
1387ea825e70SFlorian Fainelli }
1388ea825e70SFlorian Fainelli #endif /* CONFIG_PM_SLEEP */
1389ea825e70SFlorian Fainelli
139060724d4bSFlorian Fainelli #if IS_ENABLED(CONFIG_NET_DSA)
13916ca80638SFlorian Fainelli bool dsa_user_dev_check(const struct net_device *dev);
139260724d4bSFlorian Fainelli #else
dsa_user_dev_check(const struct net_device * dev)13936ca80638SFlorian Fainelli static inline bool dsa_user_dev_check(const struct net_device *dev)
1394a5e3c9baSVladimir Oltean {
1395a5e3c9baSVladimir Oltean return false;
1396a5e3c9baSVladimir Oltean }
139760724d4bSFlorian Fainelli #endif
139860724d4bSFlorian Fainelli
139997a69a0dSVladimir Oltean netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, struct net_device *dev);
140011d8f3ddSFlorian Fainelli void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up);
1401cf963573SFlorian Fainelli
140291da11f8SLennert Buytenhek #endif
1403