12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 291da11f8SLennert Buytenhek /* 391da11f8SLennert Buytenhek * include/net/dsa.h - Driver for Distributed Switch Architecture switch chips 4e84665c9SLennert Buytenhek * Copyright (c) 2008-2009 Marvell Semiconductor 591da11f8SLennert Buytenhek */ 691da11f8SLennert Buytenhek 791da11f8SLennert Buytenhek #ifndef __LINUX_NET_DSA_H 891da11f8SLennert Buytenhek #define __LINUX_NET_DSA_H 991da11f8SLennert Buytenhek 104d56a29fSRussell King #include <linux/if.h> 11ea1f51beSAxel Lin #include <linux/if_ether.h> 12c8f0b869SBen Hutchings #include <linux/list.h> 13f515f192SVivien Didelot #include <linux/notifier.h> 14cf50dcc2SBen Hutchings #include <linux/timer.h> 15cf50dcc2SBen Hutchings #include <linux/workqueue.h> 16fa981d9aSFlorian Fainelli #include <linux/of.h> 17a2820543SFlorian Fainelli #include <linux/ethtool.h> 180336369dSBrandon Streiff #include <linux/net_tstamp.h> 1911d8f3ddSFlorian Fainelli #include <linux/phy.h> 20ecfc9372SFlorian Fainelli #include <linux/platform_data/dsa.h> 2144cc27e4SIoana Ciornei #include <linux/phylink.h> 2296567d5dSAndrew Lunn #include <net/devlink.h> 23f0c24ccfSVivien Didelot #include <net/switchdev.h> 24cf50dcc2SBen Hutchings 25f50f2127SFlorian Fainelli struct tc_action; 264d56a29fSRussell King struct phy_device; 274d56a29fSRussell King struct fixed_phy_status; 2811d8f3ddSFlorian Fainelli struct phylink_link_state; 29f50f2127SFlorian Fainelli 300b42f033SAndrew Lunn #define DSA_TAG_PROTO_NONE_VALUE 0 310b42f033SAndrew Lunn #define DSA_TAG_PROTO_BRCM_VALUE 1 320b42f033SAndrew Lunn #define DSA_TAG_PROTO_BRCM_PREPEND_VALUE 2 330b42f033SAndrew Lunn #define DSA_TAG_PROTO_DSA_VALUE 3 340b42f033SAndrew Lunn #define DSA_TAG_PROTO_EDSA_VALUE 4 350b42f033SAndrew Lunn #define DSA_TAG_PROTO_GSWIP_VALUE 5 360b42f033SAndrew Lunn #define DSA_TAG_PROTO_KSZ9477_VALUE 6 370b42f033SAndrew Lunn #define DSA_TAG_PROTO_KSZ9893_VALUE 7 380b42f033SAndrew Lunn #define DSA_TAG_PROTO_LAN9303_VALUE 8 390b42f033SAndrew Lunn #define DSA_TAG_PROTO_MTK_VALUE 9 400b42f033SAndrew Lunn #define DSA_TAG_PROTO_QCA_VALUE 10 410b42f033SAndrew Lunn #define DSA_TAG_PROTO_TRAILER_VALUE 11 42f9bbe447SVladimir Oltean #define DSA_TAG_PROTO_8021Q_VALUE 12 43227d07a0SVladimir Oltean #define DSA_TAG_PROTO_SJA1105_VALUE 13 44016e43a2STristram Ha #define DSA_TAG_PROTO_KSZ8795_VALUE 14 458dce89aaSVladimir Oltean #define DSA_TAG_PROTO_OCELOT_VALUE 15 4648fda74fSOleksij Rempel #define DSA_TAG_PROTO_AR9331_VALUE 16 47efd7fe68SLinus Walleij #define DSA_TAG_PROTO_RTL4_A_VALUE 17 4801ef09caSKurt Kanzenbach #define DSA_TAG_PROTO_HELLCREEK_VALUE 18 4954a52823SGeorge McCollister #define DSA_TAG_PROTO_XRS700X_VALUE 19 507c83a7c5SVladimir Oltean #define DSA_TAG_PROTO_OCELOT_8021Q_VALUE 20 517c4bb540SVladimir Oltean #define DSA_TAG_PROTO_SEVILLE_VALUE 21 52964dbf18SÁlvaro Fernández Rojas #define DSA_TAG_PROTO_BRCM_LEGACY_VALUE 22 534913b8ebSVladimir Oltean #define DSA_TAG_PROTO_SJA1110_VALUE 23 541521d5adSAlvin Šipraga #define DSA_TAG_PROTO_RTL8_4_VALUE 24 55cd87fecdSLuiz Angelo Daros de Luca #define DSA_TAG_PROTO_RTL8_4T_VALUE 25 56a08d6a6dSClément Léger #define DSA_TAG_PROTO_RZN1_A5PSW_VALUE 26 57092f8751SPrasanna Vengateshan #define DSA_TAG_PROTO_LAN937X_VALUE 27 580b42f033SAndrew Lunn 59ac7a04c3SFlorian Fainelli enum dsa_tag_protocol { 600b42f033SAndrew Lunn DSA_TAG_PROTO_NONE = DSA_TAG_PROTO_NONE_VALUE, 610b42f033SAndrew Lunn DSA_TAG_PROTO_BRCM = DSA_TAG_PROTO_BRCM_VALUE, 62964dbf18SÁlvaro Fernández Rojas DSA_TAG_PROTO_BRCM_LEGACY = DSA_TAG_PROTO_BRCM_LEGACY_VALUE, 630b42f033SAndrew Lunn DSA_TAG_PROTO_BRCM_PREPEND = DSA_TAG_PROTO_BRCM_PREPEND_VALUE, 640b42f033SAndrew Lunn DSA_TAG_PROTO_DSA = DSA_TAG_PROTO_DSA_VALUE, 650b42f033SAndrew Lunn DSA_TAG_PROTO_EDSA = DSA_TAG_PROTO_EDSA_VALUE, 660b42f033SAndrew Lunn DSA_TAG_PROTO_GSWIP = DSA_TAG_PROTO_GSWIP_VALUE, 670b42f033SAndrew Lunn DSA_TAG_PROTO_KSZ9477 = DSA_TAG_PROTO_KSZ9477_VALUE, 680b42f033SAndrew Lunn DSA_TAG_PROTO_KSZ9893 = DSA_TAG_PROTO_KSZ9893_VALUE, 690b42f033SAndrew Lunn DSA_TAG_PROTO_LAN9303 = DSA_TAG_PROTO_LAN9303_VALUE, 700b42f033SAndrew Lunn DSA_TAG_PROTO_MTK = DSA_TAG_PROTO_MTK_VALUE, 710b42f033SAndrew Lunn DSA_TAG_PROTO_QCA = DSA_TAG_PROTO_QCA_VALUE, 720b42f033SAndrew Lunn DSA_TAG_PROTO_TRAILER = DSA_TAG_PROTO_TRAILER_VALUE, 73f9bbe447SVladimir Oltean DSA_TAG_PROTO_8021Q = DSA_TAG_PROTO_8021Q_VALUE, 74227d07a0SVladimir Oltean DSA_TAG_PROTO_SJA1105 = DSA_TAG_PROTO_SJA1105_VALUE, 75016e43a2STristram Ha DSA_TAG_PROTO_KSZ8795 = DSA_TAG_PROTO_KSZ8795_VALUE, 768dce89aaSVladimir Oltean DSA_TAG_PROTO_OCELOT = DSA_TAG_PROTO_OCELOT_VALUE, 7748fda74fSOleksij Rempel DSA_TAG_PROTO_AR9331 = DSA_TAG_PROTO_AR9331_VALUE, 78efd7fe68SLinus Walleij DSA_TAG_PROTO_RTL4_A = DSA_TAG_PROTO_RTL4_A_VALUE, 7901ef09caSKurt Kanzenbach DSA_TAG_PROTO_HELLCREEK = DSA_TAG_PROTO_HELLCREEK_VALUE, 8054a52823SGeorge McCollister DSA_TAG_PROTO_XRS700X = DSA_TAG_PROTO_XRS700X_VALUE, 817c83a7c5SVladimir Oltean DSA_TAG_PROTO_OCELOT_8021Q = DSA_TAG_PROTO_OCELOT_8021Q_VALUE, 827c4bb540SVladimir Oltean DSA_TAG_PROTO_SEVILLE = DSA_TAG_PROTO_SEVILLE_VALUE, 834913b8ebSVladimir Oltean DSA_TAG_PROTO_SJA1110 = DSA_TAG_PROTO_SJA1110_VALUE, 841521d5adSAlvin Šipraga DSA_TAG_PROTO_RTL8_4 = DSA_TAG_PROTO_RTL8_4_VALUE, 85cd87fecdSLuiz Angelo Daros de Luca DSA_TAG_PROTO_RTL8_4T = DSA_TAG_PROTO_RTL8_4T_VALUE, 86a08d6a6dSClément Léger DSA_TAG_PROTO_RZN1_A5PSW = DSA_TAG_PROTO_RZN1_A5PSW_VALUE, 87092f8751SPrasanna Vengateshan DSA_TAG_PROTO_LAN937X = DSA_TAG_PROTO_LAN937X_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 104c3975400SVladimir Oltean * address, in which case the DSA master 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 */ 108c3975400SVladimir Oltean bool promisc_on_master; 10968277a2cSJohn Crispin }; 11068277a2cSJohn Crispin 1114cfab356SFlorian Fainelli /* This structure defines the control interfaces that are overlayed by the 1124cfab356SFlorian Fainelli * DSA layer on top of the DSA CPU/management net_device instance. This is 1134cfab356SFlorian Fainelli * used by the core net_device layer while calling various net_device_ops 1144cfab356SFlorian Fainelli * function pointers. 1154cfab356SFlorian Fainelli */ 1164cfab356SFlorian Fainelli struct dsa_netdevice_ops { 117a7605370SArnd Bergmann int (*ndo_eth_ioctl)(struct net_device *dev, struct ifreq *ifr, 1184cfab356SFlorian Fainelli int cmd); 1194cfab356SFlorian Fainelli }; 1204cfab356SFlorian Fainelli 1210b42f033SAndrew Lunn #define DSA_TAG_DRIVER_ALIAS "dsa_tag-" 1220b42f033SAndrew Lunn #define MODULE_ALIAS_DSA_TAG_DRIVER(__proto) \ 1230b42f033SAndrew Lunn MODULE_ALIAS(DSA_TAG_DRIVER_ALIAS __stringify(__proto##_VALUE)) 1240b42f033SAndrew Lunn 125dedd6a00SVladimir Oltean struct dsa_lag { 126dedd6a00SVladimir Oltean struct net_device *dev; 127dedd6a00SVladimir Oltean unsigned int id; 128e212fa7cSVladimir Oltean struct mutex fdb_lock; 129e212fa7cSVladimir Oltean struct list_head fdbs; 130dedd6a00SVladimir Oltean refcount_t refcount; 131dedd6a00SVladimir Oltean }; 132dedd6a00SVladimir Oltean 133cf50dcc2SBen Hutchings struct dsa_switch_tree { 13483c0afaeSAndrew Lunn struct list_head list; 13583c0afaeSAndrew Lunn 136b035c88cSVladimir Oltean /* List of switch ports */ 137b035c88cSVladimir Oltean struct list_head ports; 138b035c88cSVladimir Oltean 139f515f192SVivien Didelot /* Notifier chain for switch-wide events */ 140f515f192SVivien Didelot struct raw_notifier_head nh; 141f515f192SVivien Didelot 14283c0afaeSAndrew Lunn /* Tree identifier */ 14349463b7fSVivien Didelot unsigned int index; 14483c0afaeSAndrew Lunn 14583c0afaeSAndrew Lunn /* Number of switches attached to this tree */ 14683c0afaeSAndrew Lunn struct kref refcount; 14783c0afaeSAndrew Lunn 148b035c88cSVladimir Oltean /* Maps offloaded LAG netdevs to a zero-based linear ID for 149b035c88cSVladimir Oltean * drivers that need it. 150b035c88cSVladimir Oltean */ 151dedd6a00SVladimir Oltean struct dsa_lag **lags; 152b035c88cSVladimir Oltean 153357f203bSVladimir Oltean /* Tagging protocol operations */ 154357f203bSVladimir Oltean const struct dsa_device_ops *tag_ops; 155357f203bSVladimir Oltean 156deff7107STobias Waldekranz /* Default tagging protocol preferred by the switches in this 157deff7107STobias Waldekranz * tree. 158deff7107STobias Waldekranz */ 159deff7107STobias Waldekranz enum dsa_tag_protocol default_proto; 160deff7107STobias Waldekranz 1614b026e82SVladimir Oltean /* Has this tree been applied to the hardware? */ 1624b026e82SVladimir Oltean bool setup; 1634b026e82SVladimir Oltean 164cf50dcc2SBen Hutchings /* 165cf50dcc2SBen Hutchings * Configuration data for the platform device that owns 166cf50dcc2SBen Hutchings * this dsa switch tree instance. 167cf50dcc2SBen Hutchings */ 168cf50dcc2SBen Hutchings struct dsa_platform_data *pd; 169cf85d08fSLennert Buytenhek 170c5f51765SVivien Didelot /* List of DSA links composing the routing table */ 171c5f51765SVivien Didelot struct list_head rtable; 172058102a6STobias Waldekranz 173b035c88cSVladimir Oltean /* Length of "lags" array */ 174058102a6STobias Waldekranz unsigned int lags_len; 1755b22d366SVladimir Oltean 1765b22d366SVladimir Oltean /* Track the largest switch index within a tree */ 1775b22d366SVladimir Oltean unsigned int last_switch; 178cf50dcc2SBen Hutchings }; 179cf50dcc2SBen Hutchings 1803d4a0a2aSVladimir Oltean /* LAG IDs are one-based, the dst->lags array is zero-based */ 181058102a6STobias Waldekranz #define dsa_lags_foreach_id(_id, _dst) \ 1823d4a0a2aSVladimir Oltean for ((_id) = 1; (_id) <= (_dst)->lags_len; (_id)++) \ 1833d4a0a2aSVladimir Oltean if ((_dst)->lags[(_id) - 1]) 184058102a6STobias Waldekranz 185058102a6STobias Waldekranz #define dsa_lag_foreach_port(_dp, _dst, _lag) \ 186058102a6STobias Waldekranz list_for_each_entry((_dp), &(_dst)->ports, list) \ 187dedd6a00SVladimir Oltean if (dsa_port_offloads_lag((_dp), (_lag))) 188058102a6STobias Waldekranz 18918596f50SGeorge McCollister #define dsa_hsr_foreach_port(_dp, _ds, _hsr) \ 19018596f50SGeorge McCollister list_for_each_entry((_dp), &(_ds)->dst->ports, list) \ 19118596f50SGeorge McCollister if ((_dp)->ds == (_ds) && (_dp)->hsr_dev == (_hsr)) 19218596f50SGeorge McCollister 193dedd6a00SVladimir Oltean static inline struct dsa_lag *dsa_lag_by_id(struct dsa_switch_tree *dst, 194058102a6STobias Waldekranz unsigned int id) 195058102a6STobias Waldekranz { 1963d4a0a2aSVladimir Oltean /* DSA LAG IDs are one-based, dst->lags is zero-based */ 1973d4a0a2aSVladimir Oltean return dst->lags[id - 1]; 198058102a6STobias Waldekranz } 199058102a6STobias Waldekranz 200058102a6STobias Waldekranz static inline int dsa_lag_id(struct dsa_switch_tree *dst, 20146a76724SVladimir Oltean struct net_device *lag_dev) 202058102a6STobias Waldekranz { 203058102a6STobias Waldekranz unsigned int id; 204058102a6STobias Waldekranz 205058102a6STobias Waldekranz dsa_lags_foreach_id(id, dst) { 206dedd6a00SVladimir Oltean struct dsa_lag *lag = dsa_lag_by_id(dst, id); 207dedd6a00SVladimir Oltean 208dedd6a00SVladimir Oltean if (lag->dev == lag_dev) 209dedd6a00SVladimir Oltean return lag->id; 210058102a6STobias Waldekranz } 211058102a6STobias Waldekranz 212058102a6STobias Waldekranz return -ENODEV; 213058102a6STobias Waldekranz } 214058102a6STobias Waldekranz 21534297176SVladimir Oltean /* TC matchall action types */ 216f50f2127SFlorian Fainelli enum dsa_port_mall_action_type { 217f50f2127SFlorian Fainelli DSA_PORT_MALL_MIRROR, 21834297176SVladimir Oltean DSA_PORT_MALL_POLICER, 219f50f2127SFlorian Fainelli }; 220f50f2127SFlorian Fainelli 221f50f2127SFlorian Fainelli /* TC mirroring entry */ 222f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry { 223f50f2127SFlorian Fainelli u8 to_local_port; 224f50f2127SFlorian Fainelli bool ingress; 225f50f2127SFlorian Fainelli }; 226f50f2127SFlorian Fainelli 22734297176SVladimir Oltean /* TC port policer entry */ 22834297176SVladimir Oltean struct dsa_mall_policer_tc_entry { 2295f035af7SPo Liu u32 burst; 23034297176SVladimir Oltean u64 rate_bytes_per_sec; 23134297176SVladimir Oltean }; 23234297176SVladimir Oltean 233f50f2127SFlorian Fainelli /* TC matchall entry */ 234f50f2127SFlorian Fainelli struct dsa_mall_tc_entry { 235f50f2127SFlorian Fainelli struct list_head list; 236f50f2127SFlorian Fainelli unsigned long cookie; 237f50f2127SFlorian Fainelli enum dsa_port_mall_action_type type; 238f50f2127SFlorian Fainelli union { 239f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry mirror; 24034297176SVladimir Oltean struct dsa_mall_policer_tc_entry policer; 241f50f2127SFlorian Fainelli }; 242f50f2127SFlorian Fainelli }; 243f50f2127SFlorian Fainelli 244d3eed0e5SVladimir Oltean struct dsa_bridge { 245d3eed0e5SVladimir Oltean struct net_device *dev; 246d3eed0e5SVladimir Oltean unsigned int num; 247857fdd74SVladimir Oltean bool tx_fwd_offload; 248d3eed0e5SVladimir Oltean refcount_t refcount; 249d3eed0e5SVladimir Oltean }; 250f50f2127SFlorian Fainelli 251c8b09808SAndrew Lunn struct dsa_port { 252f8b8b1cdSVivien Didelot /* A CPU port is physically connected to a master device. 253f8b8b1cdSVivien Didelot * A user port exposed to userspace has a slave device. 254f8b8b1cdSVivien Didelot */ 255f8b8b1cdSVivien Didelot union { 256f8b8b1cdSVivien Didelot struct net_device *master; 257f8b8b1cdSVivien Didelot struct net_device *slave; 258f8b8b1cdSVivien Didelot }; 259f8b8b1cdSVivien Didelot 260357f203bSVladimir Oltean /* Copy of the tagging protocol operations, for quicker access 261357f203bSVladimir Oltean * in the data path. Valid only for the CPU ports. 262357f203bSVladimir Oltean */ 26315240248SVivien Didelot const struct dsa_device_ops *tag_ops; 26415240248SVivien Didelot 2653e41f93bSVivien Didelot /* Copies for faster access in master receive hot path */ 2663e41f93bSVivien Didelot struct dsa_switch_tree *dst; 26729a097b7SVladimir Oltean struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev); 2683e41f93bSVivien Didelot 26906251258SVladimir Oltean struct dsa_switch *ds; 27006251258SVladimir Oltean 27106251258SVladimir Oltean unsigned int index; 27206251258SVladimir Oltean 273057cad2cSVivien Didelot enum { 274057cad2cSVivien Didelot DSA_PORT_TYPE_UNUSED = 0, 275057cad2cSVivien Didelot DSA_PORT_TYPE_CPU, 276057cad2cSVivien Didelot DSA_PORT_TYPE_DSA, 277057cad2cSVivien Didelot DSA_PORT_TYPE_USER, 278057cad2cSVivien Didelot } type; 279057cad2cSVivien Didelot 28071e0bbdeSFlorian Fainelli const char *name; 28168b2d4a8SVivien Didelot struct dsa_port *cpu_dp; 28283216e39SMichael Walle u8 mac[ETH_ALEN]; 283b08db33dSVladimir Oltean 284b08db33dSVladimir Oltean u8 stp_state; 285b08db33dSVladimir Oltean 2861b26d364SVladimir Oltean /* Warning: the following bit fields are not atomic, and updating them 2871b26d364SVladimir Oltean * can only be done from code paths where concurrency is not possible 2881b26d364SVladimir Oltean * (probe time or under rtnl_lock). 2891b26d364SVladimir Oltean */ 29063cfc657SVladimir Oltean u8 vlan_filtering:1; 29163cfc657SVladimir Oltean 29263cfc657SVladimir Oltean /* Managed by DSA on user ports and by drivers on CPU and DSA ports */ 29363cfc657SVladimir Oltean u8 learning:1; 29463cfc657SVladimir Oltean 29563cfc657SVladimir Oltean u8 lag_tx_enabled:1; 29663cfc657SVladimir Oltean 29763cfc657SVladimir Oltean u8 devlink_port_setup:1; 29863cfc657SVladimir Oltean 299295ab96fSVladimir Oltean /* Master state bits, valid only on CPU ports */ 300295ab96fSVladimir Oltean u8 master_admin_up:1; 301295ab96fSVladimir Oltean u8 master_oper_up:1; 302295ab96fSVladimir Oltean 30363cfc657SVladimir Oltean u8 setup:1; 304bde82f38SVladimir Oltean 305189b0d93SAndrew Lunn struct device_node *dn; 30634a79f63SVivien Didelot unsigned int ageing_time; 307bde82f38SVladimir Oltean 308d3eed0e5SVladimir Oltean struct dsa_bridge *bridge; 30996567d5dSAndrew Lunn struct devlink_port devlink_port; 310aab9c406SFlorian Fainelli struct phylink *pl; 31144cc27e4SIoana Ciornei struct phylink_config pl_config; 312dedd6a00SVladimir Oltean struct dsa_lag *lag; 31318596f50SGeorge McCollister struct net_device *hsr_dev; 31497a69a0dSVladimir Oltean 315ab8ccae1SVivien Didelot struct list_head list; 316ab8ccae1SVivien Didelot 31767dbb9d4SFlorian Fainelli /* 31867dbb9d4SFlorian Fainelli * Original copy of the master netdev ethtool_ops 31967dbb9d4SFlorian Fainelli */ 32067dbb9d4SFlorian Fainelli const struct ethtool_ops *orig_ethtool_ops; 321da7b9e9bSFlorian Fainelli 322da7b9e9bSFlorian Fainelli /* 323da7b9e9bSFlorian Fainelli * Original copy of the master netdev net_device_ops 324da7b9e9bSFlorian Fainelli */ 3254cfab356SFlorian Fainelli const struct dsa_netdevice_ops *netdev_ops; 326fb35c60cSVivien Didelot 327161ca59dSVladimir Oltean /* List of MAC addresses that must be forwarded on this port. 328161ca59dSVladimir Oltean * These are only valid on CPU ports and DSA links. 329161ca59dSVladimir Oltean */ 330338a3a47SVladimir Oltean struct mutex addr_lists_lock; 3313f6e32f9SVladimir Oltean struct list_head fdbs; 332161ca59dSVladimir Oltean struct list_head mdbs; 333134ef238SVladimir Oltean 334134ef238SVladimir Oltean /* List of VLANs that CPU and DSA ports are members of. */ 335134ef238SVladimir Oltean struct mutex vlans_lock; 336134ef238SVladimir Oltean struct list_head vlans; 337c8b09808SAndrew Lunn }; 338c8b09808SAndrew Lunn 339c5f51765SVivien Didelot /* TODO: ideally DSA ports would have a single dp->link_dp member, 340c5f51765SVivien Didelot * and no dst->rtable nor this struct dsa_link would be needed, 341c5f51765SVivien Didelot * but this would require some more complex tree walking, 342c5f51765SVivien Didelot * so keep it stupid at the moment and list them all. 343c5f51765SVivien Didelot */ 344c5f51765SVivien Didelot struct dsa_link { 345c5f51765SVivien Didelot struct dsa_port *dp; 346c5f51765SVivien Didelot struct dsa_port *link_dp; 347c5f51765SVivien Didelot struct list_head list; 348c5f51765SVivien Didelot }; 349c5f51765SVivien Didelot 350c2693363SVladimir Oltean enum dsa_db_type { 351c2693363SVladimir Oltean DSA_DB_PORT, 352c2693363SVladimir Oltean DSA_DB_LAG, 353c2693363SVladimir Oltean DSA_DB_BRIDGE, 354c2693363SVladimir Oltean }; 355c2693363SVladimir Oltean 356c2693363SVladimir Oltean struct dsa_db { 357c2693363SVladimir Oltean enum dsa_db_type type; 358c2693363SVladimir Oltean 359c2693363SVladimir Oltean union { 360c2693363SVladimir Oltean const struct dsa_port *dp; 361c2693363SVladimir Oltean struct dsa_lag lag; 362c2693363SVladimir Oltean struct dsa_bridge bridge; 363c2693363SVladimir Oltean }; 364c2693363SVladimir Oltean }; 365c2693363SVladimir Oltean 366161ca59dSVladimir Oltean struct dsa_mac_addr { 367161ca59dSVladimir Oltean unsigned char addr[ETH_ALEN]; 368161ca59dSVladimir Oltean u16 vid; 369161ca59dSVladimir Oltean refcount_t refcount; 370161ca59dSVladimir Oltean struct list_head list; 371c2693363SVladimir Oltean struct dsa_db db; 372161ca59dSVladimir Oltean }; 373161ca59dSVladimir Oltean 374134ef238SVladimir Oltean struct dsa_vlan { 375134ef238SVladimir Oltean u16 vid; 376134ef238SVladimir Oltean refcount_t refcount; 377134ef238SVladimir Oltean struct list_head list; 378134ef238SVladimir Oltean }; 379134ef238SVladimir Oltean 380c8f0b869SBen Hutchings struct dsa_switch { 381c33063d6SAndrew Lunn struct device *dev; 382c33063d6SAndrew Lunn 383c8f0b869SBen Hutchings /* 384c8f0b869SBen Hutchings * Parent switch tree, and switch index. 385c8f0b869SBen Hutchings */ 386c8f0b869SBen Hutchings struct dsa_switch_tree *dst; 38799feaafcSVivien Didelot unsigned int index; 388c8f0b869SBen Hutchings 3891b26d364SVladimir Oltean /* Warning: the following bit fields are not atomic, and updating them 3901b26d364SVladimir Oltean * can only be done from code paths where concurrency is not possible 3911b26d364SVladimir Oltean * (probe time or under rtnl_lock). 3921b26d364SVladimir Oltean */ 39363cfc657SVladimir Oltean u32 setup:1; 39463cfc657SVladimir Oltean 39563cfc657SVladimir Oltean /* Disallow bridge core from requesting different VLAN awareness 39663cfc657SVladimir Oltean * settings on ports if not hardware-supported 3977787ff77SVladimir Oltean */ 39863cfc657SVladimir Oltean u32 vlan_filtering_is_global:1; 39963cfc657SVladimir Oltean 40063cfc657SVladimir Oltean /* Keep VLAN filtering enabled on ports not offloading any upper */ 40163cfc657SVladimir Oltean u32 needs_standalone_vlan_filtering:1; 40263cfc657SVladimir Oltean 40363cfc657SVladimir Oltean /* Pass .port_vlan_add and .port_vlan_del to drivers even for bridges 40463cfc657SVladimir Oltean * that have vlan_filtering=0. All drivers should ideally set this (and 40563cfc657SVladimir Oltean * then the option would get removed), but it is unknown whether this 4067787ff77SVladimir Oltean * would break things or not. 4077787ff77SVladimir Oltean */ 40863cfc657SVladimir Oltean u32 configure_vlan_while_not_filtering:1; 40963cfc657SVladimir Oltean 41063cfc657SVladimir Oltean /* If the switch driver always programs the CPU port as egress tagged 41163cfc657SVladimir Oltean * despite the VLAN configuration indicating otherwise, then setting 41263cfc657SVladimir Oltean * @untag_bridge_pvid will force the DSA receive path to pop the 41363cfc657SVladimir Oltean * bridge's default_pvid VLAN tagged frames to offer a consistent 41463cfc657SVladimir Oltean * behavior between a vlan_filtering=0 and vlan_filtering=1 bridge 4157787ff77SVladimir Oltean * device. 4167787ff77SVladimir Oltean */ 41763cfc657SVladimir Oltean u32 untag_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 442f515f192SVivien Didelot /* Listener for switch fabric events */ 443f515f192SVivien Didelot struct notifier_block nb; 444f515f192SVivien Didelot 445c8f0b869SBen Hutchings /* 4467543a6d5SAndrew Lunn * Give the switch driver somewhere to hang its private data 4477543a6d5SAndrew Lunn * structure. 4487543a6d5SAndrew Lunn */ 4497543a6d5SAndrew Lunn void *priv; 4507543a6d5SAndrew Lunn 451dc452a47SVladimir Oltean void *tagger_data; 452dc452a47SVladimir Oltean 4537543a6d5SAndrew Lunn /* 454c8f0b869SBen Hutchings * Configuration data for this switch. 455c8f0b869SBen Hutchings */ 456ff04955cSAndrew Lunn struct dsa_chip_data *cd; 457c8f0b869SBen Hutchings 458c8f0b869SBen Hutchings /* 4599d490b4eSVivien Didelot * The switch operations. 460c8f0b869SBen Hutchings */ 461a82f67afSFlorian Fainelli const struct dsa_switch_ops *ops; 462c8f0b869SBen Hutchings 46366472fc0SAndrew Lunn /* 464c8f0b869SBen Hutchings * Slave mii_bus and devices for the individual ports. 465c8f0b869SBen Hutchings */ 4660d8bcdd3SFlorian Fainelli u32 phys_mii_mask; 467c8f0b869SBen Hutchings struct mii_bus *slave_mii_bus; 468a0c02161SVivien Didelot 4690f3da6afSVivien Didelot /* Ageing Time limits in msecs */ 4700f3da6afSVivien Didelot unsigned int ageing_time_min; 4710f3da6afSVivien Didelot unsigned int ageing_time_max; 4720f3da6afSVivien Didelot 473d7b1fd52SVladimir Oltean /* Storage for drivers using tag_8021q */ 474d7b1fd52SVladimir Oltean struct dsa_8021q_context *tag_8021q_ctx; 475d7b1fd52SVladimir Oltean 47696567d5dSAndrew Lunn /* devlink used to represent this switch device */ 47796567d5dSAndrew Lunn struct devlink *devlink; 47896567d5dSAndrew Lunn 47955199df6SFlorian Fainelli /* Number of switch port queues */ 48055199df6SFlorian Fainelli unsigned int num_tx_queues; 48155199df6SFlorian Fainelli 482058102a6STobias Waldekranz /* Drivers that benefit from having an ID associated with each 483058102a6STobias Waldekranz * offloaded LAG should set this to the maximum number of 484058102a6STobias Waldekranz * supported IDs. DSA will then maintain a mapping of _at 485058102a6STobias Waldekranz * least_ these many IDs, accessible to drivers via 486058102a6STobias Waldekranz * dsa_lag_id(). 487058102a6STobias Waldekranz */ 488058102a6STobias Waldekranz unsigned int num_lag_ids; 489058102a6STobias Waldekranz 490947c8746SVladimir Oltean /* Drivers that support bridge forwarding offload or FDB isolation 491947c8746SVladimir Oltean * should set this to the maximum number of bridges spanning the same 492947c8746SVladimir Oltean * switch tree (or all trees, in the case of cross-tree bridging 493947c8746SVladimir Oltean * support) that can be offloaded. 494123abc06SVladimir Oltean */ 495947c8746SVladimir Oltean unsigned int max_num_bridges; 496123abc06SVladimir Oltean 497258030acSVladimir Oltean unsigned int num_ports; 498c8f0b869SBen Hutchings }; 499c8f0b869SBen Hutchings 50068bb8ea8SVivien Didelot static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p) 501c38c5a66SVivien Didelot { 502b96ddf25SVivien Didelot struct dsa_switch_tree *dst = ds->dst; 503d607525bSVivien Didelot struct dsa_port *dp; 504b96ddf25SVivien Didelot 505b96ddf25SVivien Didelot list_for_each_entry(dp, &dst->ports, list) 506b96ddf25SVivien Didelot if (dp->ds == ds && dp->index == p) 507b96ddf25SVivien Didelot return dp; 508d607525bSVivien Didelot 509d607525bSVivien Didelot return NULL; 510c38c5a66SVivien Didelot } 511c38c5a66SVivien Didelot 512a8986681SVladimir Oltean static inline bool dsa_port_is_dsa(struct dsa_port *port) 513a8986681SVladimir Oltean { 514a8986681SVladimir Oltean return port->type == DSA_PORT_TYPE_DSA; 515a8986681SVladimir Oltean } 516a8986681SVladimir Oltean 517a8986681SVladimir Oltean static inline bool dsa_port_is_cpu(struct dsa_port *port) 518a8986681SVladimir Oltean { 519a8986681SVladimir Oltean return port->type == DSA_PORT_TYPE_CPU; 520a8986681SVladimir Oltean } 521a8986681SVladimir Oltean 522a8986681SVladimir Oltean static inline bool dsa_port_is_user(struct dsa_port *dp) 523a8986681SVladimir Oltean { 524a8986681SVladimir Oltean return dp->type == DSA_PORT_TYPE_USER; 525a8986681SVladimir Oltean } 526a8986681SVladimir Oltean 527a57d8c21SVladimir Oltean static inline bool dsa_port_is_unused(struct dsa_port *dp) 528a57d8c21SVladimir Oltean { 529a57d8c21SVladimir Oltean return dp->type == DSA_PORT_TYPE_UNUSED; 530a57d8c21SVladimir Oltean } 531a57d8c21SVladimir Oltean 532295ab96fSVladimir Oltean static inline bool dsa_port_master_is_operational(struct dsa_port *dp) 533295ab96fSVladimir Oltean { 534295ab96fSVladimir Oltean return dsa_port_is_cpu(dp) && dp->master_admin_up && 535295ab96fSVladimir Oltean dp->master_oper_up; 536295ab96fSVladimir Oltean } 537295ab96fSVladimir Oltean 538bff7b688SVivien Didelot static inline bool dsa_is_unused_port(struct dsa_switch *ds, int p) 539bff7b688SVivien Didelot { 540c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_UNUSED; 541bff7b688SVivien Didelot } 542bff7b688SVivien Didelot 543c8f0b869SBen Hutchings static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p) 544c8f0b869SBen Hutchings { 545c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_CPU; 546c8f0b869SBen Hutchings } 547c8f0b869SBen Hutchings 54860045cbfSAndrew Lunn static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p) 54960045cbfSAndrew Lunn { 550c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_DSA; 55160045cbfSAndrew Lunn } 55260045cbfSAndrew Lunn 5532b3e9891SVivien Didelot static inline bool dsa_is_user_port(struct dsa_switch *ds, int p) 5546cd456f3SVivien Didelot { 555c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_USER; 5566cd456f3SVivien Didelot } 5576cd456f3SVivien Didelot 55882b31898SVladimir Oltean #define dsa_tree_for_each_user_port(_dp, _dst) \ 55982b31898SVladimir Oltean list_for_each_entry((_dp), &(_dst)->ports, list) \ 56082b31898SVladimir Oltean if (dsa_port_is_user((_dp))) 56182b31898SVladimir Oltean 56295f510d0SVladimir Oltean #define dsa_tree_for_each_user_port_continue_reverse(_dp, _dst) \ 56395f510d0SVladimir Oltean list_for_each_entry_continue_reverse((_dp), &(_dst)->ports, list) \ 56495f510d0SVladimir Oltean if (dsa_port_is_user((_dp))) 56595f510d0SVladimir Oltean 5665dc760d1SVladimir Oltean #define dsa_tree_for_each_cpu_port(_dp, _dst) \ 5675dc760d1SVladimir Oltean list_for_each_entry((_dp), &(_dst)->ports, list) \ 5685dc760d1SVladimir Oltean if (dsa_port_is_cpu((_dp))) 5695dc760d1SVladimir Oltean 57082b31898SVladimir Oltean #define dsa_switch_for_each_port(_dp, _ds) \ 57182b31898SVladimir Oltean list_for_each_entry((_dp), &(_ds)->dst->ports, list) \ 57282b31898SVladimir Oltean if ((_dp)->ds == (_ds)) 57382b31898SVladimir Oltean 57482b31898SVladimir Oltean #define dsa_switch_for_each_port_safe(_dp, _next, _ds) \ 57582b31898SVladimir Oltean list_for_each_entry_safe((_dp), (_next), &(_ds)->dst->ports, list) \ 57682b31898SVladimir Oltean if ((_dp)->ds == (_ds)) 57782b31898SVladimir Oltean 57882b31898SVladimir Oltean #define dsa_switch_for_each_port_continue_reverse(_dp, _ds) \ 57982b31898SVladimir Oltean list_for_each_entry_continue_reverse((_dp), &(_ds)->dst->ports, list) \ 58082b31898SVladimir Oltean if ((_dp)->ds == (_ds)) 58182b31898SVladimir Oltean 58282b31898SVladimir Oltean #define dsa_switch_for_each_available_port(_dp, _ds) \ 58382b31898SVladimir Oltean dsa_switch_for_each_port((_dp), (_ds)) \ 58482b31898SVladimir Oltean if (!dsa_port_is_unused((_dp))) 58582b31898SVladimir Oltean 58682b31898SVladimir Oltean #define dsa_switch_for_each_user_port(_dp, _ds) \ 58782b31898SVladimir Oltean dsa_switch_for_each_port((_dp), (_ds)) \ 58882b31898SVladimir Oltean if (dsa_port_is_user((_dp))) 58982b31898SVladimir Oltean 59082b31898SVladimir Oltean #define dsa_switch_for_each_cpu_port(_dp, _ds) \ 59182b31898SVladimir Oltean dsa_switch_for_each_port((_dp), (_ds)) \ 59282b31898SVladimir Oltean if (dsa_port_is_cpu((_dp))) 59382b31898SVladimir Oltean 594bacf93b0SVladimir Oltean #define dsa_switch_for_each_cpu_port_continue_reverse(_dp, _ds) \ 595bacf93b0SVladimir Oltean dsa_switch_for_each_port_continue_reverse((_dp), (_ds)) \ 596bacf93b0SVladimir Oltean if (dsa_port_is_cpu((_dp))) 597bacf93b0SVladimir Oltean 59802bc6e54SVivien Didelot static inline u32 dsa_user_ports(struct dsa_switch *ds) 59902bc6e54SVivien Didelot { 600d0004a02SVladimir Oltean struct dsa_port *dp; 601c38c5a66SVivien Didelot u32 mask = 0; 60202bc6e54SVivien Didelot 603d0004a02SVladimir Oltean dsa_switch_for_each_user_port(dp, ds) 604d0004a02SVladimir Oltean mask |= BIT(dp->index); 605c38c5a66SVivien Didelot 606c38c5a66SVivien Didelot return mask; 607c8652c83SVivien Didelot } 608c8652c83SVivien Didelot 609465c3de4SVladimir Oltean static inline u32 dsa_cpu_ports(struct dsa_switch *ds) 610465c3de4SVladimir Oltean { 611465c3de4SVladimir Oltean struct dsa_port *cpu_dp; 612465c3de4SVladimir Oltean u32 mask = 0; 613465c3de4SVladimir Oltean 614465c3de4SVladimir Oltean dsa_switch_for_each_cpu_port(cpu_dp, ds) 615465c3de4SVladimir Oltean mask |= BIT(cpu_dp->index); 616465c3de4SVladimir Oltean 617465c3de4SVladimir Oltean return mask; 618465c3de4SVladimir Oltean } 619465c3de4SVladimir Oltean 620c5f51765SVivien Didelot /* Return the local port used to reach an arbitrary switch device */ 621c5f51765SVivien Didelot static inline unsigned int dsa_routing_port(struct dsa_switch *ds, int device) 622c5f51765SVivien Didelot { 623c5f51765SVivien Didelot struct dsa_switch_tree *dst = ds->dst; 624c5f51765SVivien Didelot struct dsa_link *dl; 625c5f51765SVivien Didelot 626c5f51765SVivien Didelot list_for_each_entry(dl, &dst->rtable, list) 627c5f51765SVivien Didelot if (dl->dp->ds == ds && dl->link_dp->ds->index == device) 628c5f51765SVivien Didelot return dl->dp->index; 629c5f51765SVivien Didelot 630c5f51765SVivien Didelot return ds->num_ports; 631c5f51765SVivien Didelot } 632c5f51765SVivien Didelot 6333b8fac5dSVivien Didelot /* Return the local port used to reach an arbitrary switch port */ 6343b8fac5dSVivien Didelot static inline unsigned int dsa_towards_port(struct dsa_switch *ds, int device, 6353b8fac5dSVivien Didelot int port) 6363b8fac5dSVivien Didelot { 6373b8fac5dSVivien Didelot if (device == ds->index) 6383b8fac5dSVivien Didelot return port; 6393b8fac5dSVivien Didelot else 640c5f51765SVivien Didelot return dsa_routing_port(ds, device); 6413b8fac5dSVivien Didelot } 6423b8fac5dSVivien Didelot 6433b8fac5dSVivien Didelot /* Return the local port used to reach the dedicated CPU port */ 64407073c79SVivien Didelot static inline unsigned int dsa_upstream_port(struct dsa_switch *ds, int port) 645c8f0b869SBen Hutchings { 64607073c79SVivien Didelot const struct dsa_port *dp = dsa_to_port(ds, port); 64707073c79SVivien Didelot const struct dsa_port *cpu_dp = dp->cpu_dp; 64807073c79SVivien Didelot 64907073c79SVivien Didelot if (!cpu_dp) 65007073c79SVivien Didelot return port; 651c8f0b869SBen Hutchings 6523b8fac5dSVivien Didelot return dsa_towards_port(ds, cpu_dp->ds->index, cpu_dp->index); 653c8f0b869SBen Hutchings } 654c8f0b869SBen Hutchings 65563609c8fSVladimir Oltean /* Return true if this is the local port used to reach the CPU port */ 65663609c8fSVladimir Oltean static inline bool dsa_is_upstream_port(struct dsa_switch *ds, int port) 65763609c8fSVladimir Oltean { 65863609c8fSVladimir Oltean if (dsa_is_unused_port(ds, port)) 65963609c8fSVladimir Oltean return false; 66063609c8fSVladimir Oltean 66163609c8fSVladimir Oltean return port == dsa_upstream_port(ds, port); 66263609c8fSVladimir Oltean } 66363609c8fSVladimir Oltean 664d352b20fSTobias Waldekranz /* Return true if this is a DSA port leading away from the CPU */ 665d352b20fSTobias Waldekranz static inline bool dsa_is_downstream_port(struct dsa_switch *ds, int port) 666d352b20fSTobias Waldekranz { 667d352b20fSTobias Waldekranz return dsa_is_dsa_port(ds, port) && !dsa_is_upstream_port(ds, port); 668d352b20fSTobias Waldekranz } 669d352b20fSTobias Waldekranz 6707af4a361STobias Waldekranz /* Return the local port used to reach the CPU port */ 6717af4a361STobias Waldekranz static inline unsigned int dsa_switch_upstream_port(struct dsa_switch *ds) 6727af4a361STobias Waldekranz { 6737af4a361STobias Waldekranz struct dsa_port *dp; 6747af4a361STobias Waldekranz 6757af4a361STobias Waldekranz dsa_switch_for_each_available_port(dp, ds) { 6767af4a361STobias Waldekranz return dsa_upstream_port(ds, dp->index); 6777af4a361STobias Waldekranz } 6787af4a361STobias Waldekranz 6797af4a361STobias Waldekranz return ds->num_ports; 6807af4a361STobias Waldekranz } 6817af4a361STobias Waldekranz 68263609c8fSVladimir Oltean /* Return true if @upstream_ds is an upstream switch of @downstream_ds, meaning 68363609c8fSVladimir Oltean * that the routing port from @downstream_ds to @upstream_ds is also the port 68463609c8fSVladimir Oltean * which @downstream_ds uses to reach its dedicated CPU. 68563609c8fSVladimir Oltean */ 68663609c8fSVladimir Oltean static inline bool dsa_switch_is_upstream_of(struct dsa_switch *upstream_ds, 68763609c8fSVladimir Oltean struct dsa_switch *downstream_ds) 68863609c8fSVladimir Oltean { 68963609c8fSVladimir Oltean int routing_port; 69063609c8fSVladimir Oltean 69163609c8fSVladimir Oltean if (upstream_ds == downstream_ds) 69263609c8fSVladimir Oltean return true; 69363609c8fSVladimir Oltean 69463609c8fSVladimir Oltean routing_port = dsa_routing_port(downstream_ds, upstream_ds->index); 69563609c8fSVladimir Oltean 69663609c8fSVladimir Oltean return dsa_is_upstream_port(downstream_ds, routing_port); 69763609c8fSVladimir Oltean } 69863609c8fSVladimir Oltean 699cf2d45f5SVladimir Oltean static inline bool dsa_port_is_vlan_filtering(const struct dsa_port *dp) 700cf2d45f5SVladimir Oltean { 701cf2d45f5SVladimir Oltean const struct dsa_switch *ds = dp->ds; 702cf2d45f5SVladimir Oltean 703cf2d45f5SVladimir Oltean if (ds->vlan_filtering_is_global) 704cf2d45f5SVladimir Oltean return ds->vlan_filtering; 705cf2d45f5SVladimir Oltean else 706cf2d45f5SVladimir Oltean return dp->vlan_filtering; 707cf2d45f5SVladimir Oltean } 708cf2d45f5SVladimir Oltean 709dedd6a00SVladimir Oltean static inline unsigned int dsa_port_lag_id_get(struct dsa_port *dp) 710dedd6a00SVladimir Oltean { 711dedd6a00SVladimir Oltean return dp->lag ? dp->lag->id : 0; 712dedd6a00SVladimir Oltean } 713dedd6a00SVladimir Oltean 714dedd6a00SVladimir Oltean static inline struct net_device *dsa_port_lag_dev_get(struct dsa_port *dp) 715dedd6a00SVladimir Oltean { 716dedd6a00SVladimir Oltean return dp->lag ? dp->lag->dev : NULL; 717dedd6a00SVladimir Oltean } 718dedd6a00SVladimir Oltean 719dedd6a00SVladimir Oltean static inline bool dsa_port_offloads_lag(struct dsa_port *dp, 720dedd6a00SVladimir Oltean const struct dsa_lag *lag) 721dedd6a00SVladimir Oltean { 722dedd6a00SVladimir Oltean return dsa_port_lag_dev_get(dp) == lag->dev; 723dedd6a00SVladimir Oltean } 724dedd6a00SVladimir Oltean 7258f6a19c0SVladimir Oltean static inline struct net_device *dsa_port_to_master(const struct dsa_port *dp) 7268f6a19c0SVladimir Oltean { 7278f6a19c0SVladimir Oltean return dp->cpu_dp->master; 7288f6a19c0SVladimir Oltean } 7298f6a19c0SVladimir Oltean 730cc76ce9eSTobias Waldekranz static inline 731cc76ce9eSTobias Waldekranz struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp) 732cc76ce9eSTobias Waldekranz { 733d3eed0e5SVladimir Oltean if (!dp->bridge) 734cc76ce9eSTobias Waldekranz return NULL; 735cc76ce9eSTobias Waldekranz 736dedd6a00SVladimir Oltean if (dp->lag) 737dedd6a00SVladimir Oltean return dp->lag->dev; 738cc76ce9eSTobias Waldekranz else if (dp->hsr_dev) 739cc76ce9eSTobias Waldekranz return dp->hsr_dev; 740cc76ce9eSTobias Waldekranz 741cc76ce9eSTobias Waldekranz return dp->slave; 742cc76ce9eSTobias Waldekranz } 743cc76ce9eSTobias Waldekranz 74436cbf39bSVladimir Oltean static inline struct net_device * 74536cbf39bSVladimir Oltean dsa_port_bridge_dev_get(const struct dsa_port *dp) 74636cbf39bSVladimir Oltean { 747d3eed0e5SVladimir Oltean return dp->bridge ? dp->bridge->dev : NULL; 74836cbf39bSVladimir Oltean } 74936cbf39bSVladimir Oltean 75036cbf39bSVladimir Oltean static inline unsigned int dsa_port_bridge_num_get(struct dsa_port *dp) 75136cbf39bSVladimir Oltean { 752d3eed0e5SVladimir Oltean return dp->bridge ? dp->bridge->num : 0; 75336cbf39bSVladimir Oltean } 75436cbf39bSVladimir Oltean 75536cbf39bSVladimir Oltean static inline bool dsa_port_bridge_same(const struct dsa_port *a, 75636cbf39bSVladimir Oltean const struct dsa_port *b) 75736cbf39bSVladimir Oltean { 75836cbf39bSVladimir Oltean struct net_device *br_a = dsa_port_bridge_dev_get(a); 75936cbf39bSVladimir Oltean struct net_device *br_b = dsa_port_bridge_dev_get(b); 76036cbf39bSVladimir Oltean 76136cbf39bSVladimir Oltean /* Standalone ports are not in the same bridge with one another */ 76236cbf39bSVladimir Oltean return (!br_a || !br_b) ? false : (br_a == br_b); 76336cbf39bSVladimir Oltean } 76436cbf39bSVladimir Oltean 7656a43cba3SVladimir Oltean static inline bool dsa_port_offloads_bridge_port(struct dsa_port *dp, 7666a43cba3SVladimir Oltean const struct net_device *dev) 7676a43cba3SVladimir Oltean { 7686a43cba3SVladimir Oltean return dsa_port_to_bridge_port(dp) == dev; 7696a43cba3SVladimir Oltean } 7706a43cba3SVladimir Oltean 7716a43cba3SVladimir Oltean static inline bool 7726a43cba3SVladimir Oltean dsa_port_offloads_bridge_dev(struct dsa_port *dp, 7736a43cba3SVladimir Oltean const struct net_device *bridge_dev) 7746a43cba3SVladimir Oltean { 7756a43cba3SVladimir Oltean /* DSA ports connected to a bridge, and event was emitted 7766a43cba3SVladimir Oltean * for the bridge. 7776a43cba3SVladimir Oltean */ 7786a43cba3SVladimir Oltean return dsa_port_bridge_dev_get(dp) == bridge_dev; 7796a43cba3SVladimir Oltean } 7806a43cba3SVladimir Oltean 781d3eed0e5SVladimir Oltean static inline bool dsa_port_offloads_bridge(struct dsa_port *dp, 782d3eed0e5SVladimir Oltean const struct dsa_bridge *bridge) 783d3eed0e5SVladimir Oltean { 784d3eed0e5SVladimir Oltean return dsa_port_bridge_dev_get(dp) == bridge->dev; 785d3eed0e5SVladimir Oltean } 786d3eed0e5SVladimir Oltean 7876a43cba3SVladimir Oltean /* Returns true if any port of this tree offloads the given net_device */ 7886a43cba3SVladimir Oltean static inline bool dsa_tree_offloads_bridge_port(struct dsa_switch_tree *dst, 7896a43cba3SVladimir Oltean const struct net_device *dev) 7906a43cba3SVladimir Oltean { 7916a43cba3SVladimir Oltean struct dsa_port *dp; 7926a43cba3SVladimir Oltean 7936a43cba3SVladimir Oltean list_for_each_entry(dp, &dst->ports, list) 7946a43cba3SVladimir Oltean if (dsa_port_offloads_bridge_port(dp, dev)) 7956a43cba3SVladimir Oltean return true; 7966a43cba3SVladimir Oltean 7976a43cba3SVladimir Oltean return false; 7986a43cba3SVladimir Oltean } 7996a43cba3SVladimir Oltean 8006a43cba3SVladimir Oltean /* Returns true if any port of this tree offloads the given bridge */ 8016a43cba3SVladimir Oltean static inline bool 8026a43cba3SVladimir Oltean dsa_tree_offloads_bridge_dev(struct dsa_switch_tree *dst, 8036a43cba3SVladimir Oltean const struct net_device *bridge_dev) 8046a43cba3SVladimir Oltean { 8056a43cba3SVladimir Oltean struct dsa_port *dp; 8066a43cba3SVladimir Oltean 8076a43cba3SVladimir Oltean list_for_each_entry(dp, &dst->ports, list) 8086a43cba3SVladimir Oltean if (dsa_port_offloads_bridge_dev(dp, bridge_dev)) 8096a43cba3SVladimir Oltean return true; 8106a43cba3SVladimir Oltean 8116a43cba3SVladimir Oltean return false; 8126a43cba3SVladimir Oltean } 8136a43cba3SVladimir Oltean 8142bedde1aSArkadi Sharshevsky typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid, 8152bedde1aSArkadi Sharshevsky bool is_static, void *data); 8169d490b4eSVivien Didelot struct dsa_switch_ops { 81753da0ebaSVladimir Oltean /* 81853da0ebaSVladimir Oltean * Tagging protocol helpers called for the CPU ports and DSA links. 81953da0ebaSVladimir Oltean * @get_tag_protocol retrieves the initial tagging protocol and is 82053da0ebaSVladimir Oltean * mandatory. Switches which can operate using multiple tagging 82153da0ebaSVladimir Oltean * protocols should implement @change_tag_protocol and report in 82253da0ebaSVladimir Oltean * @get_tag_protocol the tagger in current use. 82353da0ebaSVladimir Oltean */ 8245ed4e3ebSFlorian Fainelli enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds, 8254d776482SFlorian Fainelli int port, 8264d776482SFlorian Fainelli enum dsa_tag_protocol mprot); 827bacf93b0SVladimir Oltean int (*change_tag_protocol)(struct dsa_switch *ds, 82853da0ebaSVladimir Oltean enum dsa_tag_protocol proto); 829dc452a47SVladimir Oltean /* 830dc452a47SVladimir Oltean * Method for switch drivers to connect to the tagging protocol driver 831dc452a47SVladimir Oltean * in current use. The switch driver can provide handlers for certain 832dc452a47SVladimir Oltean * types of packets for switch management. 833dc452a47SVladimir Oltean */ 834dc452a47SVladimir Oltean int (*connect_tag_protocol)(struct dsa_switch *ds, 835dc452a47SVladimir Oltean enum dsa_tag_protocol proto); 8367b314362SAndrew Lunn 83795f510d0SVladimir Oltean int (*port_change_master)(struct dsa_switch *ds, int port, 83895f510d0SVladimir Oltean struct net_device *master, 83995f510d0SVladimir Oltean struct netlink_ext_ack *extack); 84095f510d0SVladimir Oltean 841fd292c18SVladimir Oltean /* Optional switch-wide initialization and destruction methods */ 842c8f0b869SBen Hutchings int (*setup)(struct dsa_switch *ds); 8435e3f847aSVladimir Oltean void (*teardown)(struct dsa_switch *ds); 844fd292c18SVladimir Oltean 845fd292c18SVladimir Oltean /* Per-port initialization and destruction methods. Mandatory if the 846fd292c18SVladimir Oltean * driver registers devlink port regions, optional otherwise. 847fd292c18SVladimir Oltean */ 848fd292c18SVladimir Oltean int (*port_setup)(struct dsa_switch *ds, int port); 849fd292c18SVladimir Oltean void (*port_teardown)(struct dsa_switch *ds, int port); 850fd292c18SVladimir Oltean 8516819563eSFlorian Fainelli u32 (*get_phy_flags)(struct dsa_switch *ds, int port); 852c8f0b869SBen Hutchings 853c8f0b869SBen Hutchings /* 854c8f0b869SBen Hutchings * Access to the switch's PHY registers. 855c8f0b869SBen Hutchings */ 856c8f0b869SBen Hutchings int (*phy_read)(struct dsa_switch *ds, int port, int regnum); 857c8f0b869SBen Hutchings int (*phy_write)(struct dsa_switch *ds, int port, 858c8f0b869SBen Hutchings int regnum, u16 val); 859c8f0b869SBen Hutchings 860c8f0b869SBen Hutchings /* 861ec9436baSFlorian Fainelli * Link state adjustment (called from libphy) 862ec9436baSFlorian Fainelli */ 863ec9436baSFlorian Fainelli void (*adjust_link)(struct dsa_switch *ds, int port, 864ec9436baSFlorian Fainelli struct phy_device *phydev); 865ce31b31cSFlorian Fainelli void (*fixed_link_update)(struct dsa_switch *ds, int port, 866ce31b31cSFlorian Fainelli struct fixed_phy_status *st); 867ec9436baSFlorian Fainelli 868ec9436baSFlorian Fainelli /* 86911d8f3ddSFlorian Fainelli * PHYLINK integration 87011d8f3ddSFlorian Fainelli */ 871072eea6cSRussell King (Oracle) void (*phylink_get_caps)(struct dsa_switch *ds, int port, 872072eea6cSRussell King (Oracle) struct phylink_config *config); 87311d8f3ddSFlorian Fainelli void (*phylink_validate)(struct dsa_switch *ds, int port, 87411d8f3ddSFlorian Fainelli unsigned long *supported, 87511d8f3ddSFlorian Fainelli struct phylink_link_state *state); 876bde01822SRussell King (Oracle) struct phylink_pcs *(*phylink_mac_select_pcs)(struct dsa_switch *ds, 877bde01822SRussell King (Oracle) int port, 878bde01822SRussell King (Oracle) phy_interface_t iface); 87911d8f3ddSFlorian Fainelli int (*phylink_mac_link_state)(struct dsa_switch *ds, int port, 88011d8f3ddSFlorian Fainelli struct phylink_link_state *state); 88111d8f3ddSFlorian Fainelli void (*phylink_mac_config)(struct dsa_switch *ds, int port, 88211d8f3ddSFlorian Fainelli unsigned int mode, 88311d8f3ddSFlorian Fainelli const struct phylink_link_state *state); 88411d8f3ddSFlorian Fainelli void (*phylink_mac_an_restart)(struct dsa_switch *ds, int port); 88511d8f3ddSFlorian Fainelli void (*phylink_mac_link_down)(struct dsa_switch *ds, int port, 88611d8f3ddSFlorian Fainelli unsigned int mode, 88711d8f3ddSFlorian Fainelli phy_interface_t interface); 88811d8f3ddSFlorian Fainelli void (*phylink_mac_link_up)(struct dsa_switch *ds, int port, 88911d8f3ddSFlorian Fainelli unsigned int mode, 89011d8f3ddSFlorian Fainelli phy_interface_t interface, 8915b502a7bSRussell King struct phy_device *phydev, 8925b502a7bSRussell King int speed, int duplex, 8935b502a7bSRussell King bool tx_pause, bool rx_pause); 89411d8f3ddSFlorian Fainelli void (*phylink_fixed_state)(struct dsa_switch *ds, int port, 89511d8f3ddSFlorian Fainelli struct phylink_link_state *state); 89611d8f3ddSFlorian Fainelli /* 897c2ec5f2eSOleksij Rempel * Port statistics counters. 898c8f0b869SBen Hutchings */ 89989f09048SFlorian Fainelli void (*get_strings)(struct dsa_switch *ds, int port, 90089f09048SFlorian Fainelli u32 stringset, uint8_t *data); 901c8f0b869SBen Hutchings void (*get_ethtool_stats)(struct dsa_switch *ds, 902c8f0b869SBen Hutchings int port, uint64_t *data); 90389f09048SFlorian Fainelli int (*get_sset_count)(struct dsa_switch *ds, int port, int sset); 904cf963573SFlorian Fainelli void (*get_ethtool_phy_stats)(struct dsa_switch *ds, 905cf963573SFlorian Fainelli int port, uint64_t *data); 906487d3855SAlvin Šipraga void (*get_eth_phy_stats)(struct dsa_switch *ds, int port, 907487d3855SAlvin Šipraga struct ethtool_eth_phy_stats *phy_stats); 908487d3855SAlvin Šipraga void (*get_eth_mac_stats)(struct dsa_switch *ds, int port, 909487d3855SAlvin Šipraga struct ethtool_eth_mac_stats *mac_stats); 910487d3855SAlvin Šipraga void (*get_eth_ctrl_stats)(struct dsa_switch *ds, int port, 911487d3855SAlvin Šipraga struct ethtool_eth_ctrl_stats *ctrl_stats); 91267f38b1cSClément Léger void (*get_rmon_stats)(struct dsa_switch *ds, int port, 91367f38b1cSClément Léger struct ethtool_rmon_stats *rmon_stats, 91467f38b1cSClément Léger const struct ethtool_rmon_hist_range **ranges); 915c2ec5f2eSOleksij Rempel void (*get_stats64)(struct dsa_switch *ds, int port, 916c2ec5f2eSOleksij Rempel struct rtnl_link_stats64 *s); 9173d410403SOleksij Rempel void (*get_pause_stats)(struct dsa_switch *ds, int port, 9183d410403SOleksij Rempel struct ethtool_pause_stats *pause_stats); 919a71acad9SOleksij Rempel void (*self_test)(struct dsa_switch *ds, int port, 920a71acad9SOleksij Rempel struct ethtool_test *etest, u64 *data); 92124462549SFlorian Fainelli 92224462549SFlorian Fainelli /* 92319e57c4eSFlorian Fainelli * ethtool Wake-on-LAN 92419e57c4eSFlorian Fainelli */ 92519e57c4eSFlorian Fainelli void (*get_wol)(struct dsa_switch *ds, int port, 92619e57c4eSFlorian Fainelli struct ethtool_wolinfo *w); 92719e57c4eSFlorian Fainelli int (*set_wol)(struct dsa_switch *ds, int port, 92819e57c4eSFlorian Fainelli struct ethtool_wolinfo *w); 92919e57c4eSFlorian Fainelli 93019e57c4eSFlorian Fainelli /* 9310336369dSBrandon Streiff * ethtool timestamp info 9320336369dSBrandon Streiff */ 9330336369dSBrandon Streiff int (*get_ts_info)(struct dsa_switch *ds, int port, 9340336369dSBrandon Streiff struct ethtool_ts_info *ts); 9350336369dSBrandon Streiff 9360336369dSBrandon Streiff /* 937d538eca8SVladimir Oltean * DCB ops 938d538eca8SVladimir Oltean */ 939d538eca8SVladimir Oltean int (*port_get_default_prio)(struct dsa_switch *ds, int port); 940d538eca8SVladimir Oltean int (*port_set_default_prio)(struct dsa_switch *ds, int port, 941d538eca8SVladimir Oltean u8 prio); 94247d75f78SVladimir Oltean int (*port_get_dscp_prio)(struct dsa_switch *ds, int port, u8 dscp); 94347d75f78SVladimir Oltean int (*port_add_dscp_prio)(struct dsa_switch *ds, int port, u8 dscp, 94447d75f78SVladimir Oltean u8 prio); 94547d75f78SVladimir Oltean int (*port_del_dscp_prio)(struct dsa_switch *ds, int port, u8 dscp, 94647d75f78SVladimir Oltean u8 prio); 947d538eca8SVladimir Oltean 948d538eca8SVladimir Oltean /* 94924462549SFlorian Fainelli * Suspend and resume 95024462549SFlorian Fainelli */ 95124462549SFlorian Fainelli int (*suspend)(struct dsa_switch *ds); 95224462549SFlorian Fainelli int (*resume)(struct dsa_switch *ds); 953b2f2af21SFlorian Fainelli 954b2f2af21SFlorian Fainelli /* 955b2f2af21SFlorian Fainelli * Port enable/disable 956b2f2af21SFlorian Fainelli */ 957b2f2af21SFlorian Fainelli int (*port_enable)(struct dsa_switch *ds, int port, 958b2f2af21SFlorian Fainelli struct phy_device *phy); 95975104db0SAndrew Lunn void (*port_disable)(struct dsa_switch *ds, int port); 9607905288fSFlorian Fainelli 9617905288fSFlorian Fainelli /* 96208f50061SVivien Didelot * Port's MAC EEE settings 9637905288fSFlorian Fainelli */ 96408f50061SVivien Didelot int (*set_mac_eee)(struct dsa_switch *ds, int port, 9657905288fSFlorian Fainelli struct ethtool_eee *e); 96608f50061SVivien Didelot int (*get_mac_eee)(struct dsa_switch *ds, int port, 9677905288fSFlorian Fainelli struct ethtool_eee *e); 96851579c3fSGuenter Roeck 9696793abb4SGuenter Roeck /* EEPROM access */ 9706793abb4SGuenter Roeck int (*get_eeprom_len)(struct dsa_switch *ds); 9716793abb4SGuenter Roeck int (*get_eeprom)(struct dsa_switch *ds, 9726793abb4SGuenter Roeck struct ethtool_eeprom *eeprom, u8 *data); 9736793abb4SGuenter Roeck int (*set_eeprom)(struct dsa_switch *ds, 9746793abb4SGuenter Roeck struct ethtool_eeprom *eeprom, u8 *data); 9753d762a0fSGuenter Roeck 9763d762a0fSGuenter Roeck /* 9773d762a0fSGuenter Roeck * Register access. 9783d762a0fSGuenter Roeck */ 9793d762a0fSGuenter Roeck int (*get_regs_len)(struct dsa_switch *ds, int port); 9803d762a0fSGuenter Roeck void (*get_regs)(struct dsa_switch *ds, int port, 9813d762a0fSGuenter Roeck struct ethtool_regs *regs, void *p); 982b73adef6SFlorian Fainelli 983b73adef6SFlorian Fainelli /* 984e358bef7SVladimir Oltean * Upper device tracking. 985e358bef7SVladimir Oltean */ 986e358bef7SVladimir Oltean int (*port_prechangeupper)(struct dsa_switch *ds, int port, 987e358bef7SVladimir Oltean struct netdev_notifier_changeupper_info *info); 988e358bef7SVladimir Oltean 989e358bef7SVladimir Oltean /* 990b73adef6SFlorian Fainelli * Bridge integration 991b73adef6SFlorian Fainelli */ 99234a79f63SVivien Didelot int (*set_ageing_time)(struct dsa_switch *ds, unsigned int msecs); 99371327a4eSVivien Didelot int (*port_bridge_join)(struct dsa_switch *ds, int port, 994b079922bSVladimir Oltean struct dsa_bridge bridge, 99506b9cce4SVladimir Oltean bool *tx_fwd_offload, 99606b9cce4SVladimir Oltean struct netlink_ext_ack *extack); 997f123f2fbSVivien Didelot void (*port_bridge_leave)(struct dsa_switch *ds, int port, 998d3eed0e5SVladimir Oltean struct dsa_bridge bridge); 99943c44a9fSVivien Didelot void (*port_stp_state_set)(struct dsa_switch *ds, int port, 1000b73adef6SFlorian Fainelli u8 state); 10017414af30STobias Waldekranz int (*port_mst_state_set)(struct dsa_switch *ds, int port, 10027414af30STobias Waldekranz const struct switchdev_mst_state *state); 1003732f794cSVivien Didelot void (*port_fast_age)(struct dsa_switch *ds, int port); 10047414af30STobias Waldekranz int (*port_vlan_fast_age)(struct dsa_switch *ds, int port, u16 vid); 1005a8b659e7SVladimir Oltean int (*port_pre_bridge_flags)(struct dsa_switch *ds, int port, 1006a8b659e7SVladimir Oltean struct switchdev_brport_flags flags, 1007a8b659e7SVladimir Oltean struct netlink_ext_ack *extack); 1008a8b659e7SVladimir Oltean int (*port_bridge_flags)(struct dsa_switch *ds, int port, 1009a8b659e7SVladimir Oltean struct switchdev_brport_flags flags, 1010a8b659e7SVladimir Oltean struct netlink_ext_ack *extack); 101172c3b0c7SVladimir Oltean void (*port_set_host_flood)(struct dsa_switch *ds, int port, 101272c3b0c7SVladimir Oltean bool uc, bool mc); 10132a778e1bSVivien Didelot 10142a778e1bSVivien Didelot /* 101511149536SVivien Didelot * VLAN support 101611149536SVivien Didelot */ 1017fb2dabadSVivien Didelot int (*port_vlan_filtering)(struct dsa_switch *ds, int port, 101889153ed6SVladimir Oltean bool vlan_filtering, 101989153ed6SVladimir Oltean struct netlink_ext_ack *extack); 10201958d581SVladimir Oltean int (*port_vlan_add)(struct dsa_switch *ds, int port, 102131046a5fSVladimir Oltean const struct switchdev_obj_port_vlan *vlan, 102231046a5fSVladimir Oltean struct netlink_ext_ack *extack); 102376e398a6SVivien Didelot int (*port_vlan_del)(struct dsa_switch *ds, int port, 102476e398a6SVivien Didelot const struct switchdev_obj_port_vlan *vlan); 10258e6598a7STobias Waldekranz int (*vlan_msti_set)(struct dsa_switch *ds, struct dsa_bridge bridge, 10268e6598a7STobias Waldekranz const struct switchdev_vlan_msti *msti); 10278e6598a7STobias Waldekranz 102811149536SVivien Didelot /* 10292a778e1bSVivien Didelot * Forwarding database 10302a778e1bSVivien Didelot */ 10311b6dd556SArkadi Sharshevsky int (*port_fdb_add)(struct dsa_switch *ds, int port, 1032c2693363SVladimir Oltean const unsigned char *addr, u16 vid, 1033c2693363SVladimir Oltean struct dsa_db db); 10342a778e1bSVivien Didelot int (*port_fdb_del)(struct dsa_switch *ds, int port, 1035c2693363SVladimir Oltean const unsigned char *addr, u16 vid, 1036c2693363SVladimir Oltean struct dsa_db db); 1037ea70ba98SVivien Didelot int (*port_fdb_dump)(struct dsa_switch *ds, int port, 10382bedde1aSArkadi Sharshevsky dsa_fdb_dump_cb_t *cb, void *data); 1039e212fa7cSVladimir Oltean int (*lag_fdb_add)(struct dsa_switch *ds, struct dsa_lag lag, 1040c2693363SVladimir Oltean const unsigned char *addr, u16 vid, 1041c2693363SVladimir Oltean struct dsa_db db); 1042e212fa7cSVladimir Oltean int (*lag_fdb_del)(struct dsa_switch *ds, struct dsa_lag lag, 1043c2693363SVladimir Oltean const unsigned char *addr, u16 vid, 1044c2693363SVladimir Oltean struct dsa_db db); 10458df30255SVivien Didelot 10468df30255SVivien Didelot /* 10478df30255SVivien Didelot * Multicast database 10488df30255SVivien Didelot */ 1049a52b2da7SVladimir Oltean int (*port_mdb_add)(struct dsa_switch *ds, int port, 1050c2693363SVladimir Oltean const struct switchdev_obj_port_mdb *mdb, 1051c2693363SVladimir Oltean struct dsa_db db); 10528df30255SVivien Didelot int (*port_mdb_del)(struct dsa_switch *ds, int port, 1053c2693363SVladimir Oltean const struct switchdev_obj_port_mdb *mdb, 1054c2693363SVladimir Oltean struct dsa_db db); 1055bf9f2648SFlorian Fainelli /* 1056bf9f2648SFlorian Fainelli * RXNFC 1057bf9f2648SFlorian Fainelli */ 1058bf9f2648SFlorian Fainelli int (*get_rxnfc)(struct dsa_switch *ds, int port, 1059bf9f2648SFlorian Fainelli struct ethtool_rxnfc *nfc, u32 *rule_locs); 1060bf9f2648SFlorian Fainelli int (*set_rxnfc)(struct dsa_switch *ds, int port, 1061bf9f2648SFlorian Fainelli struct ethtool_rxnfc *nfc); 1062f50f2127SFlorian Fainelli 1063f50f2127SFlorian Fainelli /* 1064f50f2127SFlorian Fainelli * TC integration 1065f50f2127SFlorian Fainelli */ 1066ed11bb1fSVladimir Oltean int (*cls_flower_add)(struct dsa_switch *ds, int port, 1067ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, bool ingress); 1068ed11bb1fSVladimir Oltean int (*cls_flower_del)(struct dsa_switch *ds, int port, 1069ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, bool ingress); 1070ed11bb1fSVladimir Oltean int (*cls_flower_stats)(struct dsa_switch *ds, int port, 1071ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, bool ingress); 1072f50f2127SFlorian Fainelli int (*port_mirror_add)(struct dsa_switch *ds, int port, 1073f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror, 10740148bb50SVladimir Oltean bool ingress, struct netlink_ext_ack *extack); 1075f50f2127SFlorian Fainelli void (*port_mirror_del)(struct dsa_switch *ds, int port, 1076f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror); 107734297176SVladimir Oltean int (*port_policer_add)(struct dsa_switch *ds, int port, 107834297176SVladimir Oltean struct dsa_mall_policer_tc_entry *policer); 107934297176SVladimir Oltean void (*port_policer_del)(struct dsa_switch *ds, int port); 108047d23af2SVladimir Oltean int (*port_setup_tc)(struct dsa_switch *ds, int port, 108147d23af2SVladimir Oltean enum tc_setup_type type, void *type_data); 108240ef2c93SVivien Didelot 108340ef2c93SVivien Didelot /* 108440ef2c93SVivien Didelot * Cross-chip operations 108540ef2c93SVivien Didelot */ 1086f66a6a69SVladimir Oltean int (*crosschip_bridge_join)(struct dsa_switch *ds, int tree_index, 1087f66a6a69SVladimir Oltean int sw_index, int port, 108806b9cce4SVladimir Oltean struct dsa_bridge bridge, 108906b9cce4SVladimir Oltean struct netlink_ext_ack *extack); 1090f66a6a69SVladimir Oltean void (*crosschip_bridge_leave)(struct dsa_switch *ds, int tree_index, 1091f66a6a69SVladimir Oltean int sw_index, int port, 1092d3eed0e5SVladimir Oltean struct dsa_bridge bridge); 1093058102a6STobias Waldekranz int (*crosschip_lag_change)(struct dsa_switch *ds, int sw_index, 1094058102a6STobias Waldekranz int port); 1095058102a6STobias Waldekranz int (*crosschip_lag_join)(struct dsa_switch *ds, int sw_index, 1096dedd6a00SVladimir Oltean int port, struct dsa_lag lag, 1097*2e359b00SVladimir Oltean struct netdev_lag_upper_info *info, 1098*2e359b00SVladimir Oltean struct netlink_ext_ack *extack); 1099058102a6STobias Waldekranz int (*crosschip_lag_leave)(struct dsa_switch *ds, int sw_index, 1100dedd6a00SVladimir Oltean int port, struct dsa_lag lag); 11010336369dSBrandon Streiff 11020336369dSBrandon Streiff /* 11030336369dSBrandon Streiff * PTP functionality 11040336369dSBrandon Streiff */ 11050336369dSBrandon Streiff int (*port_hwtstamp_get)(struct dsa_switch *ds, int port, 11060336369dSBrandon Streiff struct ifreq *ifr); 11070336369dSBrandon Streiff int (*port_hwtstamp_set)(struct dsa_switch *ds, int port, 11080336369dSBrandon Streiff struct ifreq *ifr); 11095c5416f5SYangbo Lu void (*port_txtstamp)(struct dsa_switch *ds, int port, 11105c5416f5SYangbo Lu struct sk_buff *skb); 111190af1059SBrandon Streiff bool (*port_rxtstamp)(struct dsa_switch *ds, int port, 111290af1059SBrandon Streiff struct sk_buff *skb, unsigned int type); 111397a69a0dSVladimir Oltean 11140f06b855SAndrew Lunn /* Devlink parameters, etc */ 11156b297524SAndrew Lunn int (*devlink_param_get)(struct dsa_switch *ds, u32 id, 11166b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx); 11176b297524SAndrew Lunn int (*devlink_param_set)(struct dsa_switch *ds, u32 id, 11186b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx); 11190f06b855SAndrew Lunn int (*devlink_info_get)(struct dsa_switch *ds, 11200f06b855SAndrew Lunn struct devlink_info_req *req, 11210f06b855SAndrew Lunn struct netlink_ext_ack *extack); 11222a6ef763SVladimir Oltean int (*devlink_sb_pool_get)(struct dsa_switch *ds, 11232a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index, 11242a6ef763SVladimir Oltean struct devlink_sb_pool_info *pool_info); 11252a6ef763SVladimir Oltean int (*devlink_sb_pool_set)(struct dsa_switch *ds, unsigned int sb_index, 11262a6ef763SVladimir Oltean u16 pool_index, u32 size, 11272a6ef763SVladimir Oltean enum devlink_sb_threshold_type threshold_type, 11282a6ef763SVladimir Oltean struct netlink_ext_ack *extack); 11292a6ef763SVladimir Oltean int (*devlink_sb_port_pool_get)(struct dsa_switch *ds, int port, 11302a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index, 11312a6ef763SVladimir Oltean u32 *p_threshold); 11322a6ef763SVladimir Oltean int (*devlink_sb_port_pool_set)(struct dsa_switch *ds, int port, 11332a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index, 11342a6ef763SVladimir Oltean u32 threshold, 11352a6ef763SVladimir Oltean struct netlink_ext_ack *extack); 11362a6ef763SVladimir Oltean int (*devlink_sb_tc_pool_bind_get)(struct dsa_switch *ds, int port, 11372a6ef763SVladimir Oltean unsigned int sb_index, u16 tc_index, 11382a6ef763SVladimir Oltean enum devlink_sb_pool_type pool_type, 11392a6ef763SVladimir Oltean u16 *p_pool_index, u32 *p_threshold); 11402a6ef763SVladimir Oltean int (*devlink_sb_tc_pool_bind_set)(struct dsa_switch *ds, int port, 11412a6ef763SVladimir Oltean unsigned int sb_index, u16 tc_index, 11422a6ef763SVladimir Oltean enum devlink_sb_pool_type pool_type, 11432a6ef763SVladimir Oltean u16 pool_index, u32 threshold, 11442a6ef763SVladimir Oltean struct netlink_ext_ack *extack); 11452a6ef763SVladimir Oltean int (*devlink_sb_occ_snapshot)(struct dsa_switch *ds, 11462a6ef763SVladimir Oltean unsigned int sb_index); 11472a6ef763SVladimir Oltean int (*devlink_sb_occ_max_clear)(struct dsa_switch *ds, 11482a6ef763SVladimir Oltean unsigned int sb_index); 11492a6ef763SVladimir Oltean int (*devlink_sb_occ_port_pool_get)(struct dsa_switch *ds, int port, 11502a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index, 11512a6ef763SVladimir Oltean u32 *p_cur, u32 *p_max); 11522a6ef763SVladimir Oltean int (*devlink_sb_occ_tc_port_bind_get)(struct dsa_switch *ds, int port, 11532a6ef763SVladimir Oltean unsigned int sb_index, u16 tc_index, 11542a6ef763SVladimir Oltean enum devlink_sb_pool_type pool_type, 11552a6ef763SVladimir Oltean u32 *p_cur, u32 *p_max); 1156bfcb8132SVladimir Oltean 1157bfcb8132SVladimir Oltean /* 1158bfcb8132SVladimir Oltean * MTU change functionality. Switches can also adjust their MRU through 1159bfcb8132SVladimir Oltean * this method. By MTU, one understands the SDU (L2 payload) length. 1160bfcb8132SVladimir Oltean * If the switch needs to account for the DSA tag on the CPU port, this 1161ab88d64aSRandy Dunlap * method needs to do so privately. 1162bfcb8132SVladimir Oltean */ 1163bfcb8132SVladimir Oltean int (*port_change_mtu)(struct dsa_switch *ds, int port, 1164bfcb8132SVladimir Oltean int new_mtu); 1165bfcb8132SVladimir Oltean int (*port_max_mtu)(struct dsa_switch *ds, int port); 1166058102a6STobias Waldekranz 1167058102a6STobias Waldekranz /* 1168058102a6STobias Waldekranz * LAG integration 1169058102a6STobias Waldekranz */ 1170058102a6STobias Waldekranz int (*port_lag_change)(struct dsa_switch *ds, int port); 1171058102a6STobias Waldekranz int (*port_lag_join)(struct dsa_switch *ds, int port, 1172dedd6a00SVladimir Oltean struct dsa_lag lag, 1173*2e359b00SVladimir Oltean struct netdev_lag_upper_info *info, 1174*2e359b00SVladimir Oltean struct netlink_ext_ack *extack); 1175058102a6STobias Waldekranz int (*port_lag_leave)(struct dsa_switch *ds, int port, 1176dedd6a00SVladimir Oltean struct dsa_lag lag); 117718596f50SGeorge McCollister 117818596f50SGeorge McCollister /* 117918596f50SGeorge McCollister * HSR integration 118018596f50SGeorge McCollister */ 118118596f50SGeorge McCollister int (*port_hsr_join)(struct dsa_switch *ds, int port, 118218596f50SGeorge McCollister struct net_device *hsr); 118318596f50SGeorge McCollister int (*port_hsr_leave)(struct dsa_switch *ds, int port, 118418596f50SGeorge McCollister struct net_device *hsr); 1185c595c433SHoratiu Vultur 1186c595c433SHoratiu Vultur /* 1187c595c433SHoratiu Vultur * MRP integration 1188c595c433SHoratiu Vultur */ 1189c595c433SHoratiu Vultur int (*port_mrp_add)(struct dsa_switch *ds, int port, 1190c595c433SHoratiu Vultur const struct switchdev_obj_mrp *mrp); 1191c595c433SHoratiu Vultur int (*port_mrp_del)(struct dsa_switch *ds, int port, 1192c595c433SHoratiu Vultur const struct switchdev_obj_mrp *mrp); 1193c595c433SHoratiu Vultur int (*port_mrp_add_ring_role)(struct dsa_switch *ds, int port, 1194c595c433SHoratiu Vultur const struct switchdev_obj_ring_role_mrp *mrp); 1195c595c433SHoratiu Vultur int (*port_mrp_del_ring_role)(struct dsa_switch *ds, int port, 1196c595c433SHoratiu Vultur const struct switchdev_obj_ring_role_mrp *mrp); 11975da11eb4SVladimir Oltean 11985da11eb4SVladimir Oltean /* 11995da11eb4SVladimir Oltean * tag_8021q operations 12005da11eb4SVladimir Oltean */ 12015da11eb4SVladimir Oltean int (*tag_8021q_vlan_add)(struct dsa_switch *ds, int port, u16 vid, 12025da11eb4SVladimir Oltean u16 flags); 12035da11eb4SVladimir Oltean int (*tag_8021q_vlan_del)(struct dsa_switch *ds, int port, u16 vid); 1204295ab96fSVladimir Oltean 1205295ab96fSVladimir Oltean /* 1206295ab96fSVladimir Oltean * DSA master tracking operations 1207295ab96fSVladimir Oltean */ 1208295ab96fSVladimir Oltean void (*master_state_change)(struct dsa_switch *ds, 1209295ab96fSVladimir Oltean const struct net_device *master, 1210295ab96fSVladimir Oltean bool operational); 12116b297524SAndrew Lunn }; 12126b297524SAndrew Lunn 12136b297524SAndrew Lunn #define DSA_DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes) \ 12146b297524SAndrew Lunn DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, \ 12156b297524SAndrew Lunn dsa_devlink_param_get, dsa_devlink_param_set, NULL) 12166b297524SAndrew Lunn 12176b297524SAndrew Lunn int dsa_devlink_param_get(struct devlink *dl, u32 id, 12186b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx); 12196b297524SAndrew Lunn int dsa_devlink_param_set(struct devlink *dl, u32 id, 12206b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx); 12216b297524SAndrew Lunn int dsa_devlink_params_register(struct dsa_switch *ds, 12226b297524SAndrew Lunn const struct devlink_param *params, 12236b297524SAndrew Lunn size_t params_count); 12246b297524SAndrew Lunn void dsa_devlink_params_unregister(struct dsa_switch *ds, 12256b297524SAndrew Lunn const struct devlink_param *params, 12266b297524SAndrew Lunn size_t params_count); 12275cd73fbdSAndrew Lunn int dsa_devlink_resource_register(struct dsa_switch *ds, 12285cd73fbdSAndrew Lunn const char *resource_name, 12295cd73fbdSAndrew Lunn u64 resource_size, 12305cd73fbdSAndrew Lunn u64 resource_id, 12315cd73fbdSAndrew Lunn u64 parent_resource_id, 12325cd73fbdSAndrew Lunn const struct devlink_resource_size_params *size_params); 12335cd73fbdSAndrew Lunn 12345cd73fbdSAndrew Lunn void dsa_devlink_resources_unregister(struct dsa_switch *ds); 12355cd73fbdSAndrew Lunn 12365cd73fbdSAndrew Lunn void dsa_devlink_resource_occ_get_register(struct dsa_switch *ds, 12375cd73fbdSAndrew Lunn u64 resource_id, 12385cd73fbdSAndrew Lunn devlink_resource_occ_get_t *occ_get, 12395cd73fbdSAndrew Lunn void *occ_get_priv); 12405cd73fbdSAndrew Lunn void dsa_devlink_resource_occ_get_unregister(struct dsa_switch *ds, 12415cd73fbdSAndrew Lunn u64 resource_id); 124297c82c23SAndrew Lunn struct devlink_region * 124397c82c23SAndrew Lunn dsa_devlink_region_create(struct dsa_switch *ds, 124497c82c23SAndrew Lunn const struct devlink_region_ops *ops, 124597c82c23SAndrew Lunn u32 region_max_snapshots, u64 region_size); 124608156ba4SAndrew Lunn struct devlink_region * 124708156ba4SAndrew Lunn dsa_devlink_port_region_create(struct dsa_switch *ds, 124808156ba4SAndrew Lunn int port, 124908156ba4SAndrew Lunn const struct devlink_port_region_ops *ops, 125008156ba4SAndrew Lunn u32 region_max_snapshots, u64 region_size); 125197c82c23SAndrew Lunn void dsa_devlink_region_destroy(struct devlink_region *region); 125297c82c23SAndrew Lunn 1253e1eea811SVladimir Oltean struct dsa_port *dsa_port_from_netdev(struct net_device *netdev); 12545cd73fbdSAndrew Lunn 12556b297524SAndrew Lunn struct dsa_devlink_priv { 12566b297524SAndrew Lunn struct dsa_switch *ds; 1257c8f0b869SBen Hutchings }; 1258c8f0b869SBen Hutchings 1259ccc3e6b0SAndrew Lunn static inline struct dsa_switch *dsa_devlink_to_ds(struct devlink *dl) 1260ccc3e6b0SAndrew Lunn { 1261ccc3e6b0SAndrew Lunn struct dsa_devlink_priv *dl_priv = devlink_priv(dl); 1262ccc3e6b0SAndrew Lunn 1263ccc3e6b0SAndrew Lunn return dl_priv->ds; 1264ccc3e6b0SAndrew Lunn } 1265ccc3e6b0SAndrew Lunn 12667d1e2a10SAndrew Lunn static inline 12677d1e2a10SAndrew Lunn struct dsa_switch *dsa_devlink_port_to_ds(struct devlink_port *port) 12687d1e2a10SAndrew Lunn { 12697d1e2a10SAndrew Lunn struct devlink *dl = port->devlink; 12707d1e2a10SAndrew Lunn struct dsa_devlink_priv *dl_priv = devlink_priv(dl); 12717d1e2a10SAndrew Lunn 12727d1e2a10SAndrew Lunn return dl_priv->ds; 12737d1e2a10SAndrew Lunn } 12747d1e2a10SAndrew Lunn 12757d1e2a10SAndrew Lunn static inline int dsa_devlink_port_to_port(struct devlink_port *port) 12767d1e2a10SAndrew Lunn { 12777d1e2a10SAndrew Lunn return port->index; 12787d1e2a10SAndrew Lunn } 12797d1e2a10SAndrew Lunn 1280ab3d408dSFlorian Fainelli struct dsa_switch_driver { 1281ab3d408dSFlorian Fainelli struct list_head list; 1282a82f67afSFlorian Fainelli const struct dsa_switch_ops *ops; 1283ab3d408dSFlorian Fainelli }; 1284ab3d408dSFlorian Fainelli 128514b89f36SFlorian Fainelli struct net_device *dsa_dev_to_net_device(struct device *dev); 1286c8f0b869SBen Hutchings 12877e580490SVladimir Oltean bool dsa_fdb_present_in_other_db(struct dsa_switch *ds, int port, 12887e580490SVladimir Oltean const unsigned char *addr, u16 vid, 12897e580490SVladimir Oltean struct dsa_db db); 12907e580490SVladimir Oltean bool dsa_mdb_present_in_other_db(struct dsa_switch *ds, int port, 12917e580490SVladimir Oltean const struct switchdev_obj_port_mdb *mdb, 12927e580490SVladimir Oltean struct dsa_db db); 1293f9cef64fSVladimir Oltean 129473a7ece8SVivien Didelot /* Keep inline for faster access in hot path */ 12959eb8eff0SVladimir Oltean static inline bool netdev_uses_dsa(const struct net_device *dev) 1296c6e970a0SAndrew Lunn { 1297c6e970a0SAndrew Lunn #if IS_ENABLED(CONFIG_NET_DSA) 1298717ffbfbSVivien Didelot return dev->dsa_ptr && dev->dsa_ptr->rcv; 1299c6e970a0SAndrew Lunn #endif 1300c6e970a0SAndrew Lunn return false; 1301c6e970a0SAndrew Lunn } 1302c6e970a0SAndrew Lunn 13039790cf20SVladimir Oltean /* All DSA tags that push the EtherType to the right (basically all except tail 13049790cf20SVladimir Oltean * tags, which don't break dissection) can be treated the same from the 13059790cf20SVladimir Oltean * perspective of the flow dissector. 13069790cf20SVladimir Oltean * 13079790cf20SVladimir Oltean * We need to return: 13089790cf20SVladimir Oltean * - offset: the (B - A) difference between: 13099790cf20SVladimir Oltean * A. the position of the real EtherType and 13109790cf20SVladimir Oltean * B. the current skb->data (aka ETH_HLEN bytes into the frame, aka 2 bytes 13119790cf20SVladimir Oltean * after the normal EtherType was supposed to be) 13129790cf20SVladimir Oltean * The offset in bytes is exactly equal to the tagger overhead (and half of 13139790cf20SVladimir Oltean * that, in __be16 shorts). 13149790cf20SVladimir Oltean * 13159790cf20SVladimir Oltean * - proto: the value of the real EtherType. 13169790cf20SVladimir Oltean */ 13179790cf20SVladimir Oltean static inline void dsa_tag_generic_flow_dissect(const struct sk_buff *skb, 13189790cf20SVladimir Oltean __be16 *proto, int *offset) 13199790cf20SVladimir Oltean { 13209790cf20SVladimir Oltean #if IS_ENABLED(CONFIG_NET_DSA) 13219790cf20SVladimir Oltean const struct dsa_device_ops *ops = skb->dev->dsa_ptr->tag_ops; 13224e500251SVladimir Oltean int tag_len = ops->needed_headroom; 13239790cf20SVladimir Oltean 13249790cf20SVladimir Oltean *offset = tag_len; 13259790cf20SVladimir Oltean *proto = ((__be16 *)skb->data)[(tag_len / 2) - 1]; 13269790cf20SVladimir Oltean #endif 13279790cf20SVladimir Oltean } 13289790cf20SVladimir Oltean 13294cfab356SFlorian Fainelli #if IS_ENABLED(CONFIG_NET_DSA) 13304cfab356SFlorian Fainelli static inline int __dsa_netdevice_ops_check(struct net_device *dev) 13314cfab356SFlorian Fainelli { 13324cfab356SFlorian Fainelli int err = -EOPNOTSUPP; 13334cfab356SFlorian Fainelli 13344cfab356SFlorian Fainelli if (!dev->dsa_ptr) 13354cfab356SFlorian Fainelli return err; 13364cfab356SFlorian Fainelli 13374cfab356SFlorian Fainelli if (!dev->dsa_ptr->netdev_ops) 13384cfab356SFlorian Fainelli return err; 13394cfab356SFlorian Fainelli 13404cfab356SFlorian Fainelli return 0; 13414cfab356SFlorian Fainelli } 13424cfab356SFlorian Fainelli 1343a7605370SArnd Bergmann static inline int dsa_ndo_eth_ioctl(struct net_device *dev, struct ifreq *ifr, 13444cfab356SFlorian Fainelli int cmd) 13454cfab356SFlorian Fainelli { 13464cfab356SFlorian Fainelli const struct dsa_netdevice_ops *ops; 13474cfab356SFlorian Fainelli int err; 13484cfab356SFlorian Fainelli 13494cfab356SFlorian Fainelli err = __dsa_netdevice_ops_check(dev); 13504cfab356SFlorian Fainelli if (err) 13514cfab356SFlorian Fainelli return err; 13524cfab356SFlorian Fainelli 13534cfab356SFlorian Fainelli ops = dev->dsa_ptr->netdev_ops; 13544cfab356SFlorian Fainelli 1355a7605370SArnd Bergmann return ops->ndo_eth_ioctl(dev, ifr, cmd); 13564cfab356SFlorian Fainelli } 13574cfab356SFlorian Fainelli #else 1358a7605370SArnd Bergmann static inline int dsa_ndo_eth_ioctl(struct net_device *dev, struct ifreq *ifr, 13594cfab356SFlorian Fainelli int cmd) 13604cfab356SFlorian Fainelli { 13614cfab356SFlorian Fainelli return -EOPNOTSUPP; 13624cfab356SFlorian Fainelli } 13634cfab356SFlorian Fainelli #endif 13644cfab356SFlorian Fainelli 136583c0afaeSAndrew Lunn void dsa_unregister_switch(struct dsa_switch *ds); 136623c9ee49SVivien Didelot int dsa_register_switch(struct dsa_switch *ds); 13670650bf52SVladimir Oltean void dsa_switch_shutdown(struct dsa_switch *ds); 13683b7bc1f0SVladimir Oltean struct dsa_switch *dsa_switch_find(int tree_index, int sw_index); 1369a2614140SVladimir Oltean void dsa_flush_workqueue(void); 1370ea825e70SFlorian Fainelli #ifdef CONFIG_PM_SLEEP 1371ea825e70SFlorian Fainelli int dsa_switch_suspend(struct dsa_switch *ds); 1372ea825e70SFlorian Fainelli int dsa_switch_resume(struct dsa_switch *ds); 1373ea825e70SFlorian Fainelli #else 1374ea825e70SFlorian Fainelli static inline int dsa_switch_suspend(struct dsa_switch *ds) 1375ea825e70SFlorian Fainelli { 1376ea825e70SFlorian Fainelli return 0; 1377ea825e70SFlorian Fainelli } 1378ea825e70SFlorian Fainelli static inline int dsa_switch_resume(struct dsa_switch *ds) 1379ea825e70SFlorian Fainelli { 1380ea825e70SFlorian Fainelli return 0; 1381ea825e70SFlorian Fainelli } 1382ea825e70SFlorian Fainelli #endif /* CONFIG_PM_SLEEP */ 1383ea825e70SFlorian Fainelli 138460724d4bSFlorian Fainelli #if IS_ENABLED(CONFIG_NET_DSA) 1385a5e3c9baSVladimir Oltean bool dsa_slave_dev_check(const struct net_device *dev); 138660724d4bSFlorian Fainelli #else 1387a5e3c9baSVladimir Oltean static inline bool dsa_slave_dev_check(const struct net_device *dev) 1388a5e3c9baSVladimir Oltean { 1389a5e3c9baSVladimir Oltean return false; 1390a5e3c9baSVladimir Oltean } 139160724d4bSFlorian Fainelli #endif 139260724d4bSFlorian Fainelli 139397a69a0dSVladimir Oltean netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, struct net_device *dev); 139411d8f3ddSFlorian Fainelli void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up); 1395cf963573SFlorian Fainelli 1396d3b8c049SAndrew Lunn struct dsa_tag_driver { 1397d3b8c049SAndrew Lunn const struct dsa_device_ops *ops; 1398d3b8c049SAndrew Lunn struct list_head list; 1399d3b8c049SAndrew Lunn struct module *owner; 1400d3b8c049SAndrew Lunn }; 1401d3b8c049SAndrew Lunn 1402d3b8c049SAndrew Lunn void dsa_tag_drivers_register(struct dsa_tag_driver *dsa_tag_driver_array[], 1403d3b8c049SAndrew Lunn unsigned int count, 1404d3b8c049SAndrew Lunn struct module *owner); 1405d3b8c049SAndrew Lunn void dsa_tag_drivers_unregister(struct dsa_tag_driver *dsa_tag_driver_array[], 1406d3b8c049SAndrew Lunn unsigned int count); 1407d3b8c049SAndrew Lunn 1408d3b8c049SAndrew Lunn #define dsa_tag_driver_module_drivers(__dsa_tag_drivers_array, __count) \ 1409d3b8c049SAndrew Lunn static int __init dsa_tag_driver_module_init(void) \ 1410d3b8c049SAndrew Lunn { \ 1411d3b8c049SAndrew Lunn dsa_tag_drivers_register(__dsa_tag_drivers_array, __count, \ 1412d3b8c049SAndrew Lunn THIS_MODULE); \ 1413d3b8c049SAndrew Lunn return 0; \ 1414d3b8c049SAndrew Lunn } \ 1415d3b8c049SAndrew Lunn module_init(dsa_tag_driver_module_init); \ 1416d3b8c049SAndrew Lunn \ 1417d3b8c049SAndrew Lunn static void __exit dsa_tag_driver_module_exit(void) \ 1418d3b8c049SAndrew Lunn { \ 1419d3b8c049SAndrew Lunn dsa_tag_drivers_unregister(__dsa_tag_drivers_array, __count); \ 1420d3b8c049SAndrew Lunn } \ 1421d3b8c049SAndrew Lunn module_exit(dsa_tag_driver_module_exit) 1422d3b8c049SAndrew Lunn 1423d3b8c049SAndrew Lunn /** 1424d3b8c049SAndrew Lunn * module_dsa_tag_drivers() - Helper macro for registering DSA tag 1425d3b8c049SAndrew Lunn * drivers 1426c7d9a675SLuiz Angelo Daros de Luca * @__ops_array: Array of tag driver structures 1427d3b8c049SAndrew Lunn * 1428d3b8c049SAndrew Lunn * Helper macro for DSA tag drivers which do not do anything special 1429d3b8c049SAndrew Lunn * in module init/exit. Each module may only use this macro once, and 1430d3b8c049SAndrew Lunn * calling it replaces module_init() and module_exit(). 1431d3b8c049SAndrew Lunn */ 1432d3b8c049SAndrew Lunn #define module_dsa_tag_drivers(__ops_array) \ 1433d3b8c049SAndrew Lunn dsa_tag_driver_module_drivers(__ops_array, ARRAY_SIZE(__ops_array)) 1434d3b8c049SAndrew Lunn 1435d3b8c049SAndrew Lunn #define DSA_TAG_DRIVER_NAME(__ops) dsa_tag_driver ## _ ## __ops 1436d3b8c049SAndrew Lunn 1437d3b8c049SAndrew Lunn /* Create a static structure we can build a linked list of dsa_tag 1438d3b8c049SAndrew Lunn * drivers 1439d3b8c049SAndrew Lunn */ 1440d3b8c049SAndrew Lunn #define DSA_TAG_DRIVER(__ops) \ 1441d3b8c049SAndrew Lunn static struct dsa_tag_driver DSA_TAG_DRIVER_NAME(__ops) = { \ 1442d3b8c049SAndrew Lunn .ops = &__ops, \ 1443d3b8c049SAndrew Lunn } 1444d3b8c049SAndrew Lunn 1445d3b8c049SAndrew Lunn /** 1446d3b8c049SAndrew Lunn * module_dsa_tag_driver() - Helper macro for registering a single DSA tag 1447d3b8c049SAndrew Lunn * driver 1448d3b8c049SAndrew Lunn * @__ops: Single tag driver structures 1449d3b8c049SAndrew Lunn * 1450d3b8c049SAndrew Lunn * Helper macro for DSA tag drivers which do not do anything special 1451d3b8c049SAndrew Lunn * in module init/exit. Each module may only use this macro once, and 1452d3b8c049SAndrew Lunn * calling it replaces module_init() and module_exit(). 1453d3b8c049SAndrew Lunn */ 1454d3b8c049SAndrew Lunn #define module_dsa_tag_driver(__ops) \ 1455d3b8c049SAndrew Lunn DSA_TAG_DRIVER(__ops); \ 1456d3b8c049SAndrew Lunn \ 1457d3b8c049SAndrew Lunn static struct dsa_tag_driver *dsa_tag_driver_array[] = { \ 1458d3b8c049SAndrew Lunn &DSA_TAG_DRIVER_NAME(__ops) \ 1459d3b8c049SAndrew Lunn }; \ 1460d3b8c049SAndrew Lunn module_dsa_tag_drivers(dsa_tag_driver_array) 146191da11f8SLennert Buytenhek #endif 1462d3b8c049SAndrew Lunn 1463