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 540b42f033SAndrew Lunn 55ac7a04c3SFlorian Fainelli enum dsa_tag_protocol { 560b42f033SAndrew Lunn DSA_TAG_PROTO_NONE = DSA_TAG_PROTO_NONE_VALUE, 570b42f033SAndrew Lunn DSA_TAG_PROTO_BRCM = DSA_TAG_PROTO_BRCM_VALUE, 58964dbf18SÁlvaro Fernández Rojas DSA_TAG_PROTO_BRCM_LEGACY = DSA_TAG_PROTO_BRCM_LEGACY_VALUE, 590b42f033SAndrew Lunn DSA_TAG_PROTO_BRCM_PREPEND = DSA_TAG_PROTO_BRCM_PREPEND_VALUE, 600b42f033SAndrew Lunn DSA_TAG_PROTO_DSA = DSA_TAG_PROTO_DSA_VALUE, 610b42f033SAndrew Lunn DSA_TAG_PROTO_EDSA = DSA_TAG_PROTO_EDSA_VALUE, 620b42f033SAndrew Lunn DSA_TAG_PROTO_GSWIP = DSA_TAG_PROTO_GSWIP_VALUE, 630b42f033SAndrew Lunn DSA_TAG_PROTO_KSZ9477 = DSA_TAG_PROTO_KSZ9477_VALUE, 640b42f033SAndrew Lunn DSA_TAG_PROTO_KSZ9893 = DSA_TAG_PROTO_KSZ9893_VALUE, 650b42f033SAndrew Lunn DSA_TAG_PROTO_LAN9303 = DSA_TAG_PROTO_LAN9303_VALUE, 660b42f033SAndrew Lunn DSA_TAG_PROTO_MTK = DSA_TAG_PROTO_MTK_VALUE, 670b42f033SAndrew Lunn DSA_TAG_PROTO_QCA = DSA_TAG_PROTO_QCA_VALUE, 680b42f033SAndrew Lunn DSA_TAG_PROTO_TRAILER = DSA_TAG_PROTO_TRAILER_VALUE, 69f9bbe447SVladimir Oltean DSA_TAG_PROTO_8021Q = DSA_TAG_PROTO_8021Q_VALUE, 70227d07a0SVladimir Oltean DSA_TAG_PROTO_SJA1105 = DSA_TAG_PROTO_SJA1105_VALUE, 71016e43a2STristram Ha DSA_TAG_PROTO_KSZ8795 = DSA_TAG_PROTO_KSZ8795_VALUE, 728dce89aaSVladimir Oltean DSA_TAG_PROTO_OCELOT = DSA_TAG_PROTO_OCELOT_VALUE, 7348fda74fSOleksij Rempel DSA_TAG_PROTO_AR9331 = DSA_TAG_PROTO_AR9331_VALUE, 74efd7fe68SLinus Walleij DSA_TAG_PROTO_RTL4_A = DSA_TAG_PROTO_RTL4_A_VALUE, 7501ef09caSKurt Kanzenbach DSA_TAG_PROTO_HELLCREEK = DSA_TAG_PROTO_HELLCREEK_VALUE, 7654a52823SGeorge McCollister DSA_TAG_PROTO_XRS700X = DSA_TAG_PROTO_XRS700X_VALUE, 777c83a7c5SVladimir Oltean DSA_TAG_PROTO_OCELOT_8021Q = DSA_TAG_PROTO_OCELOT_8021Q_VALUE, 787c4bb540SVladimir Oltean DSA_TAG_PROTO_SEVILLE = DSA_TAG_PROTO_SEVILLE_VALUE, 794913b8ebSVladimir Oltean DSA_TAG_PROTO_SJA1110 = DSA_TAG_PROTO_SJA1110_VALUE, 80ac7a04c3SFlorian Fainelli }; 815037d532SFlorian Fainelli 825075314eSAlexander Duyck struct packet_type; 8390af1059SBrandon Streiff struct dsa_switch; 843e8a72d1SFlorian Fainelli 8568277a2cSJohn Crispin struct dsa_device_ops { 8668277a2cSJohn Crispin struct sk_buff *(*xmit)(struct sk_buff *skb, struct net_device *dev); 8768277a2cSJohn Crispin struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev, 8889e49506SFlorian Westphal struct packet_type *pt); 892e8cb1b3SVladimir Oltean void (*flow_dissect)(const struct sk_buff *skb, __be16 *proto, 90598a9680SJohn Crispin int *offset); 91cc1939e4SVladimir Oltean /* Used to determine which traffic should match the DSA filter in 92cc1939e4SVladimir Oltean * eth_type_trans, and which, if any, should bypass it and be processed 93cc1939e4SVladimir Oltean * as regular on the master net device. 94cc1939e4SVladimir Oltean */ 95cc1939e4SVladimir Oltean bool (*filter)(const struct sk_buff *skb, struct net_device *dev); 964e500251SVladimir Oltean unsigned int needed_headroom; 974e500251SVladimir Oltean unsigned int needed_tailroom; 98875138f8SAndrew Lunn const char *name; 99056eed2fSAndrew Lunn enum dsa_tag_protocol proto; 100c3975400SVladimir Oltean /* Some tagging protocols either mangle or shift the destination MAC 101c3975400SVladimir Oltean * address, in which case the DSA master would drop packets on ingress 102c3975400SVladimir Oltean * if what it understands out of the destination MAC address is not in 103c3975400SVladimir Oltean * its RX filter. 104c3975400SVladimir Oltean */ 105c3975400SVladimir Oltean bool promisc_on_master; 10668277a2cSJohn Crispin }; 10768277a2cSJohn Crispin 1084cfab356SFlorian Fainelli /* This structure defines the control interfaces that are overlayed by the 1094cfab356SFlorian Fainelli * DSA layer on top of the DSA CPU/management net_device instance. This is 1104cfab356SFlorian Fainelli * used by the core net_device layer while calling various net_device_ops 1114cfab356SFlorian Fainelli * function pointers. 1124cfab356SFlorian Fainelli */ 1134cfab356SFlorian Fainelli struct dsa_netdevice_ops { 1144cfab356SFlorian Fainelli int (*ndo_do_ioctl)(struct net_device *dev, struct ifreq *ifr, 1154cfab356SFlorian Fainelli int cmd); 1164cfab356SFlorian Fainelli }; 1174cfab356SFlorian Fainelli 1180b42f033SAndrew Lunn #define DSA_TAG_DRIVER_ALIAS "dsa_tag-" 1190b42f033SAndrew Lunn #define MODULE_ALIAS_DSA_TAG_DRIVER(__proto) \ 1200b42f033SAndrew Lunn MODULE_ALIAS(DSA_TAG_DRIVER_ALIAS __stringify(__proto##_VALUE)) 1210b42f033SAndrew Lunn 122cf50dcc2SBen Hutchings struct dsa_switch_tree { 12383c0afaeSAndrew Lunn struct list_head list; 12483c0afaeSAndrew Lunn 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 13483c0afaeSAndrew Lunn /* Has this tree been applied to the hardware? */ 135ec15dd42SVivien Didelot bool setup; 13683c0afaeSAndrew Lunn 137357f203bSVladimir Oltean /* Tagging protocol operations */ 138357f203bSVladimir Oltean const struct dsa_device_ops *tag_ops; 139357f203bSVladimir Oltean 140deff7107STobias Waldekranz /* Default tagging protocol preferred by the switches in this 141deff7107STobias Waldekranz * tree. 142deff7107STobias Waldekranz */ 143deff7107STobias Waldekranz enum dsa_tag_protocol default_proto; 144deff7107STobias Waldekranz 145cf50dcc2SBen Hutchings /* 146cf50dcc2SBen Hutchings * Configuration data for the platform device that owns 147cf50dcc2SBen Hutchings * this dsa switch tree instance. 148cf50dcc2SBen Hutchings */ 149cf50dcc2SBen Hutchings struct dsa_platform_data *pd; 150cf85d08fSLennert Buytenhek 151ab8ccae1SVivien Didelot /* List of switch ports */ 152ab8ccae1SVivien Didelot struct list_head ports; 153ab8ccae1SVivien Didelot 154c5f51765SVivien Didelot /* List of DSA links composing the routing table */ 155c5f51765SVivien Didelot struct list_head rtable; 156058102a6STobias Waldekranz 157058102a6STobias Waldekranz /* Maps offloaded LAG netdevs to a zero-based linear ID for 158058102a6STobias Waldekranz * drivers that need it. 159058102a6STobias Waldekranz */ 160058102a6STobias Waldekranz struct net_device **lags; 161058102a6STobias Waldekranz unsigned int lags_len; 162cf50dcc2SBen Hutchings }; 163cf50dcc2SBen Hutchings 164058102a6STobias Waldekranz #define dsa_lags_foreach_id(_id, _dst) \ 165058102a6STobias Waldekranz for ((_id) = 0; (_id) < (_dst)->lags_len; (_id)++) \ 166058102a6STobias Waldekranz if ((_dst)->lags[(_id)]) 167058102a6STobias Waldekranz 168058102a6STobias Waldekranz #define dsa_lag_foreach_port(_dp, _dst, _lag) \ 169058102a6STobias Waldekranz list_for_each_entry((_dp), &(_dst)->ports, list) \ 170058102a6STobias Waldekranz if ((_dp)->lag_dev == (_lag)) 171058102a6STobias Waldekranz 17218596f50SGeorge McCollister #define dsa_hsr_foreach_port(_dp, _ds, _hsr) \ 17318596f50SGeorge McCollister list_for_each_entry((_dp), &(_ds)->dst->ports, list) \ 17418596f50SGeorge McCollister if ((_dp)->ds == (_ds) && (_dp)->hsr_dev == (_hsr)) 17518596f50SGeorge McCollister 176058102a6STobias Waldekranz static inline struct net_device *dsa_lag_dev(struct dsa_switch_tree *dst, 177058102a6STobias Waldekranz unsigned int id) 178058102a6STobias Waldekranz { 179058102a6STobias Waldekranz return dst->lags[id]; 180058102a6STobias Waldekranz } 181058102a6STobias Waldekranz 182058102a6STobias Waldekranz static inline int dsa_lag_id(struct dsa_switch_tree *dst, 183058102a6STobias Waldekranz struct net_device *lag) 184058102a6STobias Waldekranz { 185058102a6STobias Waldekranz unsigned int id; 186058102a6STobias Waldekranz 187058102a6STobias Waldekranz dsa_lags_foreach_id(id, dst) { 188058102a6STobias Waldekranz if (dsa_lag_dev(dst, id) == lag) 189058102a6STobias Waldekranz return id; 190058102a6STobias Waldekranz } 191058102a6STobias Waldekranz 192058102a6STobias Waldekranz return -ENODEV; 193058102a6STobias Waldekranz } 194058102a6STobias Waldekranz 19534297176SVladimir Oltean /* TC matchall action types */ 196f50f2127SFlorian Fainelli enum dsa_port_mall_action_type { 197f50f2127SFlorian Fainelli DSA_PORT_MALL_MIRROR, 19834297176SVladimir Oltean DSA_PORT_MALL_POLICER, 199f50f2127SFlorian Fainelli }; 200f50f2127SFlorian Fainelli 201f50f2127SFlorian Fainelli /* TC mirroring entry */ 202f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry { 203f50f2127SFlorian Fainelli u8 to_local_port; 204f50f2127SFlorian Fainelli bool ingress; 205f50f2127SFlorian Fainelli }; 206f50f2127SFlorian Fainelli 20734297176SVladimir Oltean /* TC port policer entry */ 20834297176SVladimir Oltean struct dsa_mall_policer_tc_entry { 2095f035af7SPo Liu u32 burst; 21034297176SVladimir Oltean u64 rate_bytes_per_sec; 21134297176SVladimir Oltean }; 21234297176SVladimir Oltean 213f50f2127SFlorian Fainelli /* TC matchall entry */ 214f50f2127SFlorian Fainelli struct dsa_mall_tc_entry { 215f50f2127SFlorian Fainelli struct list_head list; 216f50f2127SFlorian Fainelli unsigned long cookie; 217f50f2127SFlorian Fainelli enum dsa_port_mall_action_type type; 218f50f2127SFlorian Fainelli union { 219f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry mirror; 22034297176SVladimir Oltean struct dsa_mall_policer_tc_entry policer; 221f50f2127SFlorian Fainelli }; 222f50f2127SFlorian Fainelli }; 223f50f2127SFlorian Fainelli 224f50f2127SFlorian Fainelli 225c8b09808SAndrew Lunn struct dsa_port { 226f8b8b1cdSVivien Didelot /* A CPU port is physically connected to a master device. 227f8b8b1cdSVivien Didelot * A user port exposed to userspace has a slave device. 228f8b8b1cdSVivien Didelot */ 229f8b8b1cdSVivien Didelot union { 230f8b8b1cdSVivien Didelot struct net_device *master; 231f8b8b1cdSVivien Didelot struct net_device *slave; 232f8b8b1cdSVivien Didelot }; 233f8b8b1cdSVivien Didelot 234357f203bSVladimir Oltean /* Copy of the tagging protocol operations, for quicker access 235357f203bSVladimir Oltean * in the data path. Valid only for the CPU ports. 236357f203bSVladimir Oltean */ 23715240248SVivien Didelot const struct dsa_device_ops *tag_ops; 23815240248SVivien Didelot 2393e41f93bSVivien Didelot /* Copies for faster access in master receive hot path */ 2403e41f93bSVivien Didelot struct dsa_switch_tree *dst; 2413e41f93bSVivien Didelot struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev, 2423e41f93bSVivien Didelot struct packet_type *pt); 243cc1939e4SVladimir Oltean bool (*filter)(const struct sk_buff *skb, struct net_device *dev); 2443e41f93bSVivien Didelot 245057cad2cSVivien Didelot enum { 246057cad2cSVivien Didelot DSA_PORT_TYPE_UNUSED = 0, 247057cad2cSVivien Didelot DSA_PORT_TYPE_CPU, 248057cad2cSVivien Didelot DSA_PORT_TYPE_DSA, 249057cad2cSVivien Didelot DSA_PORT_TYPE_USER, 250057cad2cSVivien Didelot } type; 251057cad2cSVivien Didelot 252818be848SVivien Didelot struct dsa_switch *ds; 253818be848SVivien Didelot unsigned int index; 25471e0bbdeSFlorian Fainelli const char *name; 25568b2d4a8SVivien Didelot struct dsa_port *cpu_dp; 25683216e39SMichael Walle u8 mac[ETH_ALEN]; 257189b0d93SAndrew Lunn struct device_node *dn; 25834a79f63SVivien Didelot unsigned int ageing_time; 25933162e9aSVladimir Oltean bool vlan_filtering; 260732f794cSVivien Didelot u8 stp_state; 261a5e9a02eSVivien Didelot struct net_device *bridge_dev; 26296567d5dSAndrew Lunn struct devlink_port devlink_port; 2633122433eSAndrew Lunn bool devlink_port_setup; 264aab9c406SFlorian Fainelli struct phylink *pl; 26544cc27e4SIoana Ciornei struct phylink_config pl_config; 266058102a6STobias Waldekranz struct net_device *lag_dev; 267058102a6STobias Waldekranz bool lag_tx_enabled; 26818596f50SGeorge McCollister struct net_device *hsr_dev; 26997a69a0dSVladimir Oltean 270ab8ccae1SVivien Didelot struct list_head list; 271ab8ccae1SVivien Didelot 27267dbb9d4SFlorian Fainelli /* 273c362beb0SVladimir Oltean * Give the switch driver somewhere to hang its per-port private data 274c362beb0SVladimir Oltean * structures (accessible from the tagger). 275c362beb0SVladimir Oltean */ 276c362beb0SVladimir Oltean void *priv; 277c362beb0SVladimir Oltean 278c362beb0SVladimir Oltean /* 27967dbb9d4SFlorian Fainelli * Original copy of the master netdev ethtool_ops 28067dbb9d4SFlorian Fainelli */ 28167dbb9d4SFlorian Fainelli const struct ethtool_ops *orig_ethtool_ops; 282da7b9e9bSFlorian Fainelli 283da7b9e9bSFlorian Fainelli /* 284da7b9e9bSFlorian Fainelli * Original copy of the master netdev net_device_ops 285da7b9e9bSFlorian Fainelli */ 2864cfab356SFlorian Fainelli const struct dsa_netdevice_ops *netdev_ops; 287fb35c60cSVivien Didelot 288fb35c60cSVivien Didelot bool setup; 289c8b09808SAndrew Lunn }; 290c8b09808SAndrew Lunn 291c5f51765SVivien Didelot /* TODO: ideally DSA ports would have a single dp->link_dp member, 292c5f51765SVivien Didelot * and no dst->rtable nor this struct dsa_link would be needed, 293c5f51765SVivien Didelot * but this would require some more complex tree walking, 294c5f51765SVivien Didelot * so keep it stupid at the moment and list them all. 295c5f51765SVivien Didelot */ 296c5f51765SVivien Didelot struct dsa_link { 297c5f51765SVivien Didelot struct dsa_port *dp; 298c5f51765SVivien Didelot struct dsa_port *link_dp; 299c5f51765SVivien Didelot struct list_head list; 300c5f51765SVivien Didelot }; 301c5f51765SVivien Didelot 302c8f0b869SBen Hutchings struct dsa_switch { 303fb35c60cSVivien Didelot bool setup; 304fb35c60cSVivien Didelot 305c33063d6SAndrew Lunn struct device *dev; 306c33063d6SAndrew Lunn 307c8f0b869SBen Hutchings /* 308c8f0b869SBen Hutchings * Parent switch tree, and switch index. 309c8f0b869SBen Hutchings */ 310c8f0b869SBen Hutchings struct dsa_switch_tree *dst; 31199feaafcSVivien Didelot unsigned int index; 312c8f0b869SBen Hutchings 313f515f192SVivien Didelot /* Listener for switch fabric events */ 314f515f192SVivien Didelot struct notifier_block nb; 315f515f192SVivien Didelot 316c8f0b869SBen Hutchings /* 3177543a6d5SAndrew Lunn * Give the switch driver somewhere to hang its private data 3187543a6d5SAndrew Lunn * structure. 3197543a6d5SAndrew Lunn */ 3207543a6d5SAndrew Lunn void *priv; 3217543a6d5SAndrew Lunn 3227543a6d5SAndrew Lunn /* 323c8f0b869SBen Hutchings * Configuration data for this switch. 324c8f0b869SBen Hutchings */ 325ff04955cSAndrew Lunn struct dsa_chip_data *cd; 326c8f0b869SBen Hutchings 327c8f0b869SBen Hutchings /* 3289d490b4eSVivien Didelot * The switch operations. 329c8f0b869SBen Hutchings */ 330a82f67afSFlorian Fainelli const struct dsa_switch_ops *ops; 331c8f0b869SBen Hutchings 33266472fc0SAndrew Lunn /* 333c8f0b869SBen Hutchings * Slave mii_bus and devices for the individual ports. 334c8f0b869SBen Hutchings */ 3350d8bcdd3SFlorian Fainelli u32 phys_mii_mask; 336c8f0b869SBen Hutchings struct mii_bus *slave_mii_bus; 337a0c02161SVivien Didelot 3380f3da6afSVivien Didelot /* Ageing Time limits in msecs */ 3390f3da6afSVivien Didelot unsigned int ageing_time_min; 3400f3da6afSVivien Didelot unsigned int ageing_time_max; 3410f3da6afSVivien Didelot 34296567d5dSAndrew Lunn /* devlink used to represent this switch device */ 34396567d5dSAndrew Lunn struct devlink *devlink; 34496567d5dSAndrew Lunn 34555199df6SFlorian Fainelli /* Number of switch port queues */ 34655199df6SFlorian Fainelli unsigned int num_tx_queues; 34755199df6SFlorian Fainelli 3488f5d16f6SVladimir Oltean /* Disallow bridge core from requesting different VLAN awareness 3498f5d16f6SVladimir Oltean * settings on ports if not hardware-supported 3508f5d16f6SVladimir Oltean */ 3518f5d16f6SVladimir Oltean bool vlan_filtering_is_global; 3528f5d16f6SVladimir Oltean 35354a0ed0dSRussell King /* Pass .port_vlan_add and .port_vlan_del to drivers even for bridges 35454a0ed0dSRussell King * that have vlan_filtering=0. All drivers should ideally set this (and 35554a0ed0dSRussell King * then the option would get removed), but it is unknown whether this 35654a0ed0dSRussell King * would break things or not. 35754a0ed0dSRussell King */ 35854a0ed0dSRussell King bool configure_vlan_while_not_filtering; 35954a0ed0dSRussell King 3601dc0408cSFlorian Fainelli /* If the switch driver always programs the CPU port as egress tagged 3611dc0408cSFlorian Fainelli * despite the VLAN configuration indicating otherwise, then setting 3621dc0408cSFlorian Fainelli * @untag_bridge_pvid will force the DSA receive path to pop the bridge's 3631dc0408cSFlorian Fainelli * default_pvid VLAN tagged frames to offer a consistent behavior 3641dc0408cSFlorian Fainelli * between a vlan_filtering=0 and vlan_filtering=1 bridge device. 3651dc0408cSFlorian Fainelli */ 3661dc0408cSFlorian Fainelli bool untag_bridge_pvid; 3671dc0408cSFlorian Fainelli 368d5f19486SVladimir Oltean /* Let DSA manage the FDB entries towards the CPU, based on the 369d5f19486SVladimir Oltean * software bridge database. 370d5f19486SVladimir Oltean */ 371d5f19486SVladimir Oltean bool assisted_learning_on_cpu_port; 372d5f19486SVladimir Oltean 37314574676SVladimir Oltean /* In case vlan_filtering_is_global is set, the VLAN awareness state 37414574676SVladimir Oltean * should be retrieved from here and not from the per-port settings. 37514574676SVladimir Oltean */ 37614574676SVladimir Oltean bool vlan_filtering; 37714574676SVladimir Oltean 378787cac3fSVladimir Oltean /* MAC PCS does not provide link state change interrupt, and requires 379787cac3fSVladimir Oltean * polling. Flag passed on to PHYLINK. 380787cac3fSVladimir Oltean */ 381787cac3fSVladimir Oltean bool pcs_poll; 382787cac3fSVladimir Oltean 383bff33f7eSVladimir Oltean /* For switches that only have the MRU configurable. To ensure the 384bff33f7eSVladimir Oltean * configured MTU is not exceeded, normalization of MRU on all bridged 385bff33f7eSVladimir Oltean * interfaces is needed. 386bff33f7eSVladimir Oltean */ 387bff33f7eSVladimir Oltean bool mtu_enforcement_ingress; 388bff33f7eSVladimir Oltean 389058102a6STobias Waldekranz /* Drivers that benefit from having an ID associated with each 390058102a6STobias Waldekranz * offloaded LAG should set this to the maximum number of 391058102a6STobias Waldekranz * supported IDs. DSA will then maintain a mapping of _at 392058102a6STobias Waldekranz * least_ these many IDs, accessible to drivers via 393058102a6STobias Waldekranz * dsa_lag_id(). 394058102a6STobias Waldekranz */ 395058102a6STobias Waldekranz unsigned int num_lag_ids; 396058102a6STobias Waldekranz 397a0c02161SVivien Didelot size_t num_ports; 398c8f0b869SBen Hutchings }; 399c8f0b869SBen Hutchings 40068bb8ea8SVivien Didelot static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p) 401c38c5a66SVivien Didelot { 402b96ddf25SVivien Didelot struct dsa_switch_tree *dst = ds->dst; 403d607525bSVivien Didelot struct dsa_port *dp; 404b96ddf25SVivien Didelot 405b96ddf25SVivien Didelot list_for_each_entry(dp, &dst->ports, list) 406b96ddf25SVivien Didelot if (dp->ds == ds && dp->index == p) 407b96ddf25SVivien Didelot return dp; 408d607525bSVivien Didelot 409d607525bSVivien Didelot return NULL; 410c38c5a66SVivien Didelot } 411c38c5a66SVivien Didelot 412a8986681SVladimir Oltean static inline bool dsa_port_is_dsa(struct dsa_port *port) 413a8986681SVladimir Oltean { 414a8986681SVladimir Oltean return port->type == DSA_PORT_TYPE_DSA; 415a8986681SVladimir Oltean } 416a8986681SVladimir Oltean 417a8986681SVladimir Oltean static inline bool dsa_port_is_cpu(struct dsa_port *port) 418a8986681SVladimir Oltean { 419a8986681SVladimir Oltean return port->type == DSA_PORT_TYPE_CPU; 420a8986681SVladimir Oltean } 421a8986681SVladimir Oltean 422a8986681SVladimir Oltean static inline bool dsa_port_is_user(struct dsa_port *dp) 423a8986681SVladimir Oltean { 424a8986681SVladimir Oltean return dp->type == DSA_PORT_TYPE_USER; 425a8986681SVladimir Oltean } 426a8986681SVladimir Oltean 427bff7b688SVivien Didelot static inline bool dsa_is_unused_port(struct dsa_switch *ds, int p) 428bff7b688SVivien Didelot { 429c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_UNUSED; 430bff7b688SVivien Didelot } 431bff7b688SVivien Didelot 432c8f0b869SBen Hutchings static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p) 433c8f0b869SBen Hutchings { 434c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_CPU; 435c8f0b869SBen Hutchings } 436c8f0b869SBen Hutchings 43760045cbfSAndrew Lunn static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p) 43860045cbfSAndrew Lunn { 439c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_DSA; 44060045cbfSAndrew Lunn } 44160045cbfSAndrew Lunn 4422b3e9891SVivien Didelot static inline bool dsa_is_user_port(struct dsa_switch *ds, int p) 4436cd456f3SVivien Didelot { 444c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_USER; 4456cd456f3SVivien Didelot } 4466cd456f3SVivien Didelot 44702bc6e54SVivien Didelot static inline u32 dsa_user_ports(struct dsa_switch *ds) 44802bc6e54SVivien Didelot { 449c38c5a66SVivien Didelot u32 mask = 0; 450c38c5a66SVivien Didelot int p; 45102bc6e54SVivien Didelot 452c38c5a66SVivien Didelot for (p = 0; p < ds->num_ports; p++) 453c38c5a66SVivien Didelot if (dsa_is_user_port(ds, p)) 454c38c5a66SVivien Didelot mask |= BIT(p); 455c38c5a66SVivien Didelot 456c38c5a66SVivien Didelot return mask; 457c8652c83SVivien Didelot } 458c8652c83SVivien Didelot 459c5f51765SVivien Didelot /* Return the local port used to reach an arbitrary switch device */ 460c5f51765SVivien Didelot static inline unsigned int dsa_routing_port(struct dsa_switch *ds, int device) 461c5f51765SVivien Didelot { 462c5f51765SVivien Didelot struct dsa_switch_tree *dst = ds->dst; 463c5f51765SVivien Didelot struct dsa_link *dl; 464c5f51765SVivien Didelot 465c5f51765SVivien Didelot list_for_each_entry(dl, &dst->rtable, list) 466c5f51765SVivien Didelot if (dl->dp->ds == ds && dl->link_dp->ds->index == device) 467c5f51765SVivien Didelot return dl->dp->index; 468c5f51765SVivien Didelot 469c5f51765SVivien Didelot return ds->num_ports; 470c5f51765SVivien Didelot } 471c5f51765SVivien Didelot 4723b8fac5dSVivien Didelot /* Return the local port used to reach an arbitrary switch port */ 4733b8fac5dSVivien Didelot static inline unsigned int dsa_towards_port(struct dsa_switch *ds, int device, 4743b8fac5dSVivien Didelot int port) 4753b8fac5dSVivien Didelot { 4763b8fac5dSVivien Didelot if (device == ds->index) 4773b8fac5dSVivien Didelot return port; 4783b8fac5dSVivien Didelot else 479c5f51765SVivien Didelot return dsa_routing_port(ds, device); 4803b8fac5dSVivien Didelot } 4813b8fac5dSVivien Didelot 4823b8fac5dSVivien Didelot /* Return the local port used to reach the dedicated CPU port */ 48307073c79SVivien Didelot static inline unsigned int dsa_upstream_port(struct dsa_switch *ds, int port) 484c8f0b869SBen Hutchings { 48507073c79SVivien Didelot const struct dsa_port *dp = dsa_to_port(ds, port); 48607073c79SVivien Didelot const struct dsa_port *cpu_dp = dp->cpu_dp; 48707073c79SVivien Didelot 48807073c79SVivien Didelot if (!cpu_dp) 48907073c79SVivien Didelot return port; 490c8f0b869SBen Hutchings 4913b8fac5dSVivien Didelot return dsa_towards_port(ds, cpu_dp->ds->index, cpu_dp->index); 492c8f0b869SBen Hutchings } 493c8f0b869SBen Hutchings 494*63609c8fSVladimir Oltean /* Return true if this is the local port used to reach the CPU port */ 495*63609c8fSVladimir Oltean static inline bool dsa_is_upstream_port(struct dsa_switch *ds, int port) 496*63609c8fSVladimir Oltean { 497*63609c8fSVladimir Oltean if (dsa_is_unused_port(ds, port)) 498*63609c8fSVladimir Oltean return false; 499*63609c8fSVladimir Oltean 500*63609c8fSVladimir Oltean return port == dsa_upstream_port(ds, port); 501*63609c8fSVladimir Oltean } 502*63609c8fSVladimir Oltean 503*63609c8fSVladimir Oltean /* Return true if @upstream_ds is an upstream switch of @downstream_ds, meaning 504*63609c8fSVladimir Oltean * that the routing port from @downstream_ds to @upstream_ds is also the port 505*63609c8fSVladimir Oltean * which @downstream_ds uses to reach its dedicated CPU. 506*63609c8fSVladimir Oltean */ 507*63609c8fSVladimir Oltean static inline bool dsa_switch_is_upstream_of(struct dsa_switch *upstream_ds, 508*63609c8fSVladimir Oltean struct dsa_switch *downstream_ds) 509*63609c8fSVladimir Oltean { 510*63609c8fSVladimir Oltean int routing_port; 511*63609c8fSVladimir Oltean 512*63609c8fSVladimir Oltean if (upstream_ds == downstream_ds) 513*63609c8fSVladimir Oltean return true; 514*63609c8fSVladimir Oltean 515*63609c8fSVladimir Oltean routing_port = dsa_routing_port(downstream_ds, upstream_ds->index); 516*63609c8fSVladimir Oltean 517*63609c8fSVladimir Oltean return dsa_is_upstream_port(downstream_ds, routing_port); 518*63609c8fSVladimir Oltean } 519*63609c8fSVladimir Oltean 520cf2d45f5SVladimir Oltean static inline bool dsa_port_is_vlan_filtering(const struct dsa_port *dp) 521cf2d45f5SVladimir Oltean { 522cf2d45f5SVladimir Oltean const struct dsa_switch *ds = dp->ds; 523cf2d45f5SVladimir Oltean 524cf2d45f5SVladimir Oltean if (ds->vlan_filtering_is_global) 525cf2d45f5SVladimir Oltean return ds->vlan_filtering; 526cf2d45f5SVladimir Oltean else 527cf2d45f5SVladimir Oltean return dp->vlan_filtering; 528cf2d45f5SVladimir Oltean } 529cf2d45f5SVladimir Oltean 530cc76ce9eSTobias Waldekranz static inline 531cc76ce9eSTobias Waldekranz struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp) 532cc76ce9eSTobias Waldekranz { 533cc76ce9eSTobias Waldekranz if (!dp->bridge_dev) 534cc76ce9eSTobias Waldekranz return NULL; 535cc76ce9eSTobias Waldekranz 536cc76ce9eSTobias Waldekranz if (dp->lag_dev) 537cc76ce9eSTobias Waldekranz return dp->lag_dev; 538cc76ce9eSTobias Waldekranz else if (dp->hsr_dev) 539cc76ce9eSTobias Waldekranz return dp->hsr_dev; 540cc76ce9eSTobias Waldekranz 541cc76ce9eSTobias Waldekranz return dp->slave; 542cc76ce9eSTobias Waldekranz } 543cc76ce9eSTobias Waldekranz 5442bedde1aSArkadi Sharshevsky typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid, 5452bedde1aSArkadi Sharshevsky bool is_static, void *data); 5469d490b4eSVivien Didelot struct dsa_switch_ops { 54753da0ebaSVladimir Oltean /* 54853da0ebaSVladimir Oltean * Tagging protocol helpers called for the CPU ports and DSA links. 54953da0ebaSVladimir Oltean * @get_tag_protocol retrieves the initial tagging protocol and is 55053da0ebaSVladimir Oltean * mandatory. Switches which can operate using multiple tagging 55153da0ebaSVladimir Oltean * protocols should implement @change_tag_protocol and report in 55253da0ebaSVladimir Oltean * @get_tag_protocol the tagger in current use. 55353da0ebaSVladimir Oltean */ 5545ed4e3ebSFlorian Fainelli enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds, 5554d776482SFlorian Fainelli int port, 5564d776482SFlorian Fainelli enum dsa_tag_protocol mprot); 55753da0ebaSVladimir Oltean int (*change_tag_protocol)(struct dsa_switch *ds, int port, 55853da0ebaSVladimir Oltean enum dsa_tag_protocol proto); 5597b314362SAndrew Lunn 560c8f0b869SBen Hutchings int (*setup)(struct dsa_switch *ds); 5615e3f847aSVladimir Oltean void (*teardown)(struct dsa_switch *ds); 5626819563eSFlorian Fainelli u32 (*get_phy_flags)(struct dsa_switch *ds, int port); 563c8f0b869SBen Hutchings 564c8f0b869SBen Hutchings /* 565c8f0b869SBen Hutchings * Access to the switch's PHY registers. 566c8f0b869SBen Hutchings */ 567c8f0b869SBen Hutchings int (*phy_read)(struct dsa_switch *ds, int port, int regnum); 568c8f0b869SBen Hutchings int (*phy_write)(struct dsa_switch *ds, int port, 569c8f0b869SBen Hutchings int regnum, u16 val); 570c8f0b869SBen Hutchings 571c8f0b869SBen Hutchings /* 572ec9436baSFlorian Fainelli * Link state adjustment (called from libphy) 573ec9436baSFlorian Fainelli */ 574ec9436baSFlorian Fainelli void (*adjust_link)(struct dsa_switch *ds, int port, 575ec9436baSFlorian Fainelli struct phy_device *phydev); 576ce31b31cSFlorian Fainelli void (*fixed_link_update)(struct dsa_switch *ds, int port, 577ce31b31cSFlorian Fainelli struct fixed_phy_status *st); 578ec9436baSFlorian Fainelli 579ec9436baSFlorian Fainelli /* 58011d8f3ddSFlorian Fainelli * PHYLINK integration 58111d8f3ddSFlorian Fainelli */ 58211d8f3ddSFlorian Fainelli void (*phylink_validate)(struct dsa_switch *ds, int port, 58311d8f3ddSFlorian Fainelli unsigned long *supported, 58411d8f3ddSFlorian Fainelli struct phylink_link_state *state); 58511d8f3ddSFlorian Fainelli int (*phylink_mac_link_state)(struct dsa_switch *ds, int port, 58611d8f3ddSFlorian Fainelli struct phylink_link_state *state); 58711d8f3ddSFlorian Fainelli void (*phylink_mac_config)(struct dsa_switch *ds, int port, 58811d8f3ddSFlorian Fainelli unsigned int mode, 58911d8f3ddSFlorian Fainelli const struct phylink_link_state *state); 59011d8f3ddSFlorian Fainelli void (*phylink_mac_an_restart)(struct dsa_switch *ds, int port); 59111d8f3ddSFlorian Fainelli void (*phylink_mac_link_down)(struct dsa_switch *ds, int port, 59211d8f3ddSFlorian Fainelli unsigned int mode, 59311d8f3ddSFlorian Fainelli phy_interface_t interface); 59411d8f3ddSFlorian Fainelli void (*phylink_mac_link_up)(struct dsa_switch *ds, int port, 59511d8f3ddSFlorian Fainelli unsigned int mode, 59611d8f3ddSFlorian Fainelli phy_interface_t interface, 5975b502a7bSRussell King struct phy_device *phydev, 5985b502a7bSRussell King int speed, int duplex, 5995b502a7bSRussell King bool tx_pause, bool rx_pause); 60011d8f3ddSFlorian Fainelli void (*phylink_fixed_state)(struct dsa_switch *ds, int port, 60111d8f3ddSFlorian Fainelli struct phylink_link_state *state); 60211d8f3ddSFlorian Fainelli /* 603c2ec5f2eSOleksij Rempel * Port statistics counters. 604c8f0b869SBen Hutchings */ 60589f09048SFlorian Fainelli void (*get_strings)(struct dsa_switch *ds, int port, 60689f09048SFlorian Fainelli u32 stringset, uint8_t *data); 607c8f0b869SBen Hutchings void (*get_ethtool_stats)(struct dsa_switch *ds, 608c8f0b869SBen Hutchings int port, uint64_t *data); 60989f09048SFlorian Fainelli int (*get_sset_count)(struct dsa_switch *ds, int port, int sset); 610cf963573SFlorian Fainelli void (*get_ethtool_phy_stats)(struct dsa_switch *ds, 611cf963573SFlorian Fainelli int port, uint64_t *data); 612c2ec5f2eSOleksij Rempel void (*get_stats64)(struct dsa_switch *ds, int port, 613c2ec5f2eSOleksij Rempel struct rtnl_link_stats64 *s); 614a71acad9SOleksij Rempel void (*self_test)(struct dsa_switch *ds, int port, 615a71acad9SOleksij Rempel struct ethtool_test *etest, u64 *data); 61624462549SFlorian Fainelli 61724462549SFlorian Fainelli /* 61819e57c4eSFlorian Fainelli * ethtool Wake-on-LAN 61919e57c4eSFlorian Fainelli */ 62019e57c4eSFlorian Fainelli void (*get_wol)(struct dsa_switch *ds, int port, 62119e57c4eSFlorian Fainelli struct ethtool_wolinfo *w); 62219e57c4eSFlorian Fainelli int (*set_wol)(struct dsa_switch *ds, int port, 62319e57c4eSFlorian Fainelli struct ethtool_wolinfo *w); 62419e57c4eSFlorian Fainelli 62519e57c4eSFlorian Fainelli /* 6260336369dSBrandon Streiff * ethtool timestamp info 6270336369dSBrandon Streiff */ 6280336369dSBrandon Streiff int (*get_ts_info)(struct dsa_switch *ds, int port, 6290336369dSBrandon Streiff struct ethtool_ts_info *ts); 6300336369dSBrandon Streiff 6310336369dSBrandon Streiff /* 63224462549SFlorian Fainelli * Suspend and resume 63324462549SFlorian Fainelli */ 63424462549SFlorian Fainelli int (*suspend)(struct dsa_switch *ds); 63524462549SFlorian Fainelli int (*resume)(struct dsa_switch *ds); 636b2f2af21SFlorian Fainelli 637b2f2af21SFlorian Fainelli /* 638b2f2af21SFlorian Fainelli * Port enable/disable 639b2f2af21SFlorian Fainelli */ 640b2f2af21SFlorian Fainelli int (*port_enable)(struct dsa_switch *ds, int port, 641b2f2af21SFlorian Fainelli struct phy_device *phy); 64275104db0SAndrew Lunn void (*port_disable)(struct dsa_switch *ds, int port); 6437905288fSFlorian Fainelli 6447905288fSFlorian Fainelli /* 64508f50061SVivien Didelot * Port's MAC EEE settings 6467905288fSFlorian Fainelli */ 64708f50061SVivien Didelot int (*set_mac_eee)(struct dsa_switch *ds, int port, 6487905288fSFlorian Fainelli struct ethtool_eee *e); 64908f50061SVivien Didelot int (*get_mac_eee)(struct dsa_switch *ds, int port, 6507905288fSFlorian Fainelli struct ethtool_eee *e); 65151579c3fSGuenter Roeck 6526793abb4SGuenter Roeck /* EEPROM access */ 6536793abb4SGuenter Roeck int (*get_eeprom_len)(struct dsa_switch *ds); 6546793abb4SGuenter Roeck int (*get_eeprom)(struct dsa_switch *ds, 6556793abb4SGuenter Roeck struct ethtool_eeprom *eeprom, u8 *data); 6566793abb4SGuenter Roeck int (*set_eeprom)(struct dsa_switch *ds, 6576793abb4SGuenter Roeck struct ethtool_eeprom *eeprom, u8 *data); 6583d762a0fSGuenter Roeck 6593d762a0fSGuenter Roeck /* 6603d762a0fSGuenter Roeck * Register access. 6613d762a0fSGuenter Roeck */ 6623d762a0fSGuenter Roeck int (*get_regs_len)(struct dsa_switch *ds, int port); 6633d762a0fSGuenter Roeck void (*get_regs)(struct dsa_switch *ds, int port, 6643d762a0fSGuenter Roeck struct ethtool_regs *regs, void *p); 665b73adef6SFlorian Fainelli 666b73adef6SFlorian Fainelli /* 667e358bef7SVladimir Oltean * Upper device tracking. 668e358bef7SVladimir Oltean */ 669e358bef7SVladimir Oltean int (*port_prechangeupper)(struct dsa_switch *ds, int port, 670e358bef7SVladimir Oltean struct netdev_notifier_changeupper_info *info); 671e358bef7SVladimir Oltean 672e358bef7SVladimir Oltean /* 673b73adef6SFlorian Fainelli * Bridge integration 674b73adef6SFlorian Fainelli */ 67534a79f63SVivien Didelot int (*set_ageing_time)(struct dsa_switch *ds, unsigned int msecs); 67671327a4eSVivien Didelot int (*port_bridge_join)(struct dsa_switch *ds, int port, 677a6692754SVivien Didelot struct net_device *bridge); 678f123f2fbSVivien Didelot void (*port_bridge_leave)(struct dsa_switch *ds, int port, 679f123f2fbSVivien Didelot struct net_device *bridge); 68043c44a9fSVivien Didelot void (*port_stp_state_set)(struct dsa_switch *ds, int port, 681b73adef6SFlorian Fainelli u8 state); 682732f794cSVivien Didelot void (*port_fast_age)(struct dsa_switch *ds, int port); 683a8b659e7SVladimir Oltean int (*port_pre_bridge_flags)(struct dsa_switch *ds, int port, 684a8b659e7SVladimir Oltean struct switchdev_brport_flags flags, 685a8b659e7SVladimir Oltean struct netlink_ext_ack *extack); 686a8b659e7SVladimir Oltean int (*port_bridge_flags)(struct dsa_switch *ds, int port, 687a8b659e7SVladimir Oltean struct switchdev_brport_flags flags, 688a8b659e7SVladimir Oltean struct netlink_ext_ack *extack); 689a8b659e7SVladimir Oltean int (*port_set_mrouter)(struct dsa_switch *ds, int port, bool mrouter, 690a8b659e7SVladimir Oltean struct netlink_ext_ack *extack); 6912a778e1bSVivien Didelot 6922a778e1bSVivien Didelot /* 69311149536SVivien Didelot * VLAN support 69411149536SVivien Didelot */ 695fb2dabadSVivien Didelot int (*port_vlan_filtering)(struct dsa_switch *ds, int port, 69689153ed6SVladimir Oltean bool vlan_filtering, 69789153ed6SVladimir Oltean struct netlink_ext_ack *extack); 6981958d581SVladimir Oltean int (*port_vlan_add)(struct dsa_switch *ds, int port, 69931046a5fSVladimir Oltean const struct switchdev_obj_port_vlan *vlan, 70031046a5fSVladimir Oltean struct netlink_ext_ack *extack); 70176e398a6SVivien Didelot int (*port_vlan_del)(struct dsa_switch *ds, int port, 70276e398a6SVivien Didelot const struct switchdev_obj_port_vlan *vlan); 70311149536SVivien Didelot /* 7042a778e1bSVivien Didelot * Forwarding database 7052a778e1bSVivien Didelot */ 7061b6dd556SArkadi Sharshevsky int (*port_fdb_add)(struct dsa_switch *ds, int port, 7076c2c1dcbSArkadi Sharshevsky const unsigned char *addr, u16 vid); 7082a778e1bSVivien Didelot int (*port_fdb_del)(struct dsa_switch *ds, int port, 7096c2c1dcbSArkadi Sharshevsky const unsigned char *addr, u16 vid); 710ea70ba98SVivien Didelot int (*port_fdb_dump)(struct dsa_switch *ds, int port, 7112bedde1aSArkadi Sharshevsky dsa_fdb_dump_cb_t *cb, void *data); 7128df30255SVivien Didelot 7138df30255SVivien Didelot /* 7148df30255SVivien Didelot * Multicast database 7158df30255SVivien Didelot */ 716a52b2da7SVladimir Oltean int (*port_mdb_add)(struct dsa_switch *ds, int port, 7173709aadcSVivien Didelot const struct switchdev_obj_port_mdb *mdb); 7188df30255SVivien Didelot int (*port_mdb_del)(struct dsa_switch *ds, int port, 7198df30255SVivien Didelot const struct switchdev_obj_port_mdb *mdb); 720bf9f2648SFlorian Fainelli /* 721bf9f2648SFlorian Fainelli * RXNFC 722bf9f2648SFlorian Fainelli */ 723bf9f2648SFlorian Fainelli int (*get_rxnfc)(struct dsa_switch *ds, int port, 724bf9f2648SFlorian Fainelli struct ethtool_rxnfc *nfc, u32 *rule_locs); 725bf9f2648SFlorian Fainelli int (*set_rxnfc)(struct dsa_switch *ds, int port, 726bf9f2648SFlorian Fainelli struct ethtool_rxnfc *nfc); 727f50f2127SFlorian Fainelli 728f50f2127SFlorian Fainelli /* 729f50f2127SFlorian Fainelli * TC integration 730f50f2127SFlorian Fainelli */ 731ed11bb1fSVladimir Oltean int (*cls_flower_add)(struct dsa_switch *ds, int port, 732ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, bool ingress); 733ed11bb1fSVladimir Oltean int (*cls_flower_del)(struct dsa_switch *ds, int port, 734ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, bool ingress); 735ed11bb1fSVladimir Oltean int (*cls_flower_stats)(struct dsa_switch *ds, int port, 736ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, bool ingress); 737f50f2127SFlorian Fainelli int (*port_mirror_add)(struct dsa_switch *ds, int port, 738f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror, 739f50f2127SFlorian Fainelli bool ingress); 740f50f2127SFlorian Fainelli void (*port_mirror_del)(struct dsa_switch *ds, int port, 741f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror); 74234297176SVladimir Oltean int (*port_policer_add)(struct dsa_switch *ds, int port, 74334297176SVladimir Oltean struct dsa_mall_policer_tc_entry *policer); 74434297176SVladimir Oltean void (*port_policer_del)(struct dsa_switch *ds, int port); 74547d23af2SVladimir Oltean int (*port_setup_tc)(struct dsa_switch *ds, int port, 74647d23af2SVladimir Oltean enum tc_setup_type type, void *type_data); 74740ef2c93SVivien Didelot 74840ef2c93SVivien Didelot /* 74940ef2c93SVivien Didelot * Cross-chip operations 75040ef2c93SVivien Didelot */ 751f66a6a69SVladimir Oltean int (*crosschip_bridge_join)(struct dsa_switch *ds, int tree_index, 752f66a6a69SVladimir Oltean int sw_index, int port, 753f66a6a69SVladimir Oltean struct net_device *br); 754f66a6a69SVladimir Oltean void (*crosschip_bridge_leave)(struct dsa_switch *ds, int tree_index, 755f66a6a69SVladimir Oltean int sw_index, int port, 756f66a6a69SVladimir Oltean struct net_device *br); 757058102a6STobias Waldekranz int (*crosschip_lag_change)(struct dsa_switch *ds, int sw_index, 758058102a6STobias Waldekranz int port); 759058102a6STobias Waldekranz int (*crosschip_lag_join)(struct dsa_switch *ds, int sw_index, 760058102a6STobias Waldekranz int port, struct net_device *lag, 761058102a6STobias Waldekranz struct netdev_lag_upper_info *info); 762058102a6STobias Waldekranz int (*crosschip_lag_leave)(struct dsa_switch *ds, int sw_index, 763058102a6STobias Waldekranz int port, struct net_device *lag); 7640336369dSBrandon Streiff 7650336369dSBrandon Streiff /* 7660336369dSBrandon Streiff * PTP functionality 7670336369dSBrandon Streiff */ 7680336369dSBrandon Streiff int (*port_hwtstamp_get)(struct dsa_switch *ds, int port, 7690336369dSBrandon Streiff struct ifreq *ifr); 7700336369dSBrandon Streiff int (*port_hwtstamp_set)(struct dsa_switch *ds, int port, 7710336369dSBrandon Streiff struct ifreq *ifr); 7725c5416f5SYangbo Lu void (*port_txtstamp)(struct dsa_switch *ds, int port, 7735c5416f5SYangbo Lu struct sk_buff *skb); 77490af1059SBrandon Streiff bool (*port_rxtstamp)(struct dsa_switch *ds, int port, 77590af1059SBrandon Streiff struct sk_buff *skb, unsigned int type); 77697a69a0dSVladimir Oltean 7770f06b855SAndrew Lunn /* Devlink parameters, etc */ 7786b297524SAndrew Lunn int (*devlink_param_get)(struct dsa_switch *ds, u32 id, 7796b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx); 7806b297524SAndrew Lunn int (*devlink_param_set)(struct dsa_switch *ds, u32 id, 7816b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx); 7820f06b855SAndrew Lunn int (*devlink_info_get)(struct dsa_switch *ds, 7830f06b855SAndrew Lunn struct devlink_info_req *req, 7840f06b855SAndrew Lunn struct netlink_ext_ack *extack); 7852a6ef763SVladimir Oltean int (*devlink_sb_pool_get)(struct dsa_switch *ds, 7862a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index, 7872a6ef763SVladimir Oltean struct devlink_sb_pool_info *pool_info); 7882a6ef763SVladimir Oltean int (*devlink_sb_pool_set)(struct dsa_switch *ds, unsigned int sb_index, 7892a6ef763SVladimir Oltean u16 pool_index, u32 size, 7902a6ef763SVladimir Oltean enum devlink_sb_threshold_type threshold_type, 7912a6ef763SVladimir Oltean struct netlink_ext_ack *extack); 7922a6ef763SVladimir Oltean int (*devlink_sb_port_pool_get)(struct dsa_switch *ds, int port, 7932a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index, 7942a6ef763SVladimir Oltean u32 *p_threshold); 7952a6ef763SVladimir Oltean int (*devlink_sb_port_pool_set)(struct dsa_switch *ds, int port, 7962a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index, 7972a6ef763SVladimir Oltean u32 threshold, 7982a6ef763SVladimir Oltean struct netlink_ext_ack *extack); 7992a6ef763SVladimir Oltean int (*devlink_sb_tc_pool_bind_get)(struct dsa_switch *ds, int port, 8002a6ef763SVladimir Oltean unsigned int sb_index, u16 tc_index, 8012a6ef763SVladimir Oltean enum devlink_sb_pool_type pool_type, 8022a6ef763SVladimir Oltean u16 *p_pool_index, u32 *p_threshold); 8032a6ef763SVladimir Oltean int (*devlink_sb_tc_pool_bind_set)(struct dsa_switch *ds, int port, 8042a6ef763SVladimir Oltean unsigned int sb_index, u16 tc_index, 8052a6ef763SVladimir Oltean enum devlink_sb_pool_type pool_type, 8062a6ef763SVladimir Oltean u16 pool_index, u32 threshold, 8072a6ef763SVladimir Oltean struct netlink_ext_ack *extack); 8082a6ef763SVladimir Oltean int (*devlink_sb_occ_snapshot)(struct dsa_switch *ds, 8092a6ef763SVladimir Oltean unsigned int sb_index); 8102a6ef763SVladimir Oltean int (*devlink_sb_occ_max_clear)(struct dsa_switch *ds, 8112a6ef763SVladimir Oltean unsigned int sb_index); 8122a6ef763SVladimir Oltean int (*devlink_sb_occ_port_pool_get)(struct dsa_switch *ds, int port, 8132a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index, 8142a6ef763SVladimir Oltean u32 *p_cur, u32 *p_max); 8152a6ef763SVladimir Oltean int (*devlink_sb_occ_tc_port_bind_get)(struct dsa_switch *ds, int port, 8162a6ef763SVladimir Oltean unsigned int sb_index, u16 tc_index, 8172a6ef763SVladimir Oltean enum devlink_sb_pool_type pool_type, 8182a6ef763SVladimir Oltean u32 *p_cur, u32 *p_max); 819bfcb8132SVladimir Oltean 820bfcb8132SVladimir Oltean /* 821bfcb8132SVladimir Oltean * MTU change functionality. Switches can also adjust their MRU through 822bfcb8132SVladimir Oltean * this method. By MTU, one understands the SDU (L2 payload) length. 823bfcb8132SVladimir Oltean * If the switch needs to account for the DSA tag on the CPU port, this 824ab88d64aSRandy Dunlap * method needs to do so privately. 825bfcb8132SVladimir Oltean */ 826bfcb8132SVladimir Oltean int (*port_change_mtu)(struct dsa_switch *ds, int port, 827bfcb8132SVladimir Oltean int new_mtu); 828bfcb8132SVladimir Oltean int (*port_max_mtu)(struct dsa_switch *ds, int port); 829058102a6STobias Waldekranz 830058102a6STobias Waldekranz /* 831058102a6STobias Waldekranz * LAG integration 832058102a6STobias Waldekranz */ 833058102a6STobias Waldekranz int (*port_lag_change)(struct dsa_switch *ds, int port); 834058102a6STobias Waldekranz int (*port_lag_join)(struct dsa_switch *ds, int port, 835058102a6STobias Waldekranz struct net_device *lag, 836058102a6STobias Waldekranz struct netdev_lag_upper_info *info); 837058102a6STobias Waldekranz int (*port_lag_leave)(struct dsa_switch *ds, int port, 838058102a6STobias Waldekranz struct net_device *lag); 83918596f50SGeorge McCollister 84018596f50SGeorge McCollister /* 84118596f50SGeorge McCollister * HSR integration 84218596f50SGeorge McCollister */ 84318596f50SGeorge McCollister int (*port_hsr_join)(struct dsa_switch *ds, int port, 84418596f50SGeorge McCollister struct net_device *hsr); 84518596f50SGeorge McCollister int (*port_hsr_leave)(struct dsa_switch *ds, int port, 84618596f50SGeorge McCollister struct net_device *hsr); 847c595c433SHoratiu Vultur 848c595c433SHoratiu Vultur /* 849c595c433SHoratiu Vultur * MRP integration 850c595c433SHoratiu Vultur */ 851c595c433SHoratiu Vultur int (*port_mrp_add)(struct dsa_switch *ds, int port, 852c595c433SHoratiu Vultur const struct switchdev_obj_mrp *mrp); 853c595c433SHoratiu Vultur int (*port_mrp_del)(struct dsa_switch *ds, int port, 854c595c433SHoratiu Vultur const struct switchdev_obj_mrp *mrp); 855c595c433SHoratiu Vultur int (*port_mrp_add_ring_role)(struct dsa_switch *ds, int port, 856c595c433SHoratiu Vultur const struct switchdev_obj_ring_role_mrp *mrp); 857c595c433SHoratiu Vultur int (*port_mrp_del_ring_role)(struct dsa_switch *ds, int port, 858c595c433SHoratiu Vultur const struct switchdev_obj_ring_role_mrp *mrp); 8596b297524SAndrew Lunn }; 8606b297524SAndrew Lunn 8616b297524SAndrew Lunn #define DSA_DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes) \ 8626b297524SAndrew Lunn DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, \ 8636b297524SAndrew Lunn dsa_devlink_param_get, dsa_devlink_param_set, NULL) 8646b297524SAndrew Lunn 8656b297524SAndrew Lunn int dsa_devlink_param_get(struct devlink *dl, u32 id, 8666b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx); 8676b297524SAndrew Lunn int dsa_devlink_param_set(struct devlink *dl, u32 id, 8686b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx); 8696b297524SAndrew Lunn int dsa_devlink_params_register(struct dsa_switch *ds, 8706b297524SAndrew Lunn const struct devlink_param *params, 8716b297524SAndrew Lunn size_t params_count); 8726b297524SAndrew Lunn void dsa_devlink_params_unregister(struct dsa_switch *ds, 8736b297524SAndrew Lunn const struct devlink_param *params, 8746b297524SAndrew Lunn size_t params_count); 8755cd73fbdSAndrew Lunn int dsa_devlink_resource_register(struct dsa_switch *ds, 8765cd73fbdSAndrew Lunn const char *resource_name, 8775cd73fbdSAndrew Lunn u64 resource_size, 8785cd73fbdSAndrew Lunn u64 resource_id, 8795cd73fbdSAndrew Lunn u64 parent_resource_id, 8805cd73fbdSAndrew Lunn const struct devlink_resource_size_params *size_params); 8815cd73fbdSAndrew Lunn 8825cd73fbdSAndrew Lunn void dsa_devlink_resources_unregister(struct dsa_switch *ds); 8835cd73fbdSAndrew Lunn 8845cd73fbdSAndrew Lunn void dsa_devlink_resource_occ_get_register(struct dsa_switch *ds, 8855cd73fbdSAndrew Lunn u64 resource_id, 8865cd73fbdSAndrew Lunn devlink_resource_occ_get_t *occ_get, 8875cd73fbdSAndrew Lunn void *occ_get_priv); 8885cd73fbdSAndrew Lunn void dsa_devlink_resource_occ_get_unregister(struct dsa_switch *ds, 8895cd73fbdSAndrew Lunn u64 resource_id); 89097c82c23SAndrew Lunn struct devlink_region * 89197c82c23SAndrew Lunn dsa_devlink_region_create(struct dsa_switch *ds, 89297c82c23SAndrew Lunn const struct devlink_region_ops *ops, 89397c82c23SAndrew Lunn u32 region_max_snapshots, u64 region_size); 89408156ba4SAndrew Lunn struct devlink_region * 89508156ba4SAndrew Lunn dsa_devlink_port_region_create(struct dsa_switch *ds, 89608156ba4SAndrew Lunn int port, 89708156ba4SAndrew Lunn const struct devlink_port_region_ops *ops, 89808156ba4SAndrew Lunn u32 region_max_snapshots, u64 region_size); 89997c82c23SAndrew Lunn void dsa_devlink_region_destroy(struct devlink_region *region); 90097c82c23SAndrew Lunn 901e1eea811SVladimir Oltean struct dsa_port *dsa_port_from_netdev(struct net_device *netdev); 9025cd73fbdSAndrew Lunn 9036b297524SAndrew Lunn struct dsa_devlink_priv { 9046b297524SAndrew Lunn struct dsa_switch *ds; 905c8f0b869SBen Hutchings }; 906c8f0b869SBen Hutchings 907ccc3e6b0SAndrew Lunn static inline struct dsa_switch *dsa_devlink_to_ds(struct devlink *dl) 908ccc3e6b0SAndrew Lunn { 909ccc3e6b0SAndrew Lunn struct dsa_devlink_priv *dl_priv = devlink_priv(dl); 910ccc3e6b0SAndrew Lunn 911ccc3e6b0SAndrew Lunn return dl_priv->ds; 912ccc3e6b0SAndrew Lunn } 913ccc3e6b0SAndrew Lunn 9147d1e2a10SAndrew Lunn static inline 9157d1e2a10SAndrew Lunn struct dsa_switch *dsa_devlink_port_to_ds(struct devlink_port *port) 9167d1e2a10SAndrew Lunn { 9177d1e2a10SAndrew Lunn struct devlink *dl = port->devlink; 9187d1e2a10SAndrew Lunn struct dsa_devlink_priv *dl_priv = devlink_priv(dl); 9197d1e2a10SAndrew Lunn 9207d1e2a10SAndrew Lunn return dl_priv->ds; 9217d1e2a10SAndrew Lunn } 9227d1e2a10SAndrew Lunn 9237d1e2a10SAndrew Lunn static inline int dsa_devlink_port_to_port(struct devlink_port *port) 9247d1e2a10SAndrew Lunn { 9257d1e2a10SAndrew Lunn return port->index; 9267d1e2a10SAndrew Lunn } 9277d1e2a10SAndrew Lunn 928ab3d408dSFlorian Fainelli struct dsa_switch_driver { 929ab3d408dSFlorian Fainelli struct list_head list; 930a82f67afSFlorian Fainelli const struct dsa_switch_ops *ops; 931ab3d408dSFlorian Fainelli }; 932ab3d408dSFlorian Fainelli 93314b89f36SFlorian Fainelli struct net_device *dsa_dev_to_net_device(struct device *dev); 934c8f0b869SBen Hutchings 93573a7ece8SVivien Didelot /* Keep inline for faster access in hot path */ 9369eb8eff0SVladimir Oltean static inline bool netdev_uses_dsa(const struct net_device *dev) 937c6e970a0SAndrew Lunn { 938c6e970a0SAndrew Lunn #if IS_ENABLED(CONFIG_NET_DSA) 939717ffbfbSVivien Didelot return dev->dsa_ptr && dev->dsa_ptr->rcv; 940c6e970a0SAndrew Lunn #endif 941c6e970a0SAndrew Lunn return false; 942c6e970a0SAndrew Lunn } 943c6e970a0SAndrew Lunn 944cc1939e4SVladimir Oltean static inline bool dsa_can_decode(const struct sk_buff *skb, 945cc1939e4SVladimir Oltean struct net_device *dev) 946cc1939e4SVladimir Oltean { 947cc1939e4SVladimir Oltean #if IS_ENABLED(CONFIG_NET_DSA) 948cc1939e4SVladimir Oltean return !dev->dsa_ptr->filter || dev->dsa_ptr->filter(skb, dev); 949cc1939e4SVladimir Oltean #endif 950cc1939e4SVladimir Oltean return false; 951cc1939e4SVladimir Oltean } 952cc1939e4SVladimir Oltean 9539790cf20SVladimir Oltean /* All DSA tags that push the EtherType to the right (basically all except tail 9549790cf20SVladimir Oltean * tags, which don't break dissection) can be treated the same from the 9559790cf20SVladimir Oltean * perspective of the flow dissector. 9569790cf20SVladimir Oltean * 9579790cf20SVladimir Oltean * We need to return: 9589790cf20SVladimir Oltean * - offset: the (B - A) difference between: 9599790cf20SVladimir Oltean * A. the position of the real EtherType and 9609790cf20SVladimir Oltean * B. the current skb->data (aka ETH_HLEN bytes into the frame, aka 2 bytes 9619790cf20SVladimir Oltean * after the normal EtherType was supposed to be) 9629790cf20SVladimir Oltean * The offset in bytes is exactly equal to the tagger overhead (and half of 9639790cf20SVladimir Oltean * that, in __be16 shorts). 9649790cf20SVladimir Oltean * 9659790cf20SVladimir Oltean * - proto: the value of the real EtherType. 9669790cf20SVladimir Oltean */ 9679790cf20SVladimir Oltean static inline void dsa_tag_generic_flow_dissect(const struct sk_buff *skb, 9689790cf20SVladimir Oltean __be16 *proto, int *offset) 9699790cf20SVladimir Oltean { 9709790cf20SVladimir Oltean #if IS_ENABLED(CONFIG_NET_DSA) 9719790cf20SVladimir Oltean const struct dsa_device_ops *ops = skb->dev->dsa_ptr->tag_ops; 9724e500251SVladimir Oltean int tag_len = ops->needed_headroom; 9739790cf20SVladimir Oltean 9749790cf20SVladimir Oltean *offset = tag_len; 9759790cf20SVladimir Oltean *proto = ((__be16 *)skb->data)[(tag_len / 2) - 1]; 9769790cf20SVladimir Oltean #endif 9779790cf20SVladimir Oltean } 9789790cf20SVladimir Oltean 9794cfab356SFlorian Fainelli #if IS_ENABLED(CONFIG_NET_DSA) 9804cfab356SFlorian Fainelli static inline int __dsa_netdevice_ops_check(struct net_device *dev) 9814cfab356SFlorian Fainelli { 9824cfab356SFlorian Fainelli int err = -EOPNOTSUPP; 9834cfab356SFlorian Fainelli 9844cfab356SFlorian Fainelli if (!dev->dsa_ptr) 9854cfab356SFlorian Fainelli return err; 9864cfab356SFlorian Fainelli 9874cfab356SFlorian Fainelli if (!dev->dsa_ptr->netdev_ops) 9884cfab356SFlorian Fainelli return err; 9894cfab356SFlorian Fainelli 9904cfab356SFlorian Fainelli return 0; 9914cfab356SFlorian Fainelli } 9924cfab356SFlorian Fainelli 9934cfab356SFlorian Fainelli static inline int dsa_ndo_do_ioctl(struct net_device *dev, struct ifreq *ifr, 9944cfab356SFlorian Fainelli int cmd) 9954cfab356SFlorian Fainelli { 9964cfab356SFlorian Fainelli const struct dsa_netdevice_ops *ops; 9974cfab356SFlorian Fainelli int err; 9984cfab356SFlorian Fainelli 9994cfab356SFlorian Fainelli err = __dsa_netdevice_ops_check(dev); 10004cfab356SFlorian Fainelli if (err) 10014cfab356SFlorian Fainelli return err; 10024cfab356SFlorian Fainelli 10034cfab356SFlorian Fainelli ops = dev->dsa_ptr->netdev_ops; 10044cfab356SFlorian Fainelli 10054cfab356SFlorian Fainelli return ops->ndo_do_ioctl(dev, ifr, cmd); 10064cfab356SFlorian Fainelli } 10074cfab356SFlorian Fainelli #else 10084cfab356SFlorian Fainelli static inline int dsa_ndo_do_ioctl(struct net_device *dev, struct ifreq *ifr, 10094cfab356SFlorian Fainelli int cmd) 10104cfab356SFlorian Fainelli { 10114cfab356SFlorian Fainelli return -EOPNOTSUPP; 10124cfab356SFlorian Fainelli } 10134cfab356SFlorian Fainelli #endif 10144cfab356SFlorian Fainelli 101583c0afaeSAndrew Lunn void dsa_unregister_switch(struct dsa_switch *ds); 101623c9ee49SVivien Didelot int dsa_register_switch(struct dsa_switch *ds); 10173b7bc1f0SVladimir Oltean struct dsa_switch *dsa_switch_find(int tree_index, int sw_index); 1018ea825e70SFlorian Fainelli #ifdef CONFIG_PM_SLEEP 1019ea825e70SFlorian Fainelli int dsa_switch_suspend(struct dsa_switch *ds); 1020ea825e70SFlorian Fainelli int dsa_switch_resume(struct dsa_switch *ds); 1021ea825e70SFlorian Fainelli #else 1022ea825e70SFlorian Fainelli static inline int dsa_switch_suspend(struct dsa_switch *ds) 1023ea825e70SFlorian Fainelli { 1024ea825e70SFlorian Fainelli return 0; 1025ea825e70SFlorian Fainelli } 1026ea825e70SFlorian Fainelli static inline int dsa_switch_resume(struct dsa_switch *ds) 1027ea825e70SFlorian Fainelli { 1028ea825e70SFlorian Fainelli return 0; 1029ea825e70SFlorian Fainelli } 1030ea825e70SFlorian Fainelli #endif /* CONFIG_PM_SLEEP */ 1031ea825e70SFlorian Fainelli 103260724d4bSFlorian Fainelli #if IS_ENABLED(CONFIG_NET_DSA) 1033a5e3c9baSVladimir Oltean bool dsa_slave_dev_check(const struct net_device *dev); 103460724d4bSFlorian Fainelli #else 1035a5e3c9baSVladimir Oltean static inline bool dsa_slave_dev_check(const struct net_device *dev) 1036a5e3c9baSVladimir Oltean { 1037a5e3c9baSVladimir Oltean return false; 1038a5e3c9baSVladimir Oltean } 103960724d4bSFlorian Fainelli #endif 104060724d4bSFlorian Fainelli 104197a69a0dSVladimir Oltean netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, struct net_device *dev); 1042cf963573SFlorian Fainelli int dsa_port_get_phy_strings(struct dsa_port *dp, uint8_t *data); 1043cf963573SFlorian Fainelli int dsa_port_get_ethtool_phy_stats(struct dsa_port *dp, uint64_t *data); 1044cf963573SFlorian Fainelli int dsa_port_get_phy_sset_count(struct dsa_port *dp); 104511d8f3ddSFlorian Fainelli void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up); 1046cf963573SFlorian Fainelli 1047d3b8c049SAndrew Lunn struct dsa_tag_driver { 1048d3b8c049SAndrew Lunn const struct dsa_device_ops *ops; 1049d3b8c049SAndrew Lunn struct list_head list; 1050d3b8c049SAndrew Lunn struct module *owner; 1051d3b8c049SAndrew Lunn }; 1052d3b8c049SAndrew Lunn 1053d3b8c049SAndrew Lunn void dsa_tag_drivers_register(struct dsa_tag_driver *dsa_tag_driver_array[], 1054d3b8c049SAndrew Lunn unsigned int count, 1055d3b8c049SAndrew Lunn struct module *owner); 1056d3b8c049SAndrew Lunn void dsa_tag_drivers_unregister(struct dsa_tag_driver *dsa_tag_driver_array[], 1057d3b8c049SAndrew Lunn unsigned int count); 1058d3b8c049SAndrew Lunn 1059d3b8c049SAndrew Lunn #define dsa_tag_driver_module_drivers(__dsa_tag_drivers_array, __count) \ 1060d3b8c049SAndrew Lunn static int __init dsa_tag_driver_module_init(void) \ 1061d3b8c049SAndrew Lunn { \ 1062d3b8c049SAndrew Lunn dsa_tag_drivers_register(__dsa_tag_drivers_array, __count, \ 1063d3b8c049SAndrew Lunn THIS_MODULE); \ 1064d3b8c049SAndrew Lunn return 0; \ 1065d3b8c049SAndrew Lunn } \ 1066d3b8c049SAndrew Lunn module_init(dsa_tag_driver_module_init); \ 1067d3b8c049SAndrew Lunn \ 1068d3b8c049SAndrew Lunn static void __exit dsa_tag_driver_module_exit(void) \ 1069d3b8c049SAndrew Lunn { \ 1070d3b8c049SAndrew Lunn dsa_tag_drivers_unregister(__dsa_tag_drivers_array, __count); \ 1071d3b8c049SAndrew Lunn } \ 1072d3b8c049SAndrew Lunn module_exit(dsa_tag_driver_module_exit) 1073d3b8c049SAndrew Lunn 1074d3b8c049SAndrew Lunn /** 1075d3b8c049SAndrew Lunn * module_dsa_tag_drivers() - Helper macro for registering DSA tag 1076d3b8c049SAndrew Lunn * drivers 1077d3b8c049SAndrew Lunn * @__ops_array: Array of tag driver strucutres 1078d3b8c049SAndrew Lunn * 1079d3b8c049SAndrew Lunn * Helper macro for DSA tag drivers which do not do anything special 1080d3b8c049SAndrew Lunn * in module init/exit. Each module may only use this macro once, and 1081d3b8c049SAndrew Lunn * calling it replaces module_init() and module_exit(). 1082d3b8c049SAndrew Lunn */ 1083d3b8c049SAndrew Lunn #define module_dsa_tag_drivers(__ops_array) \ 1084d3b8c049SAndrew Lunn dsa_tag_driver_module_drivers(__ops_array, ARRAY_SIZE(__ops_array)) 1085d3b8c049SAndrew Lunn 1086d3b8c049SAndrew Lunn #define DSA_TAG_DRIVER_NAME(__ops) dsa_tag_driver ## _ ## __ops 1087d3b8c049SAndrew Lunn 1088d3b8c049SAndrew Lunn /* Create a static structure we can build a linked list of dsa_tag 1089d3b8c049SAndrew Lunn * drivers 1090d3b8c049SAndrew Lunn */ 1091d3b8c049SAndrew Lunn #define DSA_TAG_DRIVER(__ops) \ 1092d3b8c049SAndrew Lunn static struct dsa_tag_driver DSA_TAG_DRIVER_NAME(__ops) = { \ 1093d3b8c049SAndrew Lunn .ops = &__ops, \ 1094d3b8c049SAndrew Lunn } 1095d3b8c049SAndrew Lunn 1096d3b8c049SAndrew Lunn /** 1097d3b8c049SAndrew Lunn * module_dsa_tag_driver() - Helper macro for registering a single DSA tag 1098d3b8c049SAndrew Lunn * driver 1099d3b8c049SAndrew Lunn * @__ops: Single tag driver structures 1100d3b8c049SAndrew Lunn * 1101d3b8c049SAndrew Lunn * Helper macro for DSA tag drivers which do not do anything special 1102d3b8c049SAndrew Lunn * in module init/exit. Each module may only use this macro once, and 1103d3b8c049SAndrew Lunn * calling it replaces module_init() and module_exit(). 1104d3b8c049SAndrew Lunn */ 1105d3b8c049SAndrew Lunn #define module_dsa_tag_driver(__ops) \ 1106d3b8c049SAndrew Lunn DSA_TAG_DRIVER(__ops); \ 1107d3b8c049SAndrew Lunn \ 1108d3b8c049SAndrew Lunn static struct dsa_tag_driver *dsa_tag_driver_array[] = { \ 1109d3b8c049SAndrew Lunn &DSA_TAG_DRIVER_NAME(__ops) \ 1110d3b8c049SAndrew Lunn }; \ 1111d3b8c049SAndrew Lunn module_dsa_tag_drivers(dsa_tag_driver_array) 111291da11f8SLennert Buytenhek #endif 1113d3b8c049SAndrew Lunn 1114