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 550b42f033SAndrew Lunn 56ac7a04c3SFlorian Fainelli enum dsa_tag_protocol { 570b42f033SAndrew Lunn DSA_TAG_PROTO_NONE = DSA_TAG_PROTO_NONE_VALUE, 580b42f033SAndrew Lunn DSA_TAG_PROTO_BRCM = DSA_TAG_PROTO_BRCM_VALUE, 59964dbf18SÁlvaro Fernández Rojas DSA_TAG_PROTO_BRCM_LEGACY = DSA_TAG_PROTO_BRCM_LEGACY_VALUE, 600b42f033SAndrew Lunn DSA_TAG_PROTO_BRCM_PREPEND = DSA_TAG_PROTO_BRCM_PREPEND_VALUE, 610b42f033SAndrew Lunn DSA_TAG_PROTO_DSA = DSA_TAG_PROTO_DSA_VALUE, 620b42f033SAndrew Lunn DSA_TAG_PROTO_EDSA = DSA_TAG_PROTO_EDSA_VALUE, 630b42f033SAndrew Lunn DSA_TAG_PROTO_GSWIP = DSA_TAG_PROTO_GSWIP_VALUE, 640b42f033SAndrew Lunn DSA_TAG_PROTO_KSZ9477 = DSA_TAG_PROTO_KSZ9477_VALUE, 650b42f033SAndrew Lunn DSA_TAG_PROTO_KSZ9893 = DSA_TAG_PROTO_KSZ9893_VALUE, 660b42f033SAndrew Lunn DSA_TAG_PROTO_LAN9303 = DSA_TAG_PROTO_LAN9303_VALUE, 670b42f033SAndrew Lunn DSA_TAG_PROTO_MTK = DSA_TAG_PROTO_MTK_VALUE, 680b42f033SAndrew Lunn DSA_TAG_PROTO_QCA = DSA_TAG_PROTO_QCA_VALUE, 690b42f033SAndrew Lunn DSA_TAG_PROTO_TRAILER = DSA_TAG_PROTO_TRAILER_VALUE, 70f9bbe447SVladimir Oltean DSA_TAG_PROTO_8021Q = DSA_TAG_PROTO_8021Q_VALUE, 71227d07a0SVladimir Oltean DSA_TAG_PROTO_SJA1105 = DSA_TAG_PROTO_SJA1105_VALUE, 72016e43a2STristram Ha DSA_TAG_PROTO_KSZ8795 = DSA_TAG_PROTO_KSZ8795_VALUE, 738dce89aaSVladimir Oltean DSA_TAG_PROTO_OCELOT = DSA_TAG_PROTO_OCELOT_VALUE, 7448fda74fSOleksij Rempel DSA_TAG_PROTO_AR9331 = DSA_TAG_PROTO_AR9331_VALUE, 75efd7fe68SLinus Walleij DSA_TAG_PROTO_RTL4_A = DSA_TAG_PROTO_RTL4_A_VALUE, 7601ef09caSKurt Kanzenbach DSA_TAG_PROTO_HELLCREEK = DSA_TAG_PROTO_HELLCREEK_VALUE, 7754a52823SGeorge McCollister DSA_TAG_PROTO_XRS700X = DSA_TAG_PROTO_XRS700X_VALUE, 787c83a7c5SVladimir Oltean DSA_TAG_PROTO_OCELOT_8021Q = DSA_TAG_PROTO_OCELOT_8021Q_VALUE, 797c4bb540SVladimir Oltean DSA_TAG_PROTO_SEVILLE = DSA_TAG_PROTO_SEVILLE_VALUE, 804913b8ebSVladimir Oltean DSA_TAG_PROTO_SJA1110 = DSA_TAG_PROTO_SJA1110_VALUE, 811521d5adSAlvin Šipraga DSA_TAG_PROTO_RTL8_4 = DSA_TAG_PROTO_RTL8_4_VALUE, 82ac7a04c3SFlorian Fainelli }; 835037d532SFlorian Fainelli 8490af1059SBrandon Streiff struct dsa_switch; 853e8a72d1SFlorian Fainelli 8668277a2cSJohn Crispin struct dsa_device_ops { 8768277a2cSJohn Crispin struct sk_buff *(*xmit)(struct sk_buff *skb, struct net_device *dev); 8829a097b7SVladimir Oltean struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev); 892e8cb1b3SVladimir Oltean void (*flow_dissect)(const struct sk_buff *skb, __be16 *proto, 90598a9680SJohn Crispin int *offset); 917f297314SVladimir Oltean int (*connect)(struct dsa_switch *ds); 927f297314SVladimir Oltean void (*disconnect)(struct dsa_switch *ds); 934e500251SVladimir Oltean unsigned int needed_headroom; 944e500251SVladimir Oltean unsigned int needed_tailroom; 95875138f8SAndrew Lunn const char *name; 96056eed2fSAndrew Lunn enum dsa_tag_protocol proto; 97c3975400SVladimir Oltean /* Some tagging protocols either mangle or shift the destination MAC 98c3975400SVladimir Oltean * address, in which case the DSA master would drop packets on ingress 99c3975400SVladimir Oltean * if what it understands out of the destination MAC address is not in 100c3975400SVladimir Oltean * its RX filter. 101c3975400SVladimir Oltean */ 102c3975400SVladimir Oltean bool promisc_on_master; 10368277a2cSJohn Crispin }; 10468277a2cSJohn Crispin 1054cfab356SFlorian Fainelli /* This structure defines the control interfaces that are overlayed by the 1064cfab356SFlorian Fainelli * DSA layer on top of the DSA CPU/management net_device instance. This is 1074cfab356SFlorian Fainelli * used by the core net_device layer while calling various net_device_ops 1084cfab356SFlorian Fainelli * function pointers. 1094cfab356SFlorian Fainelli */ 1104cfab356SFlorian Fainelli struct dsa_netdevice_ops { 111a7605370SArnd Bergmann int (*ndo_eth_ioctl)(struct net_device *dev, struct ifreq *ifr, 1124cfab356SFlorian Fainelli int cmd); 1134cfab356SFlorian Fainelli }; 1144cfab356SFlorian Fainelli 1150b42f033SAndrew Lunn #define DSA_TAG_DRIVER_ALIAS "dsa_tag-" 1160b42f033SAndrew Lunn #define MODULE_ALIAS_DSA_TAG_DRIVER(__proto) \ 1170b42f033SAndrew Lunn MODULE_ALIAS(DSA_TAG_DRIVER_ALIAS __stringify(__proto##_VALUE)) 1180b42f033SAndrew Lunn 119cf50dcc2SBen Hutchings struct dsa_switch_tree { 12083c0afaeSAndrew Lunn struct list_head list; 12183c0afaeSAndrew Lunn 122b035c88cSVladimir Oltean /* List of switch ports */ 123b035c88cSVladimir Oltean struct list_head ports; 124b035c88cSVladimir Oltean 125f515f192SVivien Didelot /* Notifier chain for switch-wide events */ 126f515f192SVivien Didelot struct raw_notifier_head nh; 127f515f192SVivien Didelot 12883c0afaeSAndrew Lunn /* Tree identifier */ 12949463b7fSVivien Didelot unsigned int index; 13083c0afaeSAndrew Lunn 13183c0afaeSAndrew Lunn /* Number of switches attached to this tree */ 13283c0afaeSAndrew Lunn struct kref refcount; 13383c0afaeSAndrew Lunn 134b035c88cSVladimir Oltean /* Maps offloaded LAG netdevs to a zero-based linear ID for 135b035c88cSVladimir Oltean * drivers that need it. 136b035c88cSVladimir Oltean */ 137b035c88cSVladimir Oltean struct net_device **lags; 138b035c88cSVladimir Oltean 139357f203bSVladimir Oltean /* Tagging protocol operations */ 140357f203bSVladimir Oltean const struct dsa_device_ops *tag_ops; 141357f203bSVladimir Oltean 142deff7107STobias Waldekranz /* Default tagging protocol preferred by the switches in this 143deff7107STobias Waldekranz * tree. 144deff7107STobias Waldekranz */ 145deff7107STobias Waldekranz enum dsa_tag_protocol default_proto; 146deff7107STobias Waldekranz 1474b026e82SVladimir Oltean /* Has this tree been applied to the hardware? */ 1484b026e82SVladimir Oltean bool setup; 1494b026e82SVladimir Oltean 150cf50dcc2SBen Hutchings /* 151cf50dcc2SBen Hutchings * Configuration data for the platform device that owns 152cf50dcc2SBen Hutchings * this dsa switch tree instance. 153cf50dcc2SBen Hutchings */ 154cf50dcc2SBen Hutchings struct dsa_platform_data *pd; 155cf85d08fSLennert Buytenhek 156c5f51765SVivien Didelot /* List of DSA links composing the routing table */ 157c5f51765SVivien Didelot struct list_head rtable; 158058102a6STobias Waldekranz 159b035c88cSVladimir Oltean /* Length of "lags" array */ 160058102a6STobias Waldekranz unsigned int lags_len; 1615b22d366SVladimir Oltean 1625b22d366SVladimir Oltean /* Track the largest switch index within a tree */ 1635b22d366SVladimir Oltean unsigned int last_switch; 164cf50dcc2SBen Hutchings }; 165cf50dcc2SBen Hutchings 166058102a6STobias Waldekranz #define dsa_lags_foreach_id(_id, _dst) \ 167058102a6STobias Waldekranz for ((_id) = 0; (_id) < (_dst)->lags_len; (_id)++) \ 168058102a6STobias Waldekranz if ((_dst)->lags[(_id)]) 169058102a6STobias Waldekranz 170058102a6STobias Waldekranz #define dsa_lag_foreach_port(_dp, _dst, _lag) \ 171058102a6STobias Waldekranz list_for_each_entry((_dp), &(_dst)->ports, list) \ 172058102a6STobias Waldekranz if ((_dp)->lag_dev == (_lag)) 173058102a6STobias Waldekranz 17418596f50SGeorge McCollister #define dsa_hsr_foreach_port(_dp, _ds, _hsr) \ 17518596f50SGeorge McCollister list_for_each_entry((_dp), &(_ds)->dst->ports, list) \ 17618596f50SGeorge McCollister if ((_dp)->ds == (_ds) && (_dp)->hsr_dev == (_hsr)) 17718596f50SGeorge McCollister 178058102a6STobias Waldekranz static inline struct net_device *dsa_lag_dev(struct dsa_switch_tree *dst, 179058102a6STobias Waldekranz unsigned int id) 180058102a6STobias Waldekranz { 181058102a6STobias Waldekranz return dst->lags[id]; 182058102a6STobias Waldekranz } 183058102a6STobias Waldekranz 184058102a6STobias Waldekranz static inline int dsa_lag_id(struct dsa_switch_tree *dst, 185058102a6STobias Waldekranz struct net_device *lag) 186058102a6STobias Waldekranz { 187058102a6STobias Waldekranz unsigned int id; 188058102a6STobias Waldekranz 189058102a6STobias Waldekranz dsa_lags_foreach_id(id, dst) { 190058102a6STobias Waldekranz if (dsa_lag_dev(dst, id) == lag) 191058102a6STobias Waldekranz return id; 192058102a6STobias Waldekranz } 193058102a6STobias Waldekranz 194058102a6STobias Waldekranz return -ENODEV; 195058102a6STobias Waldekranz } 196058102a6STobias Waldekranz 19734297176SVladimir Oltean /* TC matchall action types */ 198f50f2127SFlorian Fainelli enum dsa_port_mall_action_type { 199f50f2127SFlorian Fainelli DSA_PORT_MALL_MIRROR, 20034297176SVladimir Oltean DSA_PORT_MALL_POLICER, 201f50f2127SFlorian Fainelli }; 202f50f2127SFlorian Fainelli 203f50f2127SFlorian Fainelli /* TC mirroring entry */ 204f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry { 205f50f2127SFlorian Fainelli u8 to_local_port; 206f50f2127SFlorian Fainelli bool ingress; 207f50f2127SFlorian Fainelli }; 208f50f2127SFlorian Fainelli 20934297176SVladimir Oltean /* TC port policer entry */ 21034297176SVladimir Oltean struct dsa_mall_policer_tc_entry { 2115f035af7SPo Liu u32 burst; 21234297176SVladimir Oltean u64 rate_bytes_per_sec; 21334297176SVladimir Oltean }; 21434297176SVladimir Oltean 215f50f2127SFlorian Fainelli /* TC matchall entry */ 216f50f2127SFlorian Fainelli struct dsa_mall_tc_entry { 217f50f2127SFlorian Fainelli struct list_head list; 218f50f2127SFlorian Fainelli unsigned long cookie; 219f50f2127SFlorian Fainelli enum dsa_port_mall_action_type type; 220f50f2127SFlorian Fainelli union { 221f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry mirror; 22234297176SVladimir Oltean struct dsa_mall_policer_tc_entry policer; 223f50f2127SFlorian Fainelli }; 224f50f2127SFlorian Fainelli }; 225f50f2127SFlorian Fainelli 226d3eed0e5SVladimir Oltean struct dsa_bridge { 227d3eed0e5SVladimir Oltean struct net_device *dev; 228d3eed0e5SVladimir Oltean unsigned int num; 229857fdd74SVladimir Oltean bool tx_fwd_offload; 230d3eed0e5SVladimir Oltean refcount_t refcount; 231d3eed0e5SVladimir Oltean }; 232f50f2127SFlorian Fainelli 233c8b09808SAndrew Lunn struct dsa_port { 234f8b8b1cdSVivien Didelot /* A CPU port is physically connected to a master device. 235f8b8b1cdSVivien Didelot * A user port exposed to userspace has a slave device. 236f8b8b1cdSVivien Didelot */ 237f8b8b1cdSVivien Didelot union { 238f8b8b1cdSVivien Didelot struct net_device *master; 239f8b8b1cdSVivien Didelot struct net_device *slave; 240f8b8b1cdSVivien Didelot }; 241f8b8b1cdSVivien Didelot 242357f203bSVladimir Oltean /* Copy of the tagging protocol operations, for quicker access 243357f203bSVladimir Oltean * in the data path. Valid only for the CPU ports. 244357f203bSVladimir Oltean */ 24515240248SVivien Didelot const struct dsa_device_ops *tag_ops; 24615240248SVivien Didelot 2473e41f93bSVivien Didelot /* Copies for faster access in master receive hot path */ 2483e41f93bSVivien Didelot struct dsa_switch_tree *dst; 24929a097b7SVladimir Oltean struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev); 2503e41f93bSVivien Didelot 25106251258SVladimir Oltean struct dsa_switch *ds; 25206251258SVladimir Oltean 25306251258SVladimir Oltean unsigned int index; 25406251258SVladimir Oltean 255057cad2cSVivien Didelot enum { 256057cad2cSVivien Didelot DSA_PORT_TYPE_UNUSED = 0, 257057cad2cSVivien Didelot DSA_PORT_TYPE_CPU, 258057cad2cSVivien Didelot DSA_PORT_TYPE_DSA, 259057cad2cSVivien Didelot DSA_PORT_TYPE_USER, 260057cad2cSVivien Didelot } type; 261057cad2cSVivien Didelot 26271e0bbdeSFlorian Fainelli const char *name; 26368b2d4a8SVivien Didelot struct dsa_port *cpu_dp; 26483216e39SMichael Walle u8 mac[ETH_ALEN]; 265b08db33dSVladimir Oltean 266b08db33dSVladimir Oltean u8 stp_state; 267b08db33dSVladimir Oltean 268*63cfc657SVladimir Oltean u8 vlan_filtering:1; 269*63cfc657SVladimir Oltean 270*63cfc657SVladimir Oltean /* Managed by DSA on user ports and by drivers on CPU and DSA ports */ 271*63cfc657SVladimir Oltean u8 learning:1; 272*63cfc657SVladimir Oltean 273*63cfc657SVladimir Oltean u8 lag_tx_enabled:1; 274*63cfc657SVladimir Oltean 275*63cfc657SVladimir Oltean u8 devlink_port_setup:1; 276*63cfc657SVladimir Oltean 277*63cfc657SVladimir Oltean u8 setup:1; 278bde82f38SVladimir Oltean 279189b0d93SAndrew Lunn struct device_node *dn; 28034a79f63SVivien Didelot unsigned int ageing_time; 281bde82f38SVladimir Oltean 282d3eed0e5SVladimir Oltean struct dsa_bridge *bridge; 28396567d5dSAndrew Lunn struct devlink_port devlink_port; 284aab9c406SFlorian Fainelli struct phylink *pl; 28544cc27e4SIoana Ciornei struct phylink_config pl_config; 286058102a6STobias Waldekranz struct net_device *lag_dev; 28718596f50SGeorge McCollister struct net_device *hsr_dev; 28897a69a0dSVladimir Oltean 289ab8ccae1SVivien Didelot struct list_head list; 290ab8ccae1SVivien Didelot 29167dbb9d4SFlorian Fainelli /* 29267dbb9d4SFlorian Fainelli * Original copy of the master netdev ethtool_ops 29367dbb9d4SFlorian Fainelli */ 29467dbb9d4SFlorian Fainelli const struct ethtool_ops *orig_ethtool_ops; 295da7b9e9bSFlorian Fainelli 296da7b9e9bSFlorian Fainelli /* 297da7b9e9bSFlorian Fainelli * Original copy of the master netdev net_device_ops 298da7b9e9bSFlorian Fainelli */ 2994cfab356SFlorian Fainelli const struct dsa_netdevice_ops *netdev_ops; 300fb35c60cSVivien Didelot 301161ca59dSVladimir Oltean /* List of MAC addresses that must be forwarded on this port. 302161ca59dSVladimir Oltean * These are only valid on CPU ports and DSA links. 303161ca59dSVladimir Oltean */ 304338a3a47SVladimir Oltean struct mutex addr_lists_lock; 3053f6e32f9SVladimir Oltean struct list_head fdbs; 306161ca59dSVladimir Oltean struct list_head mdbs; 307c8b09808SAndrew Lunn }; 308c8b09808SAndrew Lunn 309c5f51765SVivien Didelot /* TODO: ideally DSA ports would have a single dp->link_dp member, 310c5f51765SVivien Didelot * and no dst->rtable nor this struct dsa_link would be needed, 311c5f51765SVivien Didelot * but this would require some more complex tree walking, 312c5f51765SVivien Didelot * so keep it stupid at the moment and list them all. 313c5f51765SVivien Didelot */ 314c5f51765SVivien Didelot struct dsa_link { 315c5f51765SVivien Didelot struct dsa_port *dp; 316c5f51765SVivien Didelot struct dsa_port *link_dp; 317c5f51765SVivien Didelot struct list_head list; 318c5f51765SVivien Didelot }; 319c5f51765SVivien Didelot 320161ca59dSVladimir Oltean struct dsa_mac_addr { 321161ca59dSVladimir Oltean unsigned char addr[ETH_ALEN]; 322161ca59dSVladimir Oltean u16 vid; 323161ca59dSVladimir Oltean refcount_t refcount; 324161ca59dSVladimir Oltean struct list_head list; 325161ca59dSVladimir Oltean }; 326161ca59dSVladimir Oltean 327c8f0b869SBen Hutchings struct dsa_switch { 328c33063d6SAndrew Lunn struct device *dev; 329c33063d6SAndrew Lunn 330c8f0b869SBen Hutchings /* 331c8f0b869SBen Hutchings * Parent switch tree, and switch index. 332c8f0b869SBen Hutchings */ 333c8f0b869SBen Hutchings struct dsa_switch_tree *dst; 33499feaafcSVivien Didelot unsigned int index; 335c8f0b869SBen Hutchings 336*63cfc657SVladimir Oltean u32 setup:1; 337*63cfc657SVladimir Oltean 338*63cfc657SVladimir Oltean /* Disallow bridge core from requesting different VLAN awareness 339*63cfc657SVladimir Oltean * settings on ports if not hardware-supported 3407787ff77SVladimir Oltean */ 341*63cfc657SVladimir Oltean u32 vlan_filtering_is_global:1; 342*63cfc657SVladimir Oltean 343*63cfc657SVladimir Oltean /* Keep VLAN filtering enabled on ports not offloading any upper */ 344*63cfc657SVladimir Oltean u32 needs_standalone_vlan_filtering:1; 345*63cfc657SVladimir Oltean 346*63cfc657SVladimir Oltean /* Pass .port_vlan_add and .port_vlan_del to drivers even for bridges 347*63cfc657SVladimir Oltean * that have vlan_filtering=0. All drivers should ideally set this (and 348*63cfc657SVladimir Oltean * then the option would get removed), but it is unknown whether this 3497787ff77SVladimir Oltean * would break things or not. 3507787ff77SVladimir Oltean */ 351*63cfc657SVladimir Oltean u32 configure_vlan_while_not_filtering:1; 352*63cfc657SVladimir Oltean 353*63cfc657SVladimir Oltean /* If the switch driver always programs the CPU port as egress tagged 354*63cfc657SVladimir Oltean * despite the VLAN configuration indicating otherwise, then setting 355*63cfc657SVladimir Oltean * @untag_bridge_pvid will force the DSA receive path to pop the 356*63cfc657SVladimir Oltean * bridge's default_pvid VLAN tagged frames to offer a consistent 357*63cfc657SVladimir Oltean * behavior between a vlan_filtering=0 and vlan_filtering=1 bridge 3587787ff77SVladimir Oltean * device. 3597787ff77SVladimir Oltean */ 360*63cfc657SVladimir Oltean u32 untag_bridge_pvid:1; 361*63cfc657SVladimir Oltean 3627787ff77SVladimir Oltean /* Let DSA manage the FDB entries towards the 3637787ff77SVladimir Oltean * CPU, based on the software bridge database. 3647787ff77SVladimir Oltean */ 365*63cfc657SVladimir Oltean u32 assisted_learning_on_cpu_port:1; 366*63cfc657SVladimir Oltean 367*63cfc657SVladimir Oltean /* In case vlan_filtering_is_global is set, the VLAN awareness state 368*63cfc657SVladimir Oltean * should be retrieved from here and not from the per-port settings. 3697787ff77SVladimir Oltean */ 370*63cfc657SVladimir Oltean u32 vlan_filtering:1; 371*63cfc657SVladimir Oltean 372*63cfc657SVladimir Oltean /* MAC PCS does not provide link state change interrupt, and requires 373*63cfc657SVladimir Oltean * polling. Flag passed on to PHYLINK. 3747787ff77SVladimir Oltean */ 375*63cfc657SVladimir Oltean u32 pcs_poll:1; 376*63cfc657SVladimir Oltean 377*63cfc657SVladimir Oltean /* For switches that only have the MRU configurable. To ensure the 378*63cfc657SVladimir Oltean * configured MTU is not exceeded, normalization of MRU on all bridged 379*63cfc657SVladimir Oltean * interfaces is needed. 3807787ff77SVladimir Oltean */ 381*63cfc657SVladimir Oltean u32 mtu_enforcement_ingress:1; 3827787ff77SVladimir Oltean 383f515f192SVivien Didelot /* Listener for switch fabric events */ 384f515f192SVivien Didelot struct notifier_block nb; 385f515f192SVivien Didelot 386c8f0b869SBen Hutchings /* 3877543a6d5SAndrew Lunn * Give the switch driver somewhere to hang its private data 3887543a6d5SAndrew Lunn * structure. 3897543a6d5SAndrew Lunn */ 3907543a6d5SAndrew Lunn void *priv; 3917543a6d5SAndrew Lunn 392dc452a47SVladimir Oltean void *tagger_data; 393dc452a47SVladimir Oltean 3947543a6d5SAndrew Lunn /* 395c8f0b869SBen Hutchings * Configuration data for this switch. 396c8f0b869SBen Hutchings */ 397ff04955cSAndrew Lunn struct dsa_chip_data *cd; 398c8f0b869SBen Hutchings 399c8f0b869SBen Hutchings /* 4009d490b4eSVivien Didelot * The switch operations. 401c8f0b869SBen Hutchings */ 402a82f67afSFlorian Fainelli const struct dsa_switch_ops *ops; 403c8f0b869SBen Hutchings 40466472fc0SAndrew Lunn /* 405c8f0b869SBen Hutchings * Slave mii_bus and devices for the individual ports. 406c8f0b869SBen Hutchings */ 4070d8bcdd3SFlorian Fainelli u32 phys_mii_mask; 408c8f0b869SBen Hutchings struct mii_bus *slave_mii_bus; 409a0c02161SVivien Didelot 4100f3da6afSVivien Didelot /* Ageing Time limits in msecs */ 4110f3da6afSVivien Didelot unsigned int ageing_time_min; 4120f3da6afSVivien Didelot unsigned int ageing_time_max; 4130f3da6afSVivien Didelot 414d7b1fd52SVladimir Oltean /* Storage for drivers using tag_8021q */ 415d7b1fd52SVladimir Oltean struct dsa_8021q_context *tag_8021q_ctx; 416d7b1fd52SVladimir Oltean 41796567d5dSAndrew Lunn /* devlink used to represent this switch device */ 41896567d5dSAndrew Lunn struct devlink *devlink; 41996567d5dSAndrew Lunn 42055199df6SFlorian Fainelli /* Number of switch port queues */ 42155199df6SFlorian Fainelli unsigned int num_tx_queues; 42255199df6SFlorian Fainelli 423058102a6STobias Waldekranz /* Drivers that benefit from having an ID associated with each 424058102a6STobias Waldekranz * offloaded LAG should set this to the maximum number of 425058102a6STobias Waldekranz * supported IDs. DSA will then maintain a mapping of _at 426058102a6STobias Waldekranz * least_ these many IDs, accessible to drivers via 427058102a6STobias Waldekranz * dsa_lag_id(). 428058102a6STobias Waldekranz */ 429058102a6STobias Waldekranz unsigned int num_lag_ids; 430058102a6STobias Waldekranz 431947c8746SVladimir Oltean /* Drivers that support bridge forwarding offload or FDB isolation 432947c8746SVladimir Oltean * should set this to the maximum number of bridges spanning the same 433947c8746SVladimir Oltean * switch tree (or all trees, in the case of cross-tree bridging 434947c8746SVladimir Oltean * support) that can be offloaded. 435123abc06SVladimir Oltean */ 436947c8746SVladimir Oltean unsigned int max_num_bridges; 437123abc06SVladimir Oltean 438258030acSVladimir Oltean unsigned int num_ports; 439c8f0b869SBen Hutchings }; 440c8f0b869SBen Hutchings 44168bb8ea8SVivien Didelot static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p) 442c38c5a66SVivien Didelot { 443b96ddf25SVivien Didelot struct dsa_switch_tree *dst = ds->dst; 444d607525bSVivien Didelot struct dsa_port *dp; 445b96ddf25SVivien Didelot 446b96ddf25SVivien Didelot list_for_each_entry(dp, &dst->ports, list) 447b96ddf25SVivien Didelot if (dp->ds == ds && dp->index == p) 448b96ddf25SVivien Didelot return dp; 449d607525bSVivien Didelot 450d607525bSVivien Didelot return NULL; 451c38c5a66SVivien Didelot } 452c38c5a66SVivien Didelot 453a8986681SVladimir Oltean static inline bool dsa_port_is_dsa(struct dsa_port *port) 454a8986681SVladimir Oltean { 455a8986681SVladimir Oltean return port->type == DSA_PORT_TYPE_DSA; 456a8986681SVladimir Oltean } 457a8986681SVladimir Oltean 458a8986681SVladimir Oltean static inline bool dsa_port_is_cpu(struct dsa_port *port) 459a8986681SVladimir Oltean { 460a8986681SVladimir Oltean return port->type == DSA_PORT_TYPE_CPU; 461a8986681SVladimir Oltean } 462a8986681SVladimir Oltean 463a8986681SVladimir Oltean static inline bool dsa_port_is_user(struct dsa_port *dp) 464a8986681SVladimir Oltean { 465a8986681SVladimir Oltean return dp->type == DSA_PORT_TYPE_USER; 466a8986681SVladimir Oltean } 467a8986681SVladimir Oltean 468a57d8c21SVladimir Oltean static inline bool dsa_port_is_unused(struct dsa_port *dp) 469a57d8c21SVladimir Oltean { 470a57d8c21SVladimir Oltean return dp->type == DSA_PORT_TYPE_UNUSED; 471a57d8c21SVladimir Oltean } 472a57d8c21SVladimir Oltean 473bff7b688SVivien Didelot static inline bool dsa_is_unused_port(struct dsa_switch *ds, int p) 474bff7b688SVivien Didelot { 475c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_UNUSED; 476bff7b688SVivien Didelot } 477bff7b688SVivien Didelot 478c8f0b869SBen Hutchings static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p) 479c8f0b869SBen Hutchings { 480c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_CPU; 481c8f0b869SBen Hutchings } 482c8f0b869SBen Hutchings 48360045cbfSAndrew Lunn static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p) 48460045cbfSAndrew Lunn { 485c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_DSA; 48660045cbfSAndrew Lunn } 48760045cbfSAndrew Lunn 4882b3e9891SVivien Didelot static inline bool dsa_is_user_port(struct dsa_switch *ds, int p) 4896cd456f3SVivien Didelot { 490c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_USER; 4916cd456f3SVivien Didelot } 4926cd456f3SVivien Didelot 49382b31898SVladimir Oltean #define dsa_tree_for_each_user_port(_dp, _dst) \ 49482b31898SVladimir Oltean list_for_each_entry((_dp), &(_dst)->ports, list) \ 49582b31898SVladimir Oltean if (dsa_port_is_user((_dp))) 49682b31898SVladimir Oltean 49782b31898SVladimir Oltean #define dsa_switch_for_each_port(_dp, _ds) \ 49882b31898SVladimir Oltean list_for_each_entry((_dp), &(_ds)->dst->ports, list) \ 49982b31898SVladimir Oltean if ((_dp)->ds == (_ds)) 50082b31898SVladimir Oltean 50182b31898SVladimir Oltean #define dsa_switch_for_each_port_safe(_dp, _next, _ds) \ 50282b31898SVladimir Oltean list_for_each_entry_safe((_dp), (_next), &(_ds)->dst->ports, list) \ 50382b31898SVladimir Oltean if ((_dp)->ds == (_ds)) 50482b31898SVladimir Oltean 50582b31898SVladimir Oltean #define dsa_switch_for_each_port_continue_reverse(_dp, _ds) \ 50682b31898SVladimir Oltean list_for_each_entry_continue_reverse((_dp), &(_ds)->dst->ports, list) \ 50782b31898SVladimir Oltean if ((_dp)->ds == (_ds)) 50882b31898SVladimir Oltean 50982b31898SVladimir Oltean #define dsa_switch_for_each_available_port(_dp, _ds) \ 51082b31898SVladimir Oltean dsa_switch_for_each_port((_dp), (_ds)) \ 51182b31898SVladimir Oltean if (!dsa_port_is_unused((_dp))) 51282b31898SVladimir Oltean 51382b31898SVladimir Oltean #define dsa_switch_for_each_user_port(_dp, _ds) \ 51482b31898SVladimir Oltean dsa_switch_for_each_port((_dp), (_ds)) \ 51582b31898SVladimir Oltean if (dsa_port_is_user((_dp))) 51682b31898SVladimir Oltean 51782b31898SVladimir Oltean #define dsa_switch_for_each_cpu_port(_dp, _ds) \ 51882b31898SVladimir Oltean dsa_switch_for_each_port((_dp), (_ds)) \ 51982b31898SVladimir Oltean if (dsa_port_is_cpu((_dp))) 52082b31898SVladimir Oltean 52102bc6e54SVivien Didelot static inline u32 dsa_user_ports(struct dsa_switch *ds) 52202bc6e54SVivien Didelot { 523d0004a02SVladimir Oltean struct dsa_port *dp; 524c38c5a66SVivien Didelot u32 mask = 0; 52502bc6e54SVivien Didelot 526d0004a02SVladimir Oltean dsa_switch_for_each_user_port(dp, ds) 527d0004a02SVladimir Oltean mask |= BIT(dp->index); 528c38c5a66SVivien Didelot 529c38c5a66SVivien Didelot return mask; 530c8652c83SVivien Didelot } 531c8652c83SVivien Didelot 532c5f51765SVivien Didelot /* Return the local port used to reach an arbitrary switch device */ 533c5f51765SVivien Didelot static inline unsigned int dsa_routing_port(struct dsa_switch *ds, int device) 534c5f51765SVivien Didelot { 535c5f51765SVivien Didelot struct dsa_switch_tree *dst = ds->dst; 536c5f51765SVivien Didelot struct dsa_link *dl; 537c5f51765SVivien Didelot 538c5f51765SVivien Didelot list_for_each_entry(dl, &dst->rtable, list) 539c5f51765SVivien Didelot if (dl->dp->ds == ds && dl->link_dp->ds->index == device) 540c5f51765SVivien Didelot return dl->dp->index; 541c5f51765SVivien Didelot 542c5f51765SVivien Didelot return ds->num_ports; 543c5f51765SVivien Didelot } 544c5f51765SVivien Didelot 5453b8fac5dSVivien Didelot /* Return the local port used to reach an arbitrary switch port */ 5463b8fac5dSVivien Didelot static inline unsigned int dsa_towards_port(struct dsa_switch *ds, int device, 5473b8fac5dSVivien Didelot int port) 5483b8fac5dSVivien Didelot { 5493b8fac5dSVivien Didelot if (device == ds->index) 5503b8fac5dSVivien Didelot return port; 5513b8fac5dSVivien Didelot else 552c5f51765SVivien Didelot return dsa_routing_port(ds, device); 5533b8fac5dSVivien Didelot } 5543b8fac5dSVivien Didelot 5553b8fac5dSVivien Didelot /* Return the local port used to reach the dedicated CPU port */ 55607073c79SVivien Didelot static inline unsigned int dsa_upstream_port(struct dsa_switch *ds, int port) 557c8f0b869SBen Hutchings { 55807073c79SVivien Didelot const struct dsa_port *dp = dsa_to_port(ds, port); 55907073c79SVivien Didelot const struct dsa_port *cpu_dp = dp->cpu_dp; 56007073c79SVivien Didelot 56107073c79SVivien Didelot if (!cpu_dp) 56207073c79SVivien Didelot return port; 563c8f0b869SBen Hutchings 5643b8fac5dSVivien Didelot return dsa_towards_port(ds, cpu_dp->ds->index, cpu_dp->index); 565c8f0b869SBen Hutchings } 566c8f0b869SBen Hutchings 56763609c8fSVladimir Oltean /* Return true if this is the local port used to reach the CPU port */ 56863609c8fSVladimir Oltean static inline bool dsa_is_upstream_port(struct dsa_switch *ds, int port) 56963609c8fSVladimir Oltean { 57063609c8fSVladimir Oltean if (dsa_is_unused_port(ds, port)) 57163609c8fSVladimir Oltean return false; 57263609c8fSVladimir Oltean 57363609c8fSVladimir Oltean return port == dsa_upstream_port(ds, port); 57463609c8fSVladimir Oltean } 57563609c8fSVladimir Oltean 57663609c8fSVladimir Oltean /* Return true if @upstream_ds is an upstream switch of @downstream_ds, meaning 57763609c8fSVladimir Oltean * that the routing port from @downstream_ds to @upstream_ds is also the port 57863609c8fSVladimir Oltean * which @downstream_ds uses to reach its dedicated CPU. 57963609c8fSVladimir Oltean */ 58063609c8fSVladimir Oltean static inline bool dsa_switch_is_upstream_of(struct dsa_switch *upstream_ds, 58163609c8fSVladimir Oltean struct dsa_switch *downstream_ds) 58263609c8fSVladimir Oltean { 58363609c8fSVladimir Oltean int routing_port; 58463609c8fSVladimir Oltean 58563609c8fSVladimir Oltean if (upstream_ds == downstream_ds) 58663609c8fSVladimir Oltean return true; 58763609c8fSVladimir Oltean 58863609c8fSVladimir Oltean routing_port = dsa_routing_port(downstream_ds, upstream_ds->index); 58963609c8fSVladimir Oltean 59063609c8fSVladimir Oltean return dsa_is_upstream_port(downstream_ds, routing_port); 59163609c8fSVladimir Oltean } 59263609c8fSVladimir Oltean 593cf2d45f5SVladimir Oltean static inline bool dsa_port_is_vlan_filtering(const struct dsa_port *dp) 594cf2d45f5SVladimir Oltean { 595cf2d45f5SVladimir Oltean const struct dsa_switch *ds = dp->ds; 596cf2d45f5SVladimir Oltean 597cf2d45f5SVladimir Oltean if (ds->vlan_filtering_is_global) 598cf2d45f5SVladimir Oltean return ds->vlan_filtering; 599cf2d45f5SVladimir Oltean else 600cf2d45f5SVladimir Oltean return dp->vlan_filtering; 601cf2d45f5SVladimir Oltean } 602cf2d45f5SVladimir Oltean 603cc76ce9eSTobias Waldekranz static inline 604cc76ce9eSTobias Waldekranz struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp) 605cc76ce9eSTobias Waldekranz { 606d3eed0e5SVladimir Oltean if (!dp->bridge) 607cc76ce9eSTobias Waldekranz return NULL; 608cc76ce9eSTobias Waldekranz 609cc76ce9eSTobias Waldekranz if (dp->lag_dev) 610cc76ce9eSTobias Waldekranz return dp->lag_dev; 611cc76ce9eSTobias Waldekranz else if (dp->hsr_dev) 612cc76ce9eSTobias Waldekranz return dp->hsr_dev; 613cc76ce9eSTobias Waldekranz 614cc76ce9eSTobias Waldekranz return dp->slave; 615cc76ce9eSTobias Waldekranz } 616cc76ce9eSTobias Waldekranz 61736cbf39bSVladimir Oltean static inline struct net_device * 61836cbf39bSVladimir Oltean dsa_port_bridge_dev_get(const struct dsa_port *dp) 61936cbf39bSVladimir Oltean { 620d3eed0e5SVladimir Oltean return dp->bridge ? dp->bridge->dev : NULL; 62136cbf39bSVladimir Oltean } 62236cbf39bSVladimir Oltean 62336cbf39bSVladimir Oltean static inline unsigned int dsa_port_bridge_num_get(struct dsa_port *dp) 62436cbf39bSVladimir Oltean { 625d3eed0e5SVladimir Oltean return dp->bridge ? dp->bridge->num : 0; 62636cbf39bSVladimir Oltean } 62736cbf39bSVladimir Oltean 62836cbf39bSVladimir Oltean static inline bool dsa_port_bridge_same(const struct dsa_port *a, 62936cbf39bSVladimir Oltean const struct dsa_port *b) 63036cbf39bSVladimir Oltean { 63136cbf39bSVladimir Oltean struct net_device *br_a = dsa_port_bridge_dev_get(a); 63236cbf39bSVladimir Oltean struct net_device *br_b = dsa_port_bridge_dev_get(b); 63336cbf39bSVladimir Oltean 63436cbf39bSVladimir Oltean /* Standalone ports are not in the same bridge with one another */ 63536cbf39bSVladimir Oltean return (!br_a || !br_b) ? false : (br_a == br_b); 63636cbf39bSVladimir Oltean } 63736cbf39bSVladimir Oltean 6386a43cba3SVladimir Oltean static inline bool dsa_port_offloads_bridge_port(struct dsa_port *dp, 6396a43cba3SVladimir Oltean const struct net_device *dev) 6406a43cba3SVladimir Oltean { 6416a43cba3SVladimir Oltean return dsa_port_to_bridge_port(dp) == dev; 6426a43cba3SVladimir Oltean } 6436a43cba3SVladimir Oltean 6446a43cba3SVladimir Oltean static inline bool 6456a43cba3SVladimir Oltean dsa_port_offloads_bridge_dev(struct dsa_port *dp, 6466a43cba3SVladimir Oltean const struct net_device *bridge_dev) 6476a43cba3SVladimir Oltean { 6486a43cba3SVladimir Oltean /* DSA ports connected to a bridge, and event was emitted 6496a43cba3SVladimir Oltean * for the bridge. 6506a43cba3SVladimir Oltean */ 6516a43cba3SVladimir Oltean return dsa_port_bridge_dev_get(dp) == bridge_dev; 6526a43cba3SVladimir Oltean } 6536a43cba3SVladimir Oltean 654d3eed0e5SVladimir Oltean static inline bool dsa_port_offloads_bridge(struct dsa_port *dp, 655d3eed0e5SVladimir Oltean const struct dsa_bridge *bridge) 656d3eed0e5SVladimir Oltean { 657d3eed0e5SVladimir Oltean return dsa_port_bridge_dev_get(dp) == bridge->dev; 658d3eed0e5SVladimir Oltean } 659d3eed0e5SVladimir Oltean 6606a43cba3SVladimir Oltean /* Returns true if any port of this tree offloads the given net_device */ 6616a43cba3SVladimir Oltean static inline bool dsa_tree_offloads_bridge_port(struct dsa_switch_tree *dst, 6626a43cba3SVladimir Oltean const struct net_device *dev) 6636a43cba3SVladimir Oltean { 6646a43cba3SVladimir Oltean struct dsa_port *dp; 6656a43cba3SVladimir Oltean 6666a43cba3SVladimir Oltean list_for_each_entry(dp, &dst->ports, list) 6676a43cba3SVladimir Oltean if (dsa_port_offloads_bridge_port(dp, dev)) 6686a43cba3SVladimir Oltean return true; 6696a43cba3SVladimir Oltean 6706a43cba3SVladimir Oltean return false; 6716a43cba3SVladimir Oltean } 6726a43cba3SVladimir Oltean 6736a43cba3SVladimir Oltean /* Returns true if any port of this tree offloads the given bridge */ 6746a43cba3SVladimir Oltean static inline bool 6756a43cba3SVladimir Oltean dsa_tree_offloads_bridge_dev(struct dsa_switch_tree *dst, 6766a43cba3SVladimir Oltean const struct net_device *bridge_dev) 6776a43cba3SVladimir Oltean { 6786a43cba3SVladimir Oltean struct dsa_port *dp; 6796a43cba3SVladimir Oltean 6806a43cba3SVladimir Oltean list_for_each_entry(dp, &dst->ports, list) 6816a43cba3SVladimir Oltean if (dsa_port_offloads_bridge_dev(dp, bridge_dev)) 6826a43cba3SVladimir Oltean return true; 6836a43cba3SVladimir Oltean 6846a43cba3SVladimir Oltean return false; 6856a43cba3SVladimir Oltean } 6866a43cba3SVladimir Oltean 6872bedde1aSArkadi Sharshevsky typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid, 6882bedde1aSArkadi Sharshevsky bool is_static, void *data); 6899d490b4eSVivien Didelot struct dsa_switch_ops { 69053da0ebaSVladimir Oltean /* 69153da0ebaSVladimir Oltean * Tagging protocol helpers called for the CPU ports and DSA links. 69253da0ebaSVladimir Oltean * @get_tag_protocol retrieves the initial tagging protocol and is 69353da0ebaSVladimir Oltean * mandatory. Switches which can operate using multiple tagging 69453da0ebaSVladimir Oltean * protocols should implement @change_tag_protocol and report in 69553da0ebaSVladimir Oltean * @get_tag_protocol the tagger in current use. 69653da0ebaSVladimir Oltean */ 6975ed4e3ebSFlorian Fainelli enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds, 6984d776482SFlorian Fainelli int port, 6994d776482SFlorian Fainelli enum dsa_tag_protocol mprot); 70053da0ebaSVladimir Oltean int (*change_tag_protocol)(struct dsa_switch *ds, int port, 70153da0ebaSVladimir Oltean enum dsa_tag_protocol proto); 702dc452a47SVladimir Oltean /* 703dc452a47SVladimir Oltean * Method for switch drivers to connect to the tagging protocol driver 704dc452a47SVladimir Oltean * in current use. The switch driver can provide handlers for certain 705dc452a47SVladimir Oltean * types of packets for switch management. 706dc452a47SVladimir Oltean */ 707dc452a47SVladimir Oltean int (*connect_tag_protocol)(struct dsa_switch *ds, 708dc452a47SVladimir Oltean enum dsa_tag_protocol proto); 7097b314362SAndrew Lunn 710fd292c18SVladimir Oltean /* Optional switch-wide initialization and destruction methods */ 711c8f0b869SBen Hutchings int (*setup)(struct dsa_switch *ds); 7125e3f847aSVladimir Oltean void (*teardown)(struct dsa_switch *ds); 713fd292c18SVladimir Oltean 714fd292c18SVladimir Oltean /* Per-port initialization and destruction methods. Mandatory if the 715fd292c18SVladimir Oltean * driver registers devlink port regions, optional otherwise. 716fd292c18SVladimir Oltean */ 717fd292c18SVladimir Oltean int (*port_setup)(struct dsa_switch *ds, int port); 718fd292c18SVladimir Oltean void (*port_teardown)(struct dsa_switch *ds, int port); 719fd292c18SVladimir Oltean 7206819563eSFlorian Fainelli u32 (*get_phy_flags)(struct dsa_switch *ds, int port); 721c8f0b869SBen Hutchings 722c8f0b869SBen Hutchings /* 723c8f0b869SBen Hutchings * Access to the switch's PHY registers. 724c8f0b869SBen Hutchings */ 725c8f0b869SBen Hutchings int (*phy_read)(struct dsa_switch *ds, int port, int regnum); 726c8f0b869SBen Hutchings int (*phy_write)(struct dsa_switch *ds, int port, 727c8f0b869SBen Hutchings int regnum, u16 val); 728c8f0b869SBen Hutchings 729c8f0b869SBen Hutchings /* 730ec9436baSFlorian Fainelli * Link state adjustment (called from libphy) 731ec9436baSFlorian Fainelli */ 732ec9436baSFlorian Fainelli void (*adjust_link)(struct dsa_switch *ds, int port, 733ec9436baSFlorian Fainelli struct phy_device *phydev); 734ce31b31cSFlorian Fainelli void (*fixed_link_update)(struct dsa_switch *ds, int port, 735ce31b31cSFlorian Fainelli struct fixed_phy_status *st); 736ec9436baSFlorian Fainelli 737ec9436baSFlorian Fainelli /* 73811d8f3ddSFlorian Fainelli * PHYLINK integration 73911d8f3ddSFlorian Fainelli */ 740072eea6cSRussell King (Oracle) void (*phylink_get_caps)(struct dsa_switch *ds, int port, 741072eea6cSRussell King (Oracle) struct phylink_config *config); 74211d8f3ddSFlorian Fainelli void (*phylink_validate)(struct dsa_switch *ds, int port, 74311d8f3ddSFlorian Fainelli unsigned long *supported, 74411d8f3ddSFlorian Fainelli struct phylink_link_state *state); 74511d8f3ddSFlorian Fainelli int (*phylink_mac_link_state)(struct dsa_switch *ds, int port, 74611d8f3ddSFlorian Fainelli struct phylink_link_state *state); 74711d8f3ddSFlorian Fainelli void (*phylink_mac_config)(struct dsa_switch *ds, int port, 74811d8f3ddSFlorian Fainelli unsigned int mode, 74911d8f3ddSFlorian Fainelli const struct phylink_link_state *state); 75011d8f3ddSFlorian Fainelli void (*phylink_mac_an_restart)(struct dsa_switch *ds, int port); 75111d8f3ddSFlorian Fainelli void (*phylink_mac_link_down)(struct dsa_switch *ds, int port, 75211d8f3ddSFlorian Fainelli unsigned int mode, 75311d8f3ddSFlorian Fainelli phy_interface_t interface); 75411d8f3ddSFlorian Fainelli void (*phylink_mac_link_up)(struct dsa_switch *ds, int port, 75511d8f3ddSFlorian Fainelli unsigned int mode, 75611d8f3ddSFlorian Fainelli phy_interface_t interface, 7575b502a7bSRussell King struct phy_device *phydev, 7585b502a7bSRussell King int speed, int duplex, 7595b502a7bSRussell King bool tx_pause, bool rx_pause); 76011d8f3ddSFlorian Fainelli void (*phylink_fixed_state)(struct dsa_switch *ds, int port, 76111d8f3ddSFlorian Fainelli struct phylink_link_state *state); 76211d8f3ddSFlorian Fainelli /* 763c2ec5f2eSOleksij Rempel * Port statistics counters. 764c8f0b869SBen Hutchings */ 76589f09048SFlorian Fainelli void (*get_strings)(struct dsa_switch *ds, int port, 76689f09048SFlorian Fainelli u32 stringset, uint8_t *data); 767c8f0b869SBen Hutchings void (*get_ethtool_stats)(struct dsa_switch *ds, 768c8f0b869SBen Hutchings int port, uint64_t *data); 76989f09048SFlorian Fainelli int (*get_sset_count)(struct dsa_switch *ds, int port, int sset); 770cf963573SFlorian Fainelli void (*get_ethtool_phy_stats)(struct dsa_switch *ds, 771cf963573SFlorian Fainelli int port, uint64_t *data); 772487d3855SAlvin Šipraga void (*get_eth_phy_stats)(struct dsa_switch *ds, int port, 773487d3855SAlvin Šipraga struct ethtool_eth_phy_stats *phy_stats); 774487d3855SAlvin Šipraga void (*get_eth_mac_stats)(struct dsa_switch *ds, int port, 775487d3855SAlvin Šipraga struct ethtool_eth_mac_stats *mac_stats); 776487d3855SAlvin Šipraga void (*get_eth_ctrl_stats)(struct dsa_switch *ds, int port, 777487d3855SAlvin Šipraga struct ethtool_eth_ctrl_stats *ctrl_stats); 778c2ec5f2eSOleksij Rempel void (*get_stats64)(struct dsa_switch *ds, int port, 779c2ec5f2eSOleksij Rempel struct rtnl_link_stats64 *s); 780a71acad9SOleksij Rempel void (*self_test)(struct dsa_switch *ds, int port, 781a71acad9SOleksij Rempel struct ethtool_test *etest, u64 *data); 78224462549SFlorian Fainelli 78324462549SFlorian Fainelli /* 78419e57c4eSFlorian Fainelli * ethtool Wake-on-LAN 78519e57c4eSFlorian Fainelli */ 78619e57c4eSFlorian Fainelli void (*get_wol)(struct dsa_switch *ds, int port, 78719e57c4eSFlorian Fainelli struct ethtool_wolinfo *w); 78819e57c4eSFlorian Fainelli int (*set_wol)(struct dsa_switch *ds, int port, 78919e57c4eSFlorian Fainelli struct ethtool_wolinfo *w); 79019e57c4eSFlorian Fainelli 79119e57c4eSFlorian Fainelli /* 7920336369dSBrandon Streiff * ethtool timestamp info 7930336369dSBrandon Streiff */ 7940336369dSBrandon Streiff int (*get_ts_info)(struct dsa_switch *ds, int port, 7950336369dSBrandon Streiff struct ethtool_ts_info *ts); 7960336369dSBrandon Streiff 7970336369dSBrandon Streiff /* 79824462549SFlorian Fainelli * Suspend and resume 79924462549SFlorian Fainelli */ 80024462549SFlorian Fainelli int (*suspend)(struct dsa_switch *ds); 80124462549SFlorian Fainelli int (*resume)(struct dsa_switch *ds); 802b2f2af21SFlorian Fainelli 803b2f2af21SFlorian Fainelli /* 804b2f2af21SFlorian Fainelli * Port enable/disable 805b2f2af21SFlorian Fainelli */ 806b2f2af21SFlorian Fainelli int (*port_enable)(struct dsa_switch *ds, int port, 807b2f2af21SFlorian Fainelli struct phy_device *phy); 80875104db0SAndrew Lunn void (*port_disable)(struct dsa_switch *ds, int port); 8097905288fSFlorian Fainelli 8107905288fSFlorian Fainelli /* 81108f50061SVivien Didelot * Port's MAC EEE settings 8127905288fSFlorian Fainelli */ 81308f50061SVivien Didelot int (*set_mac_eee)(struct dsa_switch *ds, int port, 8147905288fSFlorian Fainelli struct ethtool_eee *e); 81508f50061SVivien Didelot int (*get_mac_eee)(struct dsa_switch *ds, int port, 8167905288fSFlorian Fainelli struct ethtool_eee *e); 81751579c3fSGuenter Roeck 8186793abb4SGuenter Roeck /* EEPROM access */ 8196793abb4SGuenter Roeck int (*get_eeprom_len)(struct dsa_switch *ds); 8206793abb4SGuenter Roeck int (*get_eeprom)(struct dsa_switch *ds, 8216793abb4SGuenter Roeck struct ethtool_eeprom *eeprom, u8 *data); 8226793abb4SGuenter Roeck int (*set_eeprom)(struct dsa_switch *ds, 8236793abb4SGuenter Roeck struct ethtool_eeprom *eeprom, u8 *data); 8243d762a0fSGuenter Roeck 8253d762a0fSGuenter Roeck /* 8263d762a0fSGuenter Roeck * Register access. 8273d762a0fSGuenter Roeck */ 8283d762a0fSGuenter Roeck int (*get_regs_len)(struct dsa_switch *ds, int port); 8293d762a0fSGuenter Roeck void (*get_regs)(struct dsa_switch *ds, int port, 8303d762a0fSGuenter Roeck struct ethtool_regs *regs, void *p); 831b73adef6SFlorian Fainelli 832b73adef6SFlorian Fainelli /* 833e358bef7SVladimir Oltean * Upper device tracking. 834e358bef7SVladimir Oltean */ 835e358bef7SVladimir Oltean int (*port_prechangeupper)(struct dsa_switch *ds, int port, 836e358bef7SVladimir Oltean struct netdev_notifier_changeupper_info *info); 837e358bef7SVladimir Oltean 838e358bef7SVladimir Oltean /* 839b73adef6SFlorian Fainelli * Bridge integration 840b73adef6SFlorian Fainelli */ 84134a79f63SVivien Didelot int (*set_ageing_time)(struct dsa_switch *ds, unsigned int msecs); 84271327a4eSVivien Didelot int (*port_bridge_join)(struct dsa_switch *ds, int port, 843b079922bSVladimir Oltean struct dsa_bridge bridge, 844b079922bSVladimir Oltean bool *tx_fwd_offload); 845f123f2fbSVivien Didelot void (*port_bridge_leave)(struct dsa_switch *ds, int port, 846d3eed0e5SVladimir Oltean struct dsa_bridge bridge); 84743c44a9fSVivien Didelot void (*port_stp_state_set)(struct dsa_switch *ds, int port, 848b73adef6SFlorian Fainelli u8 state); 849732f794cSVivien Didelot void (*port_fast_age)(struct dsa_switch *ds, int port); 850a8b659e7SVladimir Oltean int (*port_pre_bridge_flags)(struct dsa_switch *ds, int port, 851a8b659e7SVladimir Oltean struct switchdev_brport_flags flags, 852a8b659e7SVladimir Oltean struct netlink_ext_ack *extack); 853a8b659e7SVladimir Oltean int (*port_bridge_flags)(struct dsa_switch *ds, int port, 854a8b659e7SVladimir Oltean struct switchdev_brport_flags flags, 855a8b659e7SVladimir Oltean struct netlink_ext_ack *extack); 8562a778e1bSVivien Didelot 8572a778e1bSVivien Didelot /* 85811149536SVivien Didelot * VLAN support 85911149536SVivien Didelot */ 860fb2dabadSVivien Didelot int (*port_vlan_filtering)(struct dsa_switch *ds, int port, 86189153ed6SVladimir Oltean bool vlan_filtering, 86289153ed6SVladimir Oltean struct netlink_ext_ack *extack); 8631958d581SVladimir Oltean int (*port_vlan_add)(struct dsa_switch *ds, int port, 86431046a5fSVladimir Oltean const struct switchdev_obj_port_vlan *vlan, 86531046a5fSVladimir Oltean struct netlink_ext_ack *extack); 86676e398a6SVivien Didelot int (*port_vlan_del)(struct dsa_switch *ds, int port, 86776e398a6SVivien Didelot const struct switchdev_obj_port_vlan *vlan); 86811149536SVivien Didelot /* 8692a778e1bSVivien Didelot * Forwarding database 8702a778e1bSVivien Didelot */ 8711b6dd556SArkadi Sharshevsky int (*port_fdb_add)(struct dsa_switch *ds, int port, 8726c2c1dcbSArkadi Sharshevsky const unsigned char *addr, u16 vid); 8732a778e1bSVivien Didelot int (*port_fdb_del)(struct dsa_switch *ds, int port, 8746c2c1dcbSArkadi Sharshevsky const unsigned char *addr, u16 vid); 875ea70ba98SVivien Didelot int (*port_fdb_dump)(struct dsa_switch *ds, int port, 8762bedde1aSArkadi Sharshevsky dsa_fdb_dump_cb_t *cb, void *data); 8778df30255SVivien Didelot 8788df30255SVivien Didelot /* 8798df30255SVivien Didelot * Multicast database 8808df30255SVivien Didelot */ 881a52b2da7SVladimir Oltean int (*port_mdb_add)(struct dsa_switch *ds, int port, 8823709aadcSVivien Didelot const struct switchdev_obj_port_mdb *mdb); 8838df30255SVivien Didelot int (*port_mdb_del)(struct dsa_switch *ds, int port, 8848df30255SVivien Didelot const struct switchdev_obj_port_mdb *mdb); 885bf9f2648SFlorian Fainelli /* 886bf9f2648SFlorian Fainelli * RXNFC 887bf9f2648SFlorian Fainelli */ 888bf9f2648SFlorian Fainelli int (*get_rxnfc)(struct dsa_switch *ds, int port, 889bf9f2648SFlorian Fainelli struct ethtool_rxnfc *nfc, u32 *rule_locs); 890bf9f2648SFlorian Fainelli int (*set_rxnfc)(struct dsa_switch *ds, int port, 891bf9f2648SFlorian Fainelli struct ethtool_rxnfc *nfc); 892f50f2127SFlorian Fainelli 893f50f2127SFlorian Fainelli /* 894f50f2127SFlorian Fainelli * TC integration 895f50f2127SFlorian Fainelli */ 896ed11bb1fSVladimir Oltean int (*cls_flower_add)(struct dsa_switch *ds, int port, 897ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, bool ingress); 898ed11bb1fSVladimir Oltean int (*cls_flower_del)(struct dsa_switch *ds, int port, 899ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, bool ingress); 900ed11bb1fSVladimir Oltean int (*cls_flower_stats)(struct dsa_switch *ds, int port, 901ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, bool ingress); 902f50f2127SFlorian Fainelli int (*port_mirror_add)(struct dsa_switch *ds, int port, 903f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror, 904f50f2127SFlorian Fainelli bool ingress); 905f50f2127SFlorian Fainelli void (*port_mirror_del)(struct dsa_switch *ds, int port, 906f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror); 90734297176SVladimir Oltean int (*port_policer_add)(struct dsa_switch *ds, int port, 90834297176SVladimir Oltean struct dsa_mall_policer_tc_entry *policer); 90934297176SVladimir Oltean void (*port_policer_del)(struct dsa_switch *ds, int port); 91047d23af2SVladimir Oltean int (*port_setup_tc)(struct dsa_switch *ds, int port, 91147d23af2SVladimir Oltean enum tc_setup_type type, void *type_data); 91240ef2c93SVivien Didelot 91340ef2c93SVivien Didelot /* 91440ef2c93SVivien Didelot * Cross-chip operations 91540ef2c93SVivien Didelot */ 916f66a6a69SVladimir Oltean int (*crosschip_bridge_join)(struct dsa_switch *ds, int tree_index, 917f66a6a69SVladimir Oltean int sw_index, int port, 918d3eed0e5SVladimir Oltean struct dsa_bridge bridge); 919f66a6a69SVladimir Oltean void (*crosschip_bridge_leave)(struct dsa_switch *ds, int tree_index, 920f66a6a69SVladimir Oltean int sw_index, int port, 921d3eed0e5SVladimir Oltean struct dsa_bridge bridge); 922058102a6STobias Waldekranz int (*crosschip_lag_change)(struct dsa_switch *ds, int sw_index, 923058102a6STobias Waldekranz int port); 924058102a6STobias Waldekranz int (*crosschip_lag_join)(struct dsa_switch *ds, int sw_index, 925058102a6STobias Waldekranz int port, struct net_device *lag, 926058102a6STobias Waldekranz struct netdev_lag_upper_info *info); 927058102a6STobias Waldekranz int (*crosschip_lag_leave)(struct dsa_switch *ds, int sw_index, 928058102a6STobias Waldekranz int port, struct net_device *lag); 9290336369dSBrandon Streiff 9300336369dSBrandon Streiff /* 9310336369dSBrandon Streiff * PTP functionality 9320336369dSBrandon Streiff */ 9330336369dSBrandon Streiff int (*port_hwtstamp_get)(struct dsa_switch *ds, int port, 9340336369dSBrandon Streiff struct ifreq *ifr); 9350336369dSBrandon Streiff int (*port_hwtstamp_set)(struct dsa_switch *ds, int port, 9360336369dSBrandon Streiff struct ifreq *ifr); 9375c5416f5SYangbo Lu void (*port_txtstamp)(struct dsa_switch *ds, int port, 9385c5416f5SYangbo Lu struct sk_buff *skb); 93990af1059SBrandon Streiff bool (*port_rxtstamp)(struct dsa_switch *ds, int port, 94090af1059SBrandon Streiff struct sk_buff *skb, unsigned int type); 94197a69a0dSVladimir Oltean 9420f06b855SAndrew Lunn /* Devlink parameters, etc */ 9436b297524SAndrew Lunn int (*devlink_param_get)(struct dsa_switch *ds, u32 id, 9446b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx); 9456b297524SAndrew Lunn int (*devlink_param_set)(struct dsa_switch *ds, u32 id, 9466b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx); 9470f06b855SAndrew Lunn int (*devlink_info_get)(struct dsa_switch *ds, 9480f06b855SAndrew Lunn struct devlink_info_req *req, 9490f06b855SAndrew Lunn struct netlink_ext_ack *extack); 9502a6ef763SVladimir Oltean int (*devlink_sb_pool_get)(struct dsa_switch *ds, 9512a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index, 9522a6ef763SVladimir Oltean struct devlink_sb_pool_info *pool_info); 9532a6ef763SVladimir Oltean int (*devlink_sb_pool_set)(struct dsa_switch *ds, unsigned int sb_index, 9542a6ef763SVladimir Oltean u16 pool_index, u32 size, 9552a6ef763SVladimir Oltean enum devlink_sb_threshold_type threshold_type, 9562a6ef763SVladimir Oltean struct netlink_ext_ack *extack); 9572a6ef763SVladimir Oltean int (*devlink_sb_port_pool_get)(struct dsa_switch *ds, int port, 9582a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index, 9592a6ef763SVladimir Oltean u32 *p_threshold); 9602a6ef763SVladimir Oltean int (*devlink_sb_port_pool_set)(struct dsa_switch *ds, int port, 9612a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index, 9622a6ef763SVladimir Oltean u32 threshold, 9632a6ef763SVladimir Oltean struct netlink_ext_ack *extack); 9642a6ef763SVladimir Oltean int (*devlink_sb_tc_pool_bind_get)(struct dsa_switch *ds, int port, 9652a6ef763SVladimir Oltean unsigned int sb_index, u16 tc_index, 9662a6ef763SVladimir Oltean enum devlink_sb_pool_type pool_type, 9672a6ef763SVladimir Oltean u16 *p_pool_index, u32 *p_threshold); 9682a6ef763SVladimir Oltean int (*devlink_sb_tc_pool_bind_set)(struct dsa_switch *ds, int port, 9692a6ef763SVladimir Oltean unsigned int sb_index, u16 tc_index, 9702a6ef763SVladimir Oltean enum devlink_sb_pool_type pool_type, 9712a6ef763SVladimir Oltean u16 pool_index, u32 threshold, 9722a6ef763SVladimir Oltean struct netlink_ext_ack *extack); 9732a6ef763SVladimir Oltean int (*devlink_sb_occ_snapshot)(struct dsa_switch *ds, 9742a6ef763SVladimir Oltean unsigned int sb_index); 9752a6ef763SVladimir Oltean int (*devlink_sb_occ_max_clear)(struct dsa_switch *ds, 9762a6ef763SVladimir Oltean unsigned int sb_index); 9772a6ef763SVladimir Oltean int (*devlink_sb_occ_port_pool_get)(struct dsa_switch *ds, int port, 9782a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index, 9792a6ef763SVladimir Oltean u32 *p_cur, u32 *p_max); 9802a6ef763SVladimir Oltean int (*devlink_sb_occ_tc_port_bind_get)(struct dsa_switch *ds, int port, 9812a6ef763SVladimir Oltean unsigned int sb_index, u16 tc_index, 9822a6ef763SVladimir Oltean enum devlink_sb_pool_type pool_type, 9832a6ef763SVladimir Oltean u32 *p_cur, u32 *p_max); 984bfcb8132SVladimir Oltean 985bfcb8132SVladimir Oltean /* 986bfcb8132SVladimir Oltean * MTU change functionality. Switches can also adjust their MRU through 987bfcb8132SVladimir Oltean * this method. By MTU, one understands the SDU (L2 payload) length. 988bfcb8132SVladimir Oltean * If the switch needs to account for the DSA tag on the CPU port, this 989ab88d64aSRandy Dunlap * method needs to do so privately. 990bfcb8132SVladimir Oltean */ 991bfcb8132SVladimir Oltean int (*port_change_mtu)(struct dsa_switch *ds, int port, 992bfcb8132SVladimir Oltean int new_mtu); 993bfcb8132SVladimir Oltean int (*port_max_mtu)(struct dsa_switch *ds, int port); 994058102a6STobias Waldekranz 995058102a6STobias Waldekranz /* 996058102a6STobias Waldekranz * LAG integration 997058102a6STobias Waldekranz */ 998058102a6STobias Waldekranz int (*port_lag_change)(struct dsa_switch *ds, int port); 999058102a6STobias Waldekranz int (*port_lag_join)(struct dsa_switch *ds, int port, 1000058102a6STobias Waldekranz struct net_device *lag, 1001058102a6STobias Waldekranz struct netdev_lag_upper_info *info); 1002058102a6STobias Waldekranz int (*port_lag_leave)(struct dsa_switch *ds, int port, 1003058102a6STobias Waldekranz struct net_device *lag); 100418596f50SGeorge McCollister 100518596f50SGeorge McCollister /* 100618596f50SGeorge McCollister * HSR integration 100718596f50SGeorge McCollister */ 100818596f50SGeorge McCollister int (*port_hsr_join)(struct dsa_switch *ds, int port, 100918596f50SGeorge McCollister struct net_device *hsr); 101018596f50SGeorge McCollister int (*port_hsr_leave)(struct dsa_switch *ds, int port, 101118596f50SGeorge McCollister struct net_device *hsr); 1012c595c433SHoratiu Vultur 1013c595c433SHoratiu Vultur /* 1014c595c433SHoratiu Vultur * MRP integration 1015c595c433SHoratiu Vultur */ 1016c595c433SHoratiu Vultur int (*port_mrp_add)(struct dsa_switch *ds, int port, 1017c595c433SHoratiu Vultur const struct switchdev_obj_mrp *mrp); 1018c595c433SHoratiu Vultur int (*port_mrp_del)(struct dsa_switch *ds, int port, 1019c595c433SHoratiu Vultur const struct switchdev_obj_mrp *mrp); 1020c595c433SHoratiu Vultur int (*port_mrp_add_ring_role)(struct dsa_switch *ds, int port, 1021c595c433SHoratiu Vultur const struct switchdev_obj_ring_role_mrp *mrp); 1022c595c433SHoratiu Vultur int (*port_mrp_del_ring_role)(struct dsa_switch *ds, int port, 1023c595c433SHoratiu Vultur const struct switchdev_obj_ring_role_mrp *mrp); 10245da11eb4SVladimir Oltean 10255da11eb4SVladimir Oltean /* 10265da11eb4SVladimir Oltean * tag_8021q operations 10275da11eb4SVladimir Oltean */ 10285da11eb4SVladimir Oltean int (*tag_8021q_vlan_add)(struct dsa_switch *ds, int port, u16 vid, 10295da11eb4SVladimir Oltean u16 flags); 10305da11eb4SVladimir Oltean int (*tag_8021q_vlan_del)(struct dsa_switch *ds, int port, u16 vid); 10316b297524SAndrew Lunn }; 10326b297524SAndrew Lunn 10336b297524SAndrew Lunn #define DSA_DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes) \ 10346b297524SAndrew Lunn DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, \ 10356b297524SAndrew Lunn dsa_devlink_param_get, dsa_devlink_param_set, NULL) 10366b297524SAndrew Lunn 10376b297524SAndrew Lunn int dsa_devlink_param_get(struct devlink *dl, u32 id, 10386b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx); 10396b297524SAndrew Lunn int dsa_devlink_param_set(struct devlink *dl, u32 id, 10406b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx); 10416b297524SAndrew Lunn int dsa_devlink_params_register(struct dsa_switch *ds, 10426b297524SAndrew Lunn const struct devlink_param *params, 10436b297524SAndrew Lunn size_t params_count); 10446b297524SAndrew Lunn void dsa_devlink_params_unregister(struct dsa_switch *ds, 10456b297524SAndrew Lunn const struct devlink_param *params, 10466b297524SAndrew Lunn size_t params_count); 10475cd73fbdSAndrew Lunn int dsa_devlink_resource_register(struct dsa_switch *ds, 10485cd73fbdSAndrew Lunn const char *resource_name, 10495cd73fbdSAndrew Lunn u64 resource_size, 10505cd73fbdSAndrew Lunn u64 resource_id, 10515cd73fbdSAndrew Lunn u64 parent_resource_id, 10525cd73fbdSAndrew Lunn const struct devlink_resource_size_params *size_params); 10535cd73fbdSAndrew Lunn 10545cd73fbdSAndrew Lunn void dsa_devlink_resources_unregister(struct dsa_switch *ds); 10555cd73fbdSAndrew Lunn 10565cd73fbdSAndrew Lunn void dsa_devlink_resource_occ_get_register(struct dsa_switch *ds, 10575cd73fbdSAndrew Lunn u64 resource_id, 10585cd73fbdSAndrew Lunn devlink_resource_occ_get_t *occ_get, 10595cd73fbdSAndrew Lunn void *occ_get_priv); 10605cd73fbdSAndrew Lunn void dsa_devlink_resource_occ_get_unregister(struct dsa_switch *ds, 10615cd73fbdSAndrew Lunn u64 resource_id); 106297c82c23SAndrew Lunn struct devlink_region * 106397c82c23SAndrew Lunn dsa_devlink_region_create(struct dsa_switch *ds, 106497c82c23SAndrew Lunn const struct devlink_region_ops *ops, 106597c82c23SAndrew Lunn u32 region_max_snapshots, u64 region_size); 106608156ba4SAndrew Lunn struct devlink_region * 106708156ba4SAndrew Lunn dsa_devlink_port_region_create(struct dsa_switch *ds, 106808156ba4SAndrew Lunn int port, 106908156ba4SAndrew Lunn const struct devlink_port_region_ops *ops, 107008156ba4SAndrew Lunn u32 region_max_snapshots, u64 region_size); 107197c82c23SAndrew Lunn void dsa_devlink_region_destroy(struct devlink_region *region); 107297c82c23SAndrew Lunn 1073e1eea811SVladimir Oltean struct dsa_port *dsa_port_from_netdev(struct net_device *netdev); 10745cd73fbdSAndrew Lunn 10756b297524SAndrew Lunn struct dsa_devlink_priv { 10766b297524SAndrew Lunn struct dsa_switch *ds; 1077c8f0b869SBen Hutchings }; 1078c8f0b869SBen Hutchings 1079ccc3e6b0SAndrew Lunn static inline struct dsa_switch *dsa_devlink_to_ds(struct devlink *dl) 1080ccc3e6b0SAndrew Lunn { 1081ccc3e6b0SAndrew Lunn struct dsa_devlink_priv *dl_priv = devlink_priv(dl); 1082ccc3e6b0SAndrew Lunn 1083ccc3e6b0SAndrew Lunn return dl_priv->ds; 1084ccc3e6b0SAndrew Lunn } 1085ccc3e6b0SAndrew Lunn 10867d1e2a10SAndrew Lunn static inline 10877d1e2a10SAndrew Lunn struct dsa_switch *dsa_devlink_port_to_ds(struct devlink_port *port) 10887d1e2a10SAndrew Lunn { 10897d1e2a10SAndrew Lunn struct devlink *dl = port->devlink; 10907d1e2a10SAndrew Lunn struct dsa_devlink_priv *dl_priv = devlink_priv(dl); 10917d1e2a10SAndrew Lunn 10927d1e2a10SAndrew Lunn return dl_priv->ds; 10937d1e2a10SAndrew Lunn } 10947d1e2a10SAndrew Lunn 10957d1e2a10SAndrew Lunn static inline int dsa_devlink_port_to_port(struct devlink_port *port) 10967d1e2a10SAndrew Lunn { 10977d1e2a10SAndrew Lunn return port->index; 10987d1e2a10SAndrew Lunn } 10997d1e2a10SAndrew Lunn 1100ab3d408dSFlorian Fainelli struct dsa_switch_driver { 1101ab3d408dSFlorian Fainelli struct list_head list; 1102a82f67afSFlorian Fainelli const struct dsa_switch_ops *ops; 1103ab3d408dSFlorian Fainelli }; 1104ab3d408dSFlorian Fainelli 110514b89f36SFlorian Fainelli struct net_device *dsa_dev_to_net_device(struct device *dev); 1106c8f0b869SBen Hutchings 110773a7ece8SVivien Didelot /* Keep inline for faster access in hot path */ 11089eb8eff0SVladimir Oltean static inline bool netdev_uses_dsa(const struct net_device *dev) 1109c6e970a0SAndrew Lunn { 1110c6e970a0SAndrew Lunn #if IS_ENABLED(CONFIG_NET_DSA) 1111717ffbfbSVivien Didelot return dev->dsa_ptr && dev->dsa_ptr->rcv; 1112c6e970a0SAndrew Lunn #endif 1113c6e970a0SAndrew Lunn return false; 1114c6e970a0SAndrew Lunn } 1115c6e970a0SAndrew Lunn 11169790cf20SVladimir Oltean /* All DSA tags that push the EtherType to the right (basically all except tail 11179790cf20SVladimir Oltean * tags, which don't break dissection) can be treated the same from the 11189790cf20SVladimir Oltean * perspective of the flow dissector. 11199790cf20SVladimir Oltean * 11209790cf20SVladimir Oltean * We need to return: 11219790cf20SVladimir Oltean * - offset: the (B - A) difference between: 11229790cf20SVladimir Oltean * A. the position of the real EtherType and 11239790cf20SVladimir Oltean * B. the current skb->data (aka ETH_HLEN bytes into the frame, aka 2 bytes 11249790cf20SVladimir Oltean * after the normal EtherType was supposed to be) 11259790cf20SVladimir Oltean * The offset in bytes is exactly equal to the tagger overhead (and half of 11269790cf20SVladimir Oltean * that, in __be16 shorts). 11279790cf20SVladimir Oltean * 11289790cf20SVladimir Oltean * - proto: the value of the real EtherType. 11299790cf20SVladimir Oltean */ 11309790cf20SVladimir Oltean static inline void dsa_tag_generic_flow_dissect(const struct sk_buff *skb, 11319790cf20SVladimir Oltean __be16 *proto, int *offset) 11329790cf20SVladimir Oltean { 11339790cf20SVladimir Oltean #if IS_ENABLED(CONFIG_NET_DSA) 11349790cf20SVladimir Oltean const struct dsa_device_ops *ops = skb->dev->dsa_ptr->tag_ops; 11354e500251SVladimir Oltean int tag_len = ops->needed_headroom; 11369790cf20SVladimir Oltean 11379790cf20SVladimir Oltean *offset = tag_len; 11389790cf20SVladimir Oltean *proto = ((__be16 *)skb->data)[(tag_len / 2) - 1]; 11399790cf20SVladimir Oltean #endif 11409790cf20SVladimir Oltean } 11419790cf20SVladimir Oltean 11424cfab356SFlorian Fainelli #if IS_ENABLED(CONFIG_NET_DSA) 11434cfab356SFlorian Fainelli static inline int __dsa_netdevice_ops_check(struct net_device *dev) 11444cfab356SFlorian Fainelli { 11454cfab356SFlorian Fainelli int err = -EOPNOTSUPP; 11464cfab356SFlorian Fainelli 11474cfab356SFlorian Fainelli if (!dev->dsa_ptr) 11484cfab356SFlorian Fainelli return err; 11494cfab356SFlorian Fainelli 11504cfab356SFlorian Fainelli if (!dev->dsa_ptr->netdev_ops) 11514cfab356SFlorian Fainelli return err; 11524cfab356SFlorian Fainelli 11534cfab356SFlorian Fainelli return 0; 11544cfab356SFlorian Fainelli } 11554cfab356SFlorian Fainelli 1156a7605370SArnd Bergmann static inline int dsa_ndo_eth_ioctl(struct net_device *dev, struct ifreq *ifr, 11574cfab356SFlorian Fainelli int cmd) 11584cfab356SFlorian Fainelli { 11594cfab356SFlorian Fainelli const struct dsa_netdevice_ops *ops; 11604cfab356SFlorian Fainelli int err; 11614cfab356SFlorian Fainelli 11624cfab356SFlorian Fainelli err = __dsa_netdevice_ops_check(dev); 11634cfab356SFlorian Fainelli if (err) 11644cfab356SFlorian Fainelli return err; 11654cfab356SFlorian Fainelli 11664cfab356SFlorian Fainelli ops = dev->dsa_ptr->netdev_ops; 11674cfab356SFlorian Fainelli 1168a7605370SArnd Bergmann return ops->ndo_eth_ioctl(dev, ifr, cmd); 11694cfab356SFlorian Fainelli } 11704cfab356SFlorian Fainelli #else 1171a7605370SArnd Bergmann static inline int dsa_ndo_eth_ioctl(struct net_device *dev, struct ifreq *ifr, 11724cfab356SFlorian Fainelli int cmd) 11734cfab356SFlorian Fainelli { 11744cfab356SFlorian Fainelli return -EOPNOTSUPP; 11754cfab356SFlorian Fainelli } 11764cfab356SFlorian Fainelli #endif 11774cfab356SFlorian Fainelli 117883c0afaeSAndrew Lunn void dsa_unregister_switch(struct dsa_switch *ds); 117923c9ee49SVivien Didelot int dsa_register_switch(struct dsa_switch *ds); 11800650bf52SVladimir Oltean void dsa_switch_shutdown(struct dsa_switch *ds); 11813b7bc1f0SVladimir Oltean struct dsa_switch *dsa_switch_find(int tree_index, int sw_index); 1182ea825e70SFlorian Fainelli #ifdef CONFIG_PM_SLEEP 1183ea825e70SFlorian Fainelli int dsa_switch_suspend(struct dsa_switch *ds); 1184ea825e70SFlorian Fainelli int dsa_switch_resume(struct dsa_switch *ds); 1185ea825e70SFlorian Fainelli #else 1186ea825e70SFlorian Fainelli static inline int dsa_switch_suspend(struct dsa_switch *ds) 1187ea825e70SFlorian Fainelli { 1188ea825e70SFlorian Fainelli return 0; 1189ea825e70SFlorian Fainelli } 1190ea825e70SFlorian Fainelli static inline int dsa_switch_resume(struct dsa_switch *ds) 1191ea825e70SFlorian Fainelli { 1192ea825e70SFlorian Fainelli return 0; 1193ea825e70SFlorian Fainelli } 1194ea825e70SFlorian Fainelli #endif /* CONFIG_PM_SLEEP */ 1195ea825e70SFlorian Fainelli 119660724d4bSFlorian Fainelli #if IS_ENABLED(CONFIG_NET_DSA) 1197a5e3c9baSVladimir Oltean bool dsa_slave_dev_check(const struct net_device *dev); 119860724d4bSFlorian Fainelli #else 1199a5e3c9baSVladimir Oltean static inline bool dsa_slave_dev_check(const struct net_device *dev) 1200a5e3c9baSVladimir Oltean { 1201a5e3c9baSVladimir Oltean return false; 1202a5e3c9baSVladimir Oltean } 120360724d4bSFlorian Fainelli #endif 120460724d4bSFlorian Fainelli 120597a69a0dSVladimir Oltean netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, struct net_device *dev); 1206cf963573SFlorian Fainelli int dsa_port_get_phy_strings(struct dsa_port *dp, uint8_t *data); 1207cf963573SFlorian Fainelli int dsa_port_get_ethtool_phy_stats(struct dsa_port *dp, uint64_t *data); 1208cf963573SFlorian Fainelli int dsa_port_get_phy_sset_count(struct dsa_port *dp); 120911d8f3ddSFlorian Fainelli void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up); 1210cf963573SFlorian Fainelli 1211d3b8c049SAndrew Lunn struct dsa_tag_driver { 1212d3b8c049SAndrew Lunn const struct dsa_device_ops *ops; 1213d3b8c049SAndrew Lunn struct list_head list; 1214d3b8c049SAndrew Lunn struct module *owner; 1215d3b8c049SAndrew Lunn }; 1216d3b8c049SAndrew Lunn 1217d3b8c049SAndrew Lunn void dsa_tag_drivers_register(struct dsa_tag_driver *dsa_tag_driver_array[], 1218d3b8c049SAndrew Lunn unsigned int count, 1219d3b8c049SAndrew Lunn struct module *owner); 1220d3b8c049SAndrew Lunn void dsa_tag_drivers_unregister(struct dsa_tag_driver *dsa_tag_driver_array[], 1221d3b8c049SAndrew Lunn unsigned int count); 1222d3b8c049SAndrew Lunn 1223d3b8c049SAndrew Lunn #define dsa_tag_driver_module_drivers(__dsa_tag_drivers_array, __count) \ 1224d3b8c049SAndrew Lunn static int __init dsa_tag_driver_module_init(void) \ 1225d3b8c049SAndrew Lunn { \ 1226d3b8c049SAndrew Lunn dsa_tag_drivers_register(__dsa_tag_drivers_array, __count, \ 1227d3b8c049SAndrew Lunn THIS_MODULE); \ 1228d3b8c049SAndrew Lunn return 0; \ 1229d3b8c049SAndrew Lunn } \ 1230d3b8c049SAndrew Lunn module_init(dsa_tag_driver_module_init); \ 1231d3b8c049SAndrew Lunn \ 1232d3b8c049SAndrew Lunn static void __exit dsa_tag_driver_module_exit(void) \ 1233d3b8c049SAndrew Lunn { \ 1234d3b8c049SAndrew Lunn dsa_tag_drivers_unregister(__dsa_tag_drivers_array, __count); \ 1235d3b8c049SAndrew Lunn } \ 1236d3b8c049SAndrew Lunn module_exit(dsa_tag_driver_module_exit) 1237d3b8c049SAndrew Lunn 1238d3b8c049SAndrew Lunn /** 1239d3b8c049SAndrew Lunn * module_dsa_tag_drivers() - Helper macro for registering DSA tag 1240d3b8c049SAndrew Lunn * drivers 1241d3b8c049SAndrew Lunn * @__ops_array: Array of tag driver strucutres 1242d3b8c049SAndrew Lunn * 1243d3b8c049SAndrew Lunn * Helper macro for DSA tag drivers which do not do anything special 1244d3b8c049SAndrew Lunn * in module init/exit. Each module may only use this macro once, and 1245d3b8c049SAndrew Lunn * calling it replaces module_init() and module_exit(). 1246d3b8c049SAndrew Lunn */ 1247d3b8c049SAndrew Lunn #define module_dsa_tag_drivers(__ops_array) \ 1248d3b8c049SAndrew Lunn dsa_tag_driver_module_drivers(__ops_array, ARRAY_SIZE(__ops_array)) 1249d3b8c049SAndrew Lunn 1250d3b8c049SAndrew Lunn #define DSA_TAG_DRIVER_NAME(__ops) dsa_tag_driver ## _ ## __ops 1251d3b8c049SAndrew Lunn 1252d3b8c049SAndrew Lunn /* Create a static structure we can build a linked list of dsa_tag 1253d3b8c049SAndrew Lunn * drivers 1254d3b8c049SAndrew Lunn */ 1255d3b8c049SAndrew Lunn #define DSA_TAG_DRIVER(__ops) \ 1256d3b8c049SAndrew Lunn static struct dsa_tag_driver DSA_TAG_DRIVER_NAME(__ops) = { \ 1257d3b8c049SAndrew Lunn .ops = &__ops, \ 1258d3b8c049SAndrew Lunn } 1259d3b8c049SAndrew Lunn 1260d3b8c049SAndrew Lunn /** 1261d3b8c049SAndrew Lunn * module_dsa_tag_driver() - Helper macro for registering a single DSA tag 1262d3b8c049SAndrew Lunn * driver 1263d3b8c049SAndrew Lunn * @__ops: Single tag driver structures 1264d3b8c049SAndrew Lunn * 1265d3b8c049SAndrew Lunn * Helper macro for DSA tag drivers which do not do anything special 1266d3b8c049SAndrew Lunn * in module init/exit. Each module may only use this macro once, and 1267d3b8c049SAndrew Lunn * calling it replaces module_init() and module_exit(). 1268d3b8c049SAndrew Lunn */ 1269d3b8c049SAndrew Lunn #define module_dsa_tag_driver(__ops) \ 1270d3b8c049SAndrew Lunn DSA_TAG_DRIVER(__ops); \ 1271d3b8c049SAndrew Lunn \ 1272d3b8c049SAndrew Lunn static struct dsa_tag_driver *dsa_tag_driver_array[] = { \ 1273d3b8c049SAndrew Lunn &DSA_TAG_DRIVER_NAME(__ops) \ 1274d3b8c049SAndrew Lunn }; \ 1275d3b8c049SAndrew Lunn module_dsa_tag_drivers(dsa_tag_driver_array) 127691da11f8SLennert Buytenhek #endif 1277d3b8c049SAndrew Lunn 1278