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 8290af1059SBrandon Streiff struct dsa_switch; 833e8a72d1SFlorian Fainelli 8468277a2cSJohn Crispin struct dsa_device_ops { 8568277a2cSJohn Crispin struct sk_buff *(*xmit)(struct sk_buff *skb, struct net_device *dev); 8629a097b7SVladimir Oltean struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev); 872e8cb1b3SVladimir Oltean void (*flow_dissect)(const struct sk_buff *skb, __be16 *proto, 88598a9680SJohn Crispin int *offset); 894e500251SVladimir Oltean unsigned int needed_headroom; 904e500251SVladimir Oltean unsigned int needed_tailroom; 91875138f8SAndrew Lunn const char *name; 92056eed2fSAndrew Lunn enum dsa_tag_protocol proto; 93c3975400SVladimir Oltean /* Some tagging protocols either mangle or shift the destination MAC 94c3975400SVladimir Oltean * address, in which case the DSA master would drop packets on ingress 95c3975400SVladimir Oltean * if what it understands out of the destination MAC address is not in 96c3975400SVladimir Oltean * its RX filter. 97c3975400SVladimir Oltean */ 98c3975400SVladimir Oltean bool promisc_on_master; 9968277a2cSJohn Crispin }; 10068277a2cSJohn Crispin 1014cfab356SFlorian Fainelli /* This structure defines the control interfaces that are overlayed by the 1024cfab356SFlorian Fainelli * DSA layer on top of the DSA CPU/management net_device instance. This is 1034cfab356SFlorian Fainelli * used by the core net_device layer while calling various net_device_ops 1044cfab356SFlorian Fainelli * function pointers. 1054cfab356SFlorian Fainelli */ 1064cfab356SFlorian Fainelli struct dsa_netdevice_ops { 107a7605370SArnd Bergmann int (*ndo_eth_ioctl)(struct net_device *dev, struct ifreq *ifr, 1084cfab356SFlorian Fainelli int cmd); 1094cfab356SFlorian Fainelli }; 1104cfab356SFlorian Fainelli 1110b42f033SAndrew Lunn #define DSA_TAG_DRIVER_ALIAS "dsa_tag-" 1120b42f033SAndrew Lunn #define MODULE_ALIAS_DSA_TAG_DRIVER(__proto) \ 1130b42f033SAndrew Lunn MODULE_ALIAS(DSA_TAG_DRIVER_ALIAS __stringify(__proto##_VALUE)) 1140b42f033SAndrew Lunn 115cf50dcc2SBen Hutchings struct dsa_switch_tree { 11683c0afaeSAndrew Lunn struct list_head list; 11783c0afaeSAndrew Lunn 118f515f192SVivien Didelot /* Notifier chain for switch-wide events */ 119f515f192SVivien Didelot struct raw_notifier_head nh; 120f515f192SVivien Didelot 12183c0afaeSAndrew Lunn /* Tree identifier */ 12249463b7fSVivien Didelot unsigned int index; 12383c0afaeSAndrew Lunn 12483c0afaeSAndrew Lunn /* Number of switches attached to this tree */ 12583c0afaeSAndrew Lunn struct kref refcount; 12683c0afaeSAndrew Lunn 12783c0afaeSAndrew Lunn /* Has this tree been applied to the hardware? */ 128ec15dd42SVivien Didelot bool setup; 12983c0afaeSAndrew Lunn 130357f203bSVladimir Oltean /* Tagging protocol operations */ 131357f203bSVladimir Oltean const struct dsa_device_ops *tag_ops; 132357f203bSVladimir Oltean 133deff7107STobias Waldekranz /* Default tagging protocol preferred by the switches in this 134deff7107STobias Waldekranz * tree. 135deff7107STobias Waldekranz */ 136deff7107STobias Waldekranz enum dsa_tag_protocol default_proto; 137deff7107STobias Waldekranz 138cf50dcc2SBen Hutchings /* 139cf50dcc2SBen Hutchings * Configuration data for the platform device that owns 140cf50dcc2SBen Hutchings * this dsa switch tree instance. 141cf50dcc2SBen Hutchings */ 142cf50dcc2SBen Hutchings struct dsa_platform_data *pd; 143cf85d08fSLennert Buytenhek 144ab8ccae1SVivien Didelot /* List of switch ports */ 145ab8ccae1SVivien Didelot struct list_head ports; 146ab8ccae1SVivien Didelot 147c5f51765SVivien Didelot /* List of DSA links composing the routing table */ 148c5f51765SVivien Didelot struct list_head rtable; 149058102a6STobias Waldekranz 150058102a6STobias Waldekranz /* Maps offloaded LAG netdevs to a zero-based linear ID for 151058102a6STobias Waldekranz * drivers that need it. 152058102a6STobias Waldekranz */ 153058102a6STobias Waldekranz struct net_device **lags; 154058102a6STobias Waldekranz unsigned int lags_len; 1555b22d366SVladimir Oltean 1565b22d366SVladimir Oltean /* Track the largest switch index within a tree */ 1575b22d366SVladimir Oltean unsigned int last_switch; 158cf50dcc2SBen Hutchings }; 159cf50dcc2SBen Hutchings 160058102a6STobias Waldekranz #define dsa_lags_foreach_id(_id, _dst) \ 161058102a6STobias Waldekranz for ((_id) = 0; (_id) < (_dst)->lags_len; (_id)++) \ 162058102a6STobias Waldekranz if ((_dst)->lags[(_id)]) 163058102a6STobias Waldekranz 164058102a6STobias Waldekranz #define dsa_lag_foreach_port(_dp, _dst, _lag) \ 165058102a6STobias Waldekranz list_for_each_entry((_dp), &(_dst)->ports, list) \ 166058102a6STobias Waldekranz if ((_dp)->lag_dev == (_lag)) 167058102a6STobias Waldekranz 16818596f50SGeorge McCollister #define dsa_hsr_foreach_port(_dp, _ds, _hsr) \ 16918596f50SGeorge McCollister list_for_each_entry((_dp), &(_ds)->dst->ports, list) \ 17018596f50SGeorge McCollister if ((_dp)->ds == (_ds) && (_dp)->hsr_dev == (_hsr)) 17118596f50SGeorge McCollister 172058102a6STobias Waldekranz static inline struct net_device *dsa_lag_dev(struct dsa_switch_tree *dst, 173058102a6STobias Waldekranz unsigned int id) 174058102a6STobias Waldekranz { 175058102a6STobias Waldekranz return dst->lags[id]; 176058102a6STobias Waldekranz } 177058102a6STobias Waldekranz 178058102a6STobias Waldekranz static inline int dsa_lag_id(struct dsa_switch_tree *dst, 179058102a6STobias Waldekranz struct net_device *lag) 180058102a6STobias Waldekranz { 181058102a6STobias Waldekranz unsigned int id; 182058102a6STobias Waldekranz 183058102a6STobias Waldekranz dsa_lags_foreach_id(id, dst) { 184058102a6STobias Waldekranz if (dsa_lag_dev(dst, id) == lag) 185058102a6STobias Waldekranz return id; 186058102a6STobias Waldekranz } 187058102a6STobias Waldekranz 188058102a6STobias Waldekranz return -ENODEV; 189058102a6STobias Waldekranz } 190058102a6STobias Waldekranz 19134297176SVladimir Oltean /* TC matchall action types */ 192f50f2127SFlorian Fainelli enum dsa_port_mall_action_type { 193f50f2127SFlorian Fainelli DSA_PORT_MALL_MIRROR, 19434297176SVladimir Oltean DSA_PORT_MALL_POLICER, 195f50f2127SFlorian Fainelli }; 196f50f2127SFlorian Fainelli 197f50f2127SFlorian Fainelli /* TC mirroring entry */ 198f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry { 199f50f2127SFlorian Fainelli u8 to_local_port; 200f50f2127SFlorian Fainelli bool ingress; 201f50f2127SFlorian Fainelli }; 202f50f2127SFlorian Fainelli 20334297176SVladimir Oltean /* TC port policer entry */ 20434297176SVladimir Oltean struct dsa_mall_policer_tc_entry { 2055f035af7SPo Liu u32 burst; 20634297176SVladimir Oltean u64 rate_bytes_per_sec; 20734297176SVladimir Oltean }; 20834297176SVladimir Oltean 209f50f2127SFlorian Fainelli /* TC matchall entry */ 210f50f2127SFlorian Fainelli struct dsa_mall_tc_entry { 211f50f2127SFlorian Fainelli struct list_head list; 212f50f2127SFlorian Fainelli unsigned long cookie; 213f50f2127SFlorian Fainelli enum dsa_port_mall_action_type type; 214f50f2127SFlorian Fainelli union { 215f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry mirror; 21634297176SVladimir Oltean struct dsa_mall_policer_tc_entry policer; 217f50f2127SFlorian Fainelli }; 218f50f2127SFlorian Fainelli }; 219f50f2127SFlorian Fainelli 220f50f2127SFlorian Fainelli 221c8b09808SAndrew Lunn struct dsa_port { 222f8b8b1cdSVivien Didelot /* A CPU port is physically connected to a master device. 223f8b8b1cdSVivien Didelot * A user port exposed to userspace has a slave device. 224f8b8b1cdSVivien Didelot */ 225f8b8b1cdSVivien Didelot union { 226f8b8b1cdSVivien Didelot struct net_device *master; 227f8b8b1cdSVivien Didelot struct net_device *slave; 228f8b8b1cdSVivien Didelot }; 229f8b8b1cdSVivien Didelot 230357f203bSVladimir Oltean /* Copy of the tagging protocol operations, for quicker access 231357f203bSVladimir Oltean * in the data path. Valid only for the CPU ports. 232357f203bSVladimir Oltean */ 23315240248SVivien Didelot const struct dsa_device_ops *tag_ops; 23415240248SVivien Didelot 2353e41f93bSVivien Didelot /* Copies for faster access in master receive hot path */ 2363e41f93bSVivien Didelot struct dsa_switch_tree *dst; 23729a097b7SVladimir Oltean struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev); 2383e41f93bSVivien Didelot 239057cad2cSVivien Didelot enum { 240057cad2cSVivien Didelot DSA_PORT_TYPE_UNUSED = 0, 241057cad2cSVivien Didelot DSA_PORT_TYPE_CPU, 242057cad2cSVivien Didelot DSA_PORT_TYPE_DSA, 243057cad2cSVivien Didelot DSA_PORT_TYPE_USER, 244057cad2cSVivien Didelot } type; 245057cad2cSVivien Didelot 246818be848SVivien Didelot struct dsa_switch *ds; 247818be848SVivien Didelot unsigned int index; 24871e0bbdeSFlorian Fainelli const char *name; 24968b2d4a8SVivien Didelot struct dsa_port *cpu_dp; 25083216e39SMichael Walle u8 mac[ETH_ALEN]; 251189b0d93SAndrew Lunn struct device_node *dn; 25234a79f63SVivien Didelot unsigned int ageing_time; 25333162e9aSVladimir Oltean bool vlan_filtering; 2545313a37bSVladimir Oltean /* Managed by DSA on user ports and by drivers on CPU and DSA ports */ 255045c45d1SVladimir Oltean bool learning; 256732f794cSVivien Didelot u8 stp_state; 257a5e9a02eSVivien Didelot struct net_device *bridge_dev; 258123abc06SVladimir Oltean int bridge_num; 25996567d5dSAndrew Lunn struct devlink_port devlink_port; 2603122433eSAndrew Lunn bool devlink_port_setup; 261aab9c406SFlorian Fainelli struct phylink *pl; 26244cc27e4SIoana Ciornei struct phylink_config pl_config; 263058102a6STobias Waldekranz struct net_device *lag_dev; 264058102a6STobias Waldekranz bool lag_tx_enabled; 26518596f50SGeorge McCollister struct net_device *hsr_dev; 26697a69a0dSVladimir Oltean 267ab8ccae1SVivien Didelot struct list_head list; 268ab8ccae1SVivien Didelot 26967dbb9d4SFlorian Fainelli /* 270c362beb0SVladimir Oltean * Give the switch driver somewhere to hang its per-port private data 271c362beb0SVladimir Oltean * structures (accessible from the tagger). 272c362beb0SVladimir Oltean */ 273c362beb0SVladimir Oltean void *priv; 274c362beb0SVladimir Oltean 275c362beb0SVladimir Oltean /* 27667dbb9d4SFlorian Fainelli * Original copy of the master netdev ethtool_ops 27767dbb9d4SFlorian Fainelli */ 27867dbb9d4SFlorian Fainelli const struct ethtool_ops *orig_ethtool_ops; 279da7b9e9bSFlorian Fainelli 280da7b9e9bSFlorian Fainelli /* 281da7b9e9bSFlorian Fainelli * Original copy of the master netdev net_device_ops 282da7b9e9bSFlorian Fainelli */ 2834cfab356SFlorian Fainelli const struct dsa_netdevice_ops *netdev_ops; 284fb35c60cSVivien Didelot 285161ca59dSVladimir Oltean /* List of MAC addresses that must be forwarded on this port. 286161ca59dSVladimir Oltean * These are only valid on CPU ports and DSA links. 287161ca59dSVladimir Oltean */ 2883f6e32f9SVladimir Oltean struct list_head fdbs; 289161ca59dSVladimir Oltean struct list_head mdbs; 290161ca59dSVladimir Oltean 291fb35c60cSVivien Didelot bool setup; 292c8b09808SAndrew Lunn }; 293c8b09808SAndrew Lunn 294c5f51765SVivien Didelot /* TODO: ideally DSA ports would have a single dp->link_dp member, 295c5f51765SVivien Didelot * and no dst->rtable nor this struct dsa_link would be needed, 296c5f51765SVivien Didelot * but this would require some more complex tree walking, 297c5f51765SVivien Didelot * so keep it stupid at the moment and list them all. 298c5f51765SVivien Didelot */ 299c5f51765SVivien Didelot struct dsa_link { 300c5f51765SVivien Didelot struct dsa_port *dp; 301c5f51765SVivien Didelot struct dsa_port *link_dp; 302c5f51765SVivien Didelot struct list_head list; 303c5f51765SVivien Didelot }; 304c5f51765SVivien Didelot 305161ca59dSVladimir Oltean struct dsa_mac_addr { 306161ca59dSVladimir Oltean unsigned char addr[ETH_ALEN]; 307161ca59dSVladimir Oltean u16 vid; 308161ca59dSVladimir Oltean refcount_t refcount; 309161ca59dSVladimir Oltean struct list_head list; 310161ca59dSVladimir Oltean }; 311161ca59dSVladimir Oltean 312c8f0b869SBen Hutchings struct dsa_switch { 313fb35c60cSVivien Didelot bool setup; 314fb35c60cSVivien Didelot 315c33063d6SAndrew Lunn struct device *dev; 316c33063d6SAndrew Lunn 317c8f0b869SBen Hutchings /* 318c8f0b869SBen Hutchings * Parent switch tree, and switch index. 319c8f0b869SBen Hutchings */ 320c8f0b869SBen Hutchings struct dsa_switch_tree *dst; 32199feaafcSVivien Didelot unsigned int index; 322c8f0b869SBen Hutchings 323f515f192SVivien Didelot /* Listener for switch fabric events */ 324f515f192SVivien Didelot struct notifier_block nb; 325f515f192SVivien Didelot 326c8f0b869SBen Hutchings /* 3277543a6d5SAndrew Lunn * Give the switch driver somewhere to hang its private data 3287543a6d5SAndrew Lunn * structure. 3297543a6d5SAndrew Lunn */ 3307543a6d5SAndrew Lunn void *priv; 3317543a6d5SAndrew Lunn 3327543a6d5SAndrew Lunn /* 333c8f0b869SBen Hutchings * Configuration data for this switch. 334c8f0b869SBen Hutchings */ 335ff04955cSAndrew Lunn struct dsa_chip_data *cd; 336c8f0b869SBen Hutchings 337c8f0b869SBen Hutchings /* 3389d490b4eSVivien Didelot * The switch operations. 339c8f0b869SBen Hutchings */ 340a82f67afSFlorian Fainelli const struct dsa_switch_ops *ops; 341c8f0b869SBen Hutchings 34266472fc0SAndrew Lunn /* 343c8f0b869SBen Hutchings * Slave mii_bus and devices for the individual ports. 344c8f0b869SBen Hutchings */ 3450d8bcdd3SFlorian Fainelli u32 phys_mii_mask; 346c8f0b869SBen Hutchings struct mii_bus *slave_mii_bus; 347a0c02161SVivien Didelot 3480f3da6afSVivien Didelot /* Ageing Time limits in msecs */ 3490f3da6afSVivien Didelot unsigned int ageing_time_min; 3500f3da6afSVivien Didelot unsigned int ageing_time_max; 3510f3da6afSVivien Didelot 352d7b1fd52SVladimir Oltean /* Storage for drivers using tag_8021q */ 353d7b1fd52SVladimir Oltean struct dsa_8021q_context *tag_8021q_ctx; 354d7b1fd52SVladimir Oltean 35596567d5dSAndrew Lunn /* devlink used to represent this switch device */ 35696567d5dSAndrew Lunn struct devlink *devlink; 35796567d5dSAndrew Lunn 35855199df6SFlorian Fainelli /* Number of switch port queues */ 35955199df6SFlorian Fainelli unsigned int num_tx_queues; 36055199df6SFlorian Fainelli 3618f5d16f6SVladimir Oltean /* Disallow bridge core from requesting different VLAN awareness 3628f5d16f6SVladimir Oltean * settings on ports if not hardware-supported 3638f5d16f6SVladimir Oltean */ 3648f5d16f6SVladimir Oltean bool vlan_filtering_is_global; 3658f5d16f6SVladimir Oltean 36658adf9dcSVladimir Oltean /* Keep VLAN filtering enabled on ports not offloading any upper. */ 36758adf9dcSVladimir Oltean bool needs_standalone_vlan_filtering; 36858adf9dcSVladimir Oltean 36954a0ed0dSRussell King /* Pass .port_vlan_add and .port_vlan_del to drivers even for bridges 37054a0ed0dSRussell King * that have vlan_filtering=0. All drivers should ideally set this (and 37154a0ed0dSRussell King * then the option would get removed), but it is unknown whether this 37254a0ed0dSRussell King * would break things or not. 37354a0ed0dSRussell King */ 37454a0ed0dSRussell King bool configure_vlan_while_not_filtering; 37554a0ed0dSRussell King 3761dc0408cSFlorian Fainelli /* If the switch driver always programs the CPU port as egress tagged 3771dc0408cSFlorian Fainelli * despite the VLAN configuration indicating otherwise, then setting 3781dc0408cSFlorian Fainelli * @untag_bridge_pvid will force the DSA receive path to pop the bridge's 3791dc0408cSFlorian Fainelli * default_pvid VLAN tagged frames to offer a consistent behavior 3801dc0408cSFlorian Fainelli * between a vlan_filtering=0 and vlan_filtering=1 bridge device. 3811dc0408cSFlorian Fainelli */ 3821dc0408cSFlorian Fainelli bool untag_bridge_pvid; 3831dc0408cSFlorian Fainelli 384d5f19486SVladimir Oltean /* Let DSA manage the FDB entries towards the CPU, based on the 385d5f19486SVladimir Oltean * software bridge database. 386d5f19486SVladimir Oltean */ 387d5f19486SVladimir Oltean bool assisted_learning_on_cpu_port; 388d5f19486SVladimir Oltean 38914574676SVladimir Oltean /* In case vlan_filtering_is_global is set, the VLAN awareness state 39014574676SVladimir Oltean * should be retrieved from here and not from the per-port settings. 39114574676SVladimir Oltean */ 39214574676SVladimir Oltean bool vlan_filtering; 39314574676SVladimir Oltean 394787cac3fSVladimir Oltean /* MAC PCS does not provide link state change interrupt, and requires 395787cac3fSVladimir Oltean * polling. Flag passed on to PHYLINK. 396787cac3fSVladimir Oltean */ 397787cac3fSVladimir Oltean bool pcs_poll; 398787cac3fSVladimir Oltean 399bff33f7eSVladimir Oltean /* For switches that only have the MRU configurable. To ensure the 400bff33f7eSVladimir Oltean * configured MTU is not exceeded, normalization of MRU on all bridged 401bff33f7eSVladimir Oltean * interfaces is needed. 402bff33f7eSVladimir Oltean */ 403bff33f7eSVladimir Oltean bool mtu_enforcement_ingress; 404bff33f7eSVladimir Oltean 405058102a6STobias Waldekranz /* Drivers that benefit from having an ID associated with each 406058102a6STobias Waldekranz * offloaded LAG should set this to the maximum number of 407058102a6STobias Waldekranz * supported IDs. DSA will then maintain a mapping of _at 408058102a6STobias Waldekranz * least_ these many IDs, accessible to drivers via 409058102a6STobias Waldekranz * dsa_lag_id(). 410058102a6STobias Waldekranz */ 411058102a6STobias Waldekranz unsigned int num_lag_ids; 412058102a6STobias Waldekranz 413123abc06SVladimir Oltean /* Drivers that support bridge forwarding offload should set this to 414f5e165e7SVladimir Oltean * the maximum number of bridges spanning the same switch tree (or all 415f5e165e7SVladimir Oltean * trees, in the case of cross-tree bridging support) that can be 416f5e165e7SVladimir Oltean * offloaded. 417123abc06SVladimir Oltean */ 418123abc06SVladimir Oltean unsigned int num_fwd_offloading_bridges; 419123abc06SVladimir Oltean 420a0c02161SVivien Didelot size_t num_ports; 421c8f0b869SBen Hutchings }; 422c8f0b869SBen Hutchings 42368bb8ea8SVivien Didelot static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p) 424c38c5a66SVivien Didelot { 425b96ddf25SVivien Didelot struct dsa_switch_tree *dst = ds->dst; 426d607525bSVivien Didelot struct dsa_port *dp; 427b96ddf25SVivien Didelot 428b96ddf25SVivien Didelot list_for_each_entry(dp, &dst->ports, list) 429b96ddf25SVivien Didelot if (dp->ds == ds && dp->index == p) 430b96ddf25SVivien Didelot return dp; 431d607525bSVivien Didelot 432d607525bSVivien Didelot return NULL; 433c38c5a66SVivien Didelot } 434c38c5a66SVivien Didelot 435a8986681SVladimir Oltean static inline bool dsa_port_is_dsa(struct dsa_port *port) 436a8986681SVladimir Oltean { 437a8986681SVladimir Oltean return port->type == DSA_PORT_TYPE_DSA; 438a8986681SVladimir Oltean } 439a8986681SVladimir Oltean 440a8986681SVladimir Oltean static inline bool dsa_port_is_cpu(struct dsa_port *port) 441a8986681SVladimir Oltean { 442a8986681SVladimir Oltean return port->type == DSA_PORT_TYPE_CPU; 443a8986681SVladimir Oltean } 444a8986681SVladimir Oltean 445a8986681SVladimir Oltean static inline bool dsa_port_is_user(struct dsa_port *dp) 446a8986681SVladimir Oltean { 447a8986681SVladimir Oltean return dp->type == DSA_PORT_TYPE_USER; 448a8986681SVladimir Oltean } 449a8986681SVladimir Oltean 450a57d8c21SVladimir Oltean static inline bool dsa_port_is_unused(struct dsa_port *dp) 451a57d8c21SVladimir Oltean { 452a57d8c21SVladimir Oltean return dp->type == DSA_PORT_TYPE_UNUSED; 453a57d8c21SVladimir Oltean } 454a57d8c21SVladimir Oltean 455bff7b688SVivien Didelot static inline bool dsa_is_unused_port(struct dsa_switch *ds, int p) 456bff7b688SVivien Didelot { 457c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_UNUSED; 458bff7b688SVivien Didelot } 459bff7b688SVivien Didelot 460c8f0b869SBen Hutchings static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p) 461c8f0b869SBen Hutchings { 462c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_CPU; 463c8f0b869SBen Hutchings } 464c8f0b869SBen Hutchings 46560045cbfSAndrew Lunn static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p) 46660045cbfSAndrew Lunn { 467c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_DSA; 46860045cbfSAndrew Lunn } 46960045cbfSAndrew Lunn 4702b3e9891SVivien Didelot static inline bool dsa_is_user_port(struct dsa_switch *ds, int p) 4716cd456f3SVivien Didelot { 472c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_USER; 4736cd456f3SVivien Didelot } 4746cd456f3SVivien Didelot 47502bc6e54SVivien Didelot static inline u32 dsa_user_ports(struct dsa_switch *ds) 47602bc6e54SVivien Didelot { 477c38c5a66SVivien Didelot u32 mask = 0; 478c38c5a66SVivien Didelot int p; 47902bc6e54SVivien Didelot 480c38c5a66SVivien Didelot for (p = 0; p < ds->num_ports; p++) 481c38c5a66SVivien Didelot if (dsa_is_user_port(ds, p)) 482c38c5a66SVivien Didelot mask |= BIT(p); 483c38c5a66SVivien Didelot 484c38c5a66SVivien Didelot return mask; 485c8652c83SVivien Didelot } 486c8652c83SVivien Didelot 487c5f51765SVivien Didelot /* Return the local port used to reach an arbitrary switch device */ 488c5f51765SVivien Didelot static inline unsigned int dsa_routing_port(struct dsa_switch *ds, int device) 489c5f51765SVivien Didelot { 490c5f51765SVivien Didelot struct dsa_switch_tree *dst = ds->dst; 491c5f51765SVivien Didelot struct dsa_link *dl; 492c5f51765SVivien Didelot 493c5f51765SVivien Didelot list_for_each_entry(dl, &dst->rtable, list) 494c5f51765SVivien Didelot if (dl->dp->ds == ds && dl->link_dp->ds->index == device) 495c5f51765SVivien Didelot return dl->dp->index; 496c5f51765SVivien Didelot 497c5f51765SVivien Didelot return ds->num_ports; 498c5f51765SVivien Didelot } 499c5f51765SVivien Didelot 5003b8fac5dSVivien Didelot /* Return the local port used to reach an arbitrary switch port */ 5013b8fac5dSVivien Didelot static inline unsigned int dsa_towards_port(struct dsa_switch *ds, int device, 5023b8fac5dSVivien Didelot int port) 5033b8fac5dSVivien Didelot { 5043b8fac5dSVivien Didelot if (device == ds->index) 5053b8fac5dSVivien Didelot return port; 5063b8fac5dSVivien Didelot else 507c5f51765SVivien Didelot return dsa_routing_port(ds, device); 5083b8fac5dSVivien Didelot } 5093b8fac5dSVivien Didelot 5103b8fac5dSVivien Didelot /* Return the local port used to reach the dedicated CPU port */ 51107073c79SVivien Didelot static inline unsigned int dsa_upstream_port(struct dsa_switch *ds, int port) 512c8f0b869SBen Hutchings { 51307073c79SVivien Didelot const struct dsa_port *dp = dsa_to_port(ds, port); 51407073c79SVivien Didelot const struct dsa_port *cpu_dp = dp->cpu_dp; 51507073c79SVivien Didelot 51607073c79SVivien Didelot if (!cpu_dp) 51707073c79SVivien Didelot return port; 518c8f0b869SBen Hutchings 5193b8fac5dSVivien Didelot return dsa_towards_port(ds, cpu_dp->ds->index, cpu_dp->index); 520c8f0b869SBen Hutchings } 521c8f0b869SBen Hutchings 52263609c8fSVladimir Oltean /* Return true if this is the local port used to reach the CPU port */ 52363609c8fSVladimir Oltean static inline bool dsa_is_upstream_port(struct dsa_switch *ds, int port) 52463609c8fSVladimir Oltean { 52563609c8fSVladimir Oltean if (dsa_is_unused_port(ds, port)) 52663609c8fSVladimir Oltean return false; 52763609c8fSVladimir Oltean 52863609c8fSVladimir Oltean return port == dsa_upstream_port(ds, port); 52963609c8fSVladimir Oltean } 53063609c8fSVladimir Oltean 53163609c8fSVladimir Oltean /* Return true if @upstream_ds is an upstream switch of @downstream_ds, meaning 53263609c8fSVladimir Oltean * that the routing port from @downstream_ds to @upstream_ds is also the port 53363609c8fSVladimir Oltean * which @downstream_ds uses to reach its dedicated CPU. 53463609c8fSVladimir Oltean */ 53563609c8fSVladimir Oltean static inline bool dsa_switch_is_upstream_of(struct dsa_switch *upstream_ds, 53663609c8fSVladimir Oltean struct dsa_switch *downstream_ds) 53763609c8fSVladimir Oltean { 53863609c8fSVladimir Oltean int routing_port; 53963609c8fSVladimir Oltean 54063609c8fSVladimir Oltean if (upstream_ds == downstream_ds) 54163609c8fSVladimir Oltean return true; 54263609c8fSVladimir Oltean 54363609c8fSVladimir Oltean routing_port = dsa_routing_port(downstream_ds, upstream_ds->index); 54463609c8fSVladimir Oltean 54563609c8fSVladimir Oltean return dsa_is_upstream_port(downstream_ds, routing_port); 54663609c8fSVladimir Oltean } 54763609c8fSVladimir Oltean 548cf2d45f5SVladimir Oltean static inline bool dsa_port_is_vlan_filtering(const struct dsa_port *dp) 549cf2d45f5SVladimir Oltean { 550cf2d45f5SVladimir Oltean const struct dsa_switch *ds = dp->ds; 551cf2d45f5SVladimir Oltean 552cf2d45f5SVladimir Oltean if (ds->vlan_filtering_is_global) 553cf2d45f5SVladimir Oltean return ds->vlan_filtering; 554cf2d45f5SVladimir Oltean else 555cf2d45f5SVladimir Oltean return dp->vlan_filtering; 556cf2d45f5SVladimir Oltean } 557cf2d45f5SVladimir Oltean 558cc76ce9eSTobias Waldekranz static inline 559cc76ce9eSTobias Waldekranz struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp) 560cc76ce9eSTobias Waldekranz { 561cc76ce9eSTobias Waldekranz if (!dp->bridge_dev) 562cc76ce9eSTobias Waldekranz return NULL; 563cc76ce9eSTobias Waldekranz 564cc76ce9eSTobias Waldekranz if (dp->lag_dev) 565cc76ce9eSTobias Waldekranz return dp->lag_dev; 566cc76ce9eSTobias Waldekranz else if (dp->hsr_dev) 567cc76ce9eSTobias Waldekranz return dp->hsr_dev; 568cc76ce9eSTobias Waldekranz 569cc76ce9eSTobias Waldekranz return dp->slave; 570cc76ce9eSTobias Waldekranz } 571cc76ce9eSTobias Waldekranz 5722bedde1aSArkadi Sharshevsky typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid, 5732bedde1aSArkadi Sharshevsky bool is_static, void *data); 5749d490b4eSVivien Didelot struct dsa_switch_ops { 57553da0ebaSVladimir Oltean /* 57653da0ebaSVladimir Oltean * Tagging protocol helpers called for the CPU ports and DSA links. 57753da0ebaSVladimir Oltean * @get_tag_protocol retrieves the initial tagging protocol and is 57853da0ebaSVladimir Oltean * mandatory. Switches which can operate using multiple tagging 57953da0ebaSVladimir Oltean * protocols should implement @change_tag_protocol and report in 58053da0ebaSVladimir Oltean * @get_tag_protocol the tagger in current use. 58153da0ebaSVladimir Oltean */ 5825ed4e3ebSFlorian Fainelli enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds, 5834d776482SFlorian Fainelli int port, 5844d776482SFlorian Fainelli enum dsa_tag_protocol mprot); 58553da0ebaSVladimir Oltean int (*change_tag_protocol)(struct dsa_switch *ds, int port, 58653da0ebaSVladimir Oltean enum dsa_tag_protocol proto); 5877b314362SAndrew Lunn 588*fd292c18SVladimir Oltean /* Optional switch-wide initialization and destruction methods */ 589c8f0b869SBen Hutchings int (*setup)(struct dsa_switch *ds); 5905e3f847aSVladimir Oltean void (*teardown)(struct dsa_switch *ds); 591*fd292c18SVladimir Oltean 592*fd292c18SVladimir Oltean /* Per-port initialization and destruction methods. Mandatory if the 593*fd292c18SVladimir Oltean * driver registers devlink port regions, optional otherwise. 594*fd292c18SVladimir Oltean */ 595*fd292c18SVladimir Oltean int (*port_setup)(struct dsa_switch *ds, int port); 596*fd292c18SVladimir Oltean void (*port_teardown)(struct dsa_switch *ds, int port); 597*fd292c18SVladimir Oltean 5986819563eSFlorian Fainelli u32 (*get_phy_flags)(struct dsa_switch *ds, int port); 599c8f0b869SBen Hutchings 600c8f0b869SBen Hutchings /* 601c8f0b869SBen Hutchings * Access to the switch's PHY registers. 602c8f0b869SBen Hutchings */ 603c8f0b869SBen Hutchings int (*phy_read)(struct dsa_switch *ds, int port, int regnum); 604c8f0b869SBen Hutchings int (*phy_write)(struct dsa_switch *ds, int port, 605c8f0b869SBen Hutchings int regnum, u16 val); 606c8f0b869SBen Hutchings 607c8f0b869SBen Hutchings /* 608ec9436baSFlorian Fainelli * Link state adjustment (called from libphy) 609ec9436baSFlorian Fainelli */ 610ec9436baSFlorian Fainelli void (*adjust_link)(struct dsa_switch *ds, int port, 611ec9436baSFlorian Fainelli struct phy_device *phydev); 612ce31b31cSFlorian Fainelli void (*fixed_link_update)(struct dsa_switch *ds, int port, 613ce31b31cSFlorian Fainelli struct fixed_phy_status *st); 614ec9436baSFlorian Fainelli 615ec9436baSFlorian Fainelli /* 61611d8f3ddSFlorian Fainelli * PHYLINK integration 61711d8f3ddSFlorian Fainelli */ 61811d8f3ddSFlorian Fainelli void (*phylink_validate)(struct dsa_switch *ds, int port, 61911d8f3ddSFlorian Fainelli unsigned long *supported, 62011d8f3ddSFlorian Fainelli struct phylink_link_state *state); 62111d8f3ddSFlorian Fainelli int (*phylink_mac_link_state)(struct dsa_switch *ds, int port, 62211d8f3ddSFlorian Fainelli struct phylink_link_state *state); 62311d8f3ddSFlorian Fainelli void (*phylink_mac_config)(struct dsa_switch *ds, int port, 62411d8f3ddSFlorian Fainelli unsigned int mode, 62511d8f3ddSFlorian Fainelli const struct phylink_link_state *state); 62611d8f3ddSFlorian Fainelli void (*phylink_mac_an_restart)(struct dsa_switch *ds, int port); 62711d8f3ddSFlorian Fainelli void (*phylink_mac_link_down)(struct dsa_switch *ds, int port, 62811d8f3ddSFlorian Fainelli unsigned int mode, 62911d8f3ddSFlorian Fainelli phy_interface_t interface); 63011d8f3ddSFlorian Fainelli void (*phylink_mac_link_up)(struct dsa_switch *ds, int port, 63111d8f3ddSFlorian Fainelli unsigned int mode, 63211d8f3ddSFlorian Fainelli phy_interface_t interface, 6335b502a7bSRussell King struct phy_device *phydev, 6345b502a7bSRussell King int speed, int duplex, 6355b502a7bSRussell King bool tx_pause, bool rx_pause); 63611d8f3ddSFlorian Fainelli void (*phylink_fixed_state)(struct dsa_switch *ds, int port, 63711d8f3ddSFlorian Fainelli struct phylink_link_state *state); 63811d8f3ddSFlorian Fainelli /* 639c2ec5f2eSOleksij Rempel * Port statistics counters. 640c8f0b869SBen Hutchings */ 64189f09048SFlorian Fainelli void (*get_strings)(struct dsa_switch *ds, int port, 64289f09048SFlorian Fainelli u32 stringset, uint8_t *data); 643c8f0b869SBen Hutchings void (*get_ethtool_stats)(struct dsa_switch *ds, 644c8f0b869SBen Hutchings int port, uint64_t *data); 64589f09048SFlorian Fainelli int (*get_sset_count)(struct dsa_switch *ds, int port, int sset); 646cf963573SFlorian Fainelli void (*get_ethtool_phy_stats)(struct dsa_switch *ds, 647cf963573SFlorian Fainelli int port, uint64_t *data); 648c2ec5f2eSOleksij Rempel void (*get_stats64)(struct dsa_switch *ds, int port, 649c2ec5f2eSOleksij Rempel struct rtnl_link_stats64 *s); 650a71acad9SOleksij Rempel void (*self_test)(struct dsa_switch *ds, int port, 651a71acad9SOleksij Rempel struct ethtool_test *etest, u64 *data); 65224462549SFlorian Fainelli 65324462549SFlorian Fainelli /* 65419e57c4eSFlorian Fainelli * ethtool Wake-on-LAN 65519e57c4eSFlorian Fainelli */ 65619e57c4eSFlorian Fainelli void (*get_wol)(struct dsa_switch *ds, int port, 65719e57c4eSFlorian Fainelli struct ethtool_wolinfo *w); 65819e57c4eSFlorian Fainelli int (*set_wol)(struct dsa_switch *ds, int port, 65919e57c4eSFlorian Fainelli struct ethtool_wolinfo *w); 66019e57c4eSFlorian Fainelli 66119e57c4eSFlorian Fainelli /* 6620336369dSBrandon Streiff * ethtool timestamp info 6630336369dSBrandon Streiff */ 6640336369dSBrandon Streiff int (*get_ts_info)(struct dsa_switch *ds, int port, 6650336369dSBrandon Streiff struct ethtool_ts_info *ts); 6660336369dSBrandon Streiff 6670336369dSBrandon Streiff /* 66824462549SFlorian Fainelli * Suspend and resume 66924462549SFlorian Fainelli */ 67024462549SFlorian Fainelli int (*suspend)(struct dsa_switch *ds); 67124462549SFlorian Fainelli int (*resume)(struct dsa_switch *ds); 672b2f2af21SFlorian Fainelli 673b2f2af21SFlorian Fainelli /* 674b2f2af21SFlorian Fainelli * Port enable/disable 675b2f2af21SFlorian Fainelli */ 676b2f2af21SFlorian Fainelli int (*port_enable)(struct dsa_switch *ds, int port, 677b2f2af21SFlorian Fainelli struct phy_device *phy); 67875104db0SAndrew Lunn void (*port_disable)(struct dsa_switch *ds, int port); 6797905288fSFlorian Fainelli 6807905288fSFlorian Fainelli /* 68108f50061SVivien Didelot * Port's MAC EEE settings 6827905288fSFlorian Fainelli */ 68308f50061SVivien Didelot int (*set_mac_eee)(struct dsa_switch *ds, int port, 6847905288fSFlorian Fainelli struct ethtool_eee *e); 68508f50061SVivien Didelot int (*get_mac_eee)(struct dsa_switch *ds, int port, 6867905288fSFlorian Fainelli struct ethtool_eee *e); 68751579c3fSGuenter Roeck 6886793abb4SGuenter Roeck /* EEPROM access */ 6896793abb4SGuenter Roeck int (*get_eeprom_len)(struct dsa_switch *ds); 6906793abb4SGuenter Roeck int (*get_eeprom)(struct dsa_switch *ds, 6916793abb4SGuenter Roeck struct ethtool_eeprom *eeprom, u8 *data); 6926793abb4SGuenter Roeck int (*set_eeprom)(struct dsa_switch *ds, 6936793abb4SGuenter Roeck struct ethtool_eeprom *eeprom, u8 *data); 6943d762a0fSGuenter Roeck 6953d762a0fSGuenter Roeck /* 6963d762a0fSGuenter Roeck * Register access. 6973d762a0fSGuenter Roeck */ 6983d762a0fSGuenter Roeck int (*get_regs_len)(struct dsa_switch *ds, int port); 6993d762a0fSGuenter Roeck void (*get_regs)(struct dsa_switch *ds, int port, 7003d762a0fSGuenter Roeck struct ethtool_regs *regs, void *p); 701b73adef6SFlorian Fainelli 702b73adef6SFlorian Fainelli /* 703e358bef7SVladimir Oltean * Upper device tracking. 704e358bef7SVladimir Oltean */ 705e358bef7SVladimir Oltean int (*port_prechangeupper)(struct dsa_switch *ds, int port, 706e358bef7SVladimir Oltean struct netdev_notifier_changeupper_info *info); 707e358bef7SVladimir Oltean 708e358bef7SVladimir Oltean /* 709b73adef6SFlorian Fainelli * Bridge integration 710b73adef6SFlorian Fainelli */ 71134a79f63SVivien Didelot int (*set_ageing_time)(struct dsa_switch *ds, unsigned int msecs); 71271327a4eSVivien Didelot int (*port_bridge_join)(struct dsa_switch *ds, int port, 713a6692754SVivien Didelot struct net_device *bridge); 714f123f2fbSVivien Didelot void (*port_bridge_leave)(struct dsa_switch *ds, int port, 715f123f2fbSVivien Didelot struct net_device *bridge); 716123abc06SVladimir Oltean /* Called right after .port_bridge_join() */ 717123abc06SVladimir Oltean int (*port_bridge_tx_fwd_offload)(struct dsa_switch *ds, int port, 718123abc06SVladimir Oltean struct net_device *bridge, 719123abc06SVladimir Oltean int bridge_num); 720123abc06SVladimir Oltean /* Called right before .port_bridge_leave() */ 721123abc06SVladimir Oltean void (*port_bridge_tx_fwd_unoffload)(struct dsa_switch *ds, int port, 722123abc06SVladimir Oltean struct net_device *bridge, 723123abc06SVladimir Oltean int bridge_num); 72443c44a9fSVivien Didelot void (*port_stp_state_set)(struct dsa_switch *ds, int port, 725b73adef6SFlorian Fainelli u8 state); 726732f794cSVivien Didelot void (*port_fast_age)(struct dsa_switch *ds, int port); 727a8b659e7SVladimir Oltean int (*port_pre_bridge_flags)(struct dsa_switch *ds, int port, 728a8b659e7SVladimir Oltean struct switchdev_brport_flags flags, 729a8b659e7SVladimir Oltean struct netlink_ext_ack *extack); 730a8b659e7SVladimir Oltean int (*port_bridge_flags)(struct dsa_switch *ds, int port, 731a8b659e7SVladimir Oltean struct switchdev_brport_flags flags, 732a8b659e7SVladimir Oltean struct netlink_ext_ack *extack); 7332a778e1bSVivien Didelot 7342a778e1bSVivien Didelot /* 73511149536SVivien Didelot * VLAN support 73611149536SVivien Didelot */ 737fb2dabadSVivien Didelot int (*port_vlan_filtering)(struct dsa_switch *ds, int port, 73889153ed6SVladimir Oltean bool vlan_filtering, 73989153ed6SVladimir Oltean struct netlink_ext_ack *extack); 7401958d581SVladimir Oltean int (*port_vlan_add)(struct dsa_switch *ds, int port, 74131046a5fSVladimir Oltean const struct switchdev_obj_port_vlan *vlan, 74231046a5fSVladimir Oltean struct netlink_ext_ack *extack); 74376e398a6SVivien Didelot int (*port_vlan_del)(struct dsa_switch *ds, int port, 74476e398a6SVivien Didelot const struct switchdev_obj_port_vlan *vlan); 74511149536SVivien Didelot /* 7462a778e1bSVivien Didelot * Forwarding database 7472a778e1bSVivien Didelot */ 7481b6dd556SArkadi Sharshevsky int (*port_fdb_add)(struct dsa_switch *ds, int port, 7496c2c1dcbSArkadi Sharshevsky const unsigned char *addr, u16 vid); 7502a778e1bSVivien Didelot int (*port_fdb_del)(struct dsa_switch *ds, int port, 7516c2c1dcbSArkadi Sharshevsky const unsigned char *addr, u16 vid); 752ea70ba98SVivien Didelot int (*port_fdb_dump)(struct dsa_switch *ds, int port, 7532bedde1aSArkadi Sharshevsky dsa_fdb_dump_cb_t *cb, void *data); 7548df30255SVivien Didelot 7558df30255SVivien Didelot /* 7568df30255SVivien Didelot * Multicast database 7578df30255SVivien Didelot */ 758a52b2da7SVladimir Oltean int (*port_mdb_add)(struct dsa_switch *ds, int port, 7593709aadcSVivien Didelot const struct switchdev_obj_port_mdb *mdb); 7608df30255SVivien Didelot int (*port_mdb_del)(struct dsa_switch *ds, int port, 7618df30255SVivien Didelot const struct switchdev_obj_port_mdb *mdb); 762bf9f2648SFlorian Fainelli /* 763bf9f2648SFlorian Fainelli * RXNFC 764bf9f2648SFlorian Fainelli */ 765bf9f2648SFlorian Fainelli int (*get_rxnfc)(struct dsa_switch *ds, int port, 766bf9f2648SFlorian Fainelli struct ethtool_rxnfc *nfc, u32 *rule_locs); 767bf9f2648SFlorian Fainelli int (*set_rxnfc)(struct dsa_switch *ds, int port, 768bf9f2648SFlorian Fainelli struct ethtool_rxnfc *nfc); 769f50f2127SFlorian Fainelli 770f50f2127SFlorian Fainelli /* 771f50f2127SFlorian Fainelli * TC integration 772f50f2127SFlorian Fainelli */ 773ed11bb1fSVladimir Oltean int (*cls_flower_add)(struct dsa_switch *ds, int port, 774ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, bool ingress); 775ed11bb1fSVladimir Oltean int (*cls_flower_del)(struct dsa_switch *ds, int port, 776ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, bool ingress); 777ed11bb1fSVladimir Oltean int (*cls_flower_stats)(struct dsa_switch *ds, int port, 778ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, bool ingress); 779f50f2127SFlorian Fainelli int (*port_mirror_add)(struct dsa_switch *ds, int port, 780f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror, 781f50f2127SFlorian Fainelli bool ingress); 782f50f2127SFlorian Fainelli void (*port_mirror_del)(struct dsa_switch *ds, int port, 783f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror); 78434297176SVladimir Oltean int (*port_policer_add)(struct dsa_switch *ds, int port, 78534297176SVladimir Oltean struct dsa_mall_policer_tc_entry *policer); 78634297176SVladimir Oltean void (*port_policer_del)(struct dsa_switch *ds, int port); 78747d23af2SVladimir Oltean int (*port_setup_tc)(struct dsa_switch *ds, int port, 78847d23af2SVladimir Oltean enum tc_setup_type type, void *type_data); 78940ef2c93SVivien Didelot 79040ef2c93SVivien Didelot /* 79140ef2c93SVivien Didelot * Cross-chip operations 79240ef2c93SVivien Didelot */ 793f66a6a69SVladimir Oltean int (*crosschip_bridge_join)(struct dsa_switch *ds, int tree_index, 794f66a6a69SVladimir Oltean int sw_index, int port, 795f66a6a69SVladimir Oltean struct net_device *br); 796f66a6a69SVladimir Oltean void (*crosschip_bridge_leave)(struct dsa_switch *ds, int tree_index, 797f66a6a69SVladimir Oltean int sw_index, int port, 798f66a6a69SVladimir Oltean struct net_device *br); 799058102a6STobias Waldekranz int (*crosschip_lag_change)(struct dsa_switch *ds, int sw_index, 800058102a6STobias Waldekranz int port); 801058102a6STobias Waldekranz int (*crosschip_lag_join)(struct dsa_switch *ds, int sw_index, 802058102a6STobias Waldekranz int port, struct net_device *lag, 803058102a6STobias Waldekranz struct netdev_lag_upper_info *info); 804058102a6STobias Waldekranz int (*crosschip_lag_leave)(struct dsa_switch *ds, int sw_index, 805058102a6STobias Waldekranz int port, struct net_device *lag); 8060336369dSBrandon Streiff 8070336369dSBrandon Streiff /* 8080336369dSBrandon Streiff * PTP functionality 8090336369dSBrandon Streiff */ 8100336369dSBrandon Streiff int (*port_hwtstamp_get)(struct dsa_switch *ds, int port, 8110336369dSBrandon Streiff struct ifreq *ifr); 8120336369dSBrandon Streiff int (*port_hwtstamp_set)(struct dsa_switch *ds, int port, 8130336369dSBrandon Streiff struct ifreq *ifr); 8145c5416f5SYangbo Lu void (*port_txtstamp)(struct dsa_switch *ds, int port, 8155c5416f5SYangbo Lu struct sk_buff *skb); 81690af1059SBrandon Streiff bool (*port_rxtstamp)(struct dsa_switch *ds, int port, 81790af1059SBrandon Streiff struct sk_buff *skb, unsigned int type); 81897a69a0dSVladimir Oltean 8190f06b855SAndrew Lunn /* Devlink parameters, etc */ 8206b297524SAndrew Lunn int (*devlink_param_get)(struct dsa_switch *ds, u32 id, 8216b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx); 8226b297524SAndrew Lunn int (*devlink_param_set)(struct dsa_switch *ds, u32 id, 8236b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx); 8240f06b855SAndrew Lunn int (*devlink_info_get)(struct dsa_switch *ds, 8250f06b855SAndrew Lunn struct devlink_info_req *req, 8260f06b855SAndrew Lunn struct netlink_ext_ack *extack); 8272a6ef763SVladimir Oltean int (*devlink_sb_pool_get)(struct dsa_switch *ds, 8282a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index, 8292a6ef763SVladimir Oltean struct devlink_sb_pool_info *pool_info); 8302a6ef763SVladimir Oltean int (*devlink_sb_pool_set)(struct dsa_switch *ds, unsigned int sb_index, 8312a6ef763SVladimir Oltean u16 pool_index, u32 size, 8322a6ef763SVladimir Oltean enum devlink_sb_threshold_type threshold_type, 8332a6ef763SVladimir Oltean struct netlink_ext_ack *extack); 8342a6ef763SVladimir Oltean int (*devlink_sb_port_pool_get)(struct dsa_switch *ds, int port, 8352a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index, 8362a6ef763SVladimir Oltean u32 *p_threshold); 8372a6ef763SVladimir Oltean int (*devlink_sb_port_pool_set)(struct dsa_switch *ds, int port, 8382a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index, 8392a6ef763SVladimir Oltean u32 threshold, 8402a6ef763SVladimir Oltean struct netlink_ext_ack *extack); 8412a6ef763SVladimir Oltean int (*devlink_sb_tc_pool_bind_get)(struct dsa_switch *ds, int port, 8422a6ef763SVladimir Oltean unsigned int sb_index, u16 tc_index, 8432a6ef763SVladimir Oltean enum devlink_sb_pool_type pool_type, 8442a6ef763SVladimir Oltean u16 *p_pool_index, u32 *p_threshold); 8452a6ef763SVladimir Oltean int (*devlink_sb_tc_pool_bind_set)(struct dsa_switch *ds, int port, 8462a6ef763SVladimir Oltean unsigned int sb_index, u16 tc_index, 8472a6ef763SVladimir Oltean enum devlink_sb_pool_type pool_type, 8482a6ef763SVladimir Oltean u16 pool_index, u32 threshold, 8492a6ef763SVladimir Oltean struct netlink_ext_ack *extack); 8502a6ef763SVladimir Oltean int (*devlink_sb_occ_snapshot)(struct dsa_switch *ds, 8512a6ef763SVladimir Oltean unsigned int sb_index); 8522a6ef763SVladimir Oltean int (*devlink_sb_occ_max_clear)(struct dsa_switch *ds, 8532a6ef763SVladimir Oltean unsigned int sb_index); 8542a6ef763SVladimir Oltean int (*devlink_sb_occ_port_pool_get)(struct dsa_switch *ds, int port, 8552a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index, 8562a6ef763SVladimir Oltean u32 *p_cur, u32 *p_max); 8572a6ef763SVladimir Oltean int (*devlink_sb_occ_tc_port_bind_get)(struct dsa_switch *ds, int port, 8582a6ef763SVladimir Oltean unsigned int sb_index, u16 tc_index, 8592a6ef763SVladimir Oltean enum devlink_sb_pool_type pool_type, 8602a6ef763SVladimir Oltean u32 *p_cur, u32 *p_max); 861bfcb8132SVladimir Oltean 862bfcb8132SVladimir Oltean /* 863bfcb8132SVladimir Oltean * MTU change functionality. Switches can also adjust their MRU through 864bfcb8132SVladimir Oltean * this method. By MTU, one understands the SDU (L2 payload) length. 865bfcb8132SVladimir Oltean * If the switch needs to account for the DSA tag on the CPU port, this 866ab88d64aSRandy Dunlap * method needs to do so privately. 867bfcb8132SVladimir Oltean */ 868bfcb8132SVladimir Oltean int (*port_change_mtu)(struct dsa_switch *ds, int port, 869bfcb8132SVladimir Oltean int new_mtu); 870bfcb8132SVladimir Oltean int (*port_max_mtu)(struct dsa_switch *ds, int port); 871058102a6STobias Waldekranz 872058102a6STobias Waldekranz /* 873058102a6STobias Waldekranz * LAG integration 874058102a6STobias Waldekranz */ 875058102a6STobias Waldekranz int (*port_lag_change)(struct dsa_switch *ds, int port); 876058102a6STobias Waldekranz int (*port_lag_join)(struct dsa_switch *ds, int port, 877058102a6STobias Waldekranz struct net_device *lag, 878058102a6STobias Waldekranz struct netdev_lag_upper_info *info); 879058102a6STobias Waldekranz int (*port_lag_leave)(struct dsa_switch *ds, int port, 880058102a6STobias Waldekranz struct net_device *lag); 88118596f50SGeorge McCollister 88218596f50SGeorge McCollister /* 88318596f50SGeorge McCollister * HSR integration 88418596f50SGeorge McCollister */ 88518596f50SGeorge McCollister int (*port_hsr_join)(struct dsa_switch *ds, int port, 88618596f50SGeorge McCollister struct net_device *hsr); 88718596f50SGeorge McCollister int (*port_hsr_leave)(struct dsa_switch *ds, int port, 88818596f50SGeorge McCollister struct net_device *hsr); 889c595c433SHoratiu Vultur 890c595c433SHoratiu Vultur /* 891c595c433SHoratiu Vultur * MRP integration 892c595c433SHoratiu Vultur */ 893c595c433SHoratiu Vultur int (*port_mrp_add)(struct dsa_switch *ds, int port, 894c595c433SHoratiu Vultur const struct switchdev_obj_mrp *mrp); 895c595c433SHoratiu Vultur int (*port_mrp_del)(struct dsa_switch *ds, int port, 896c595c433SHoratiu Vultur const struct switchdev_obj_mrp *mrp); 897c595c433SHoratiu Vultur int (*port_mrp_add_ring_role)(struct dsa_switch *ds, int port, 898c595c433SHoratiu Vultur const struct switchdev_obj_ring_role_mrp *mrp); 899c595c433SHoratiu Vultur int (*port_mrp_del_ring_role)(struct dsa_switch *ds, int port, 900c595c433SHoratiu Vultur const struct switchdev_obj_ring_role_mrp *mrp); 9015da11eb4SVladimir Oltean 9025da11eb4SVladimir Oltean /* 9035da11eb4SVladimir Oltean * tag_8021q operations 9045da11eb4SVladimir Oltean */ 9055da11eb4SVladimir Oltean int (*tag_8021q_vlan_add)(struct dsa_switch *ds, int port, u16 vid, 9065da11eb4SVladimir Oltean u16 flags); 9075da11eb4SVladimir Oltean int (*tag_8021q_vlan_del)(struct dsa_switch *ds, int port, u16 vid); 9086b297524SAndrew Lunn }; 9096b297524SAndrew Lunn 9106b297524SAndrew Lunn #define DSA_DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes) \ 9116b297524SAndrew Lunn DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, \ 9126b297524SAndrew Lunn dsa_devlink_param_get, dsa_devlink_param_set, NULL) 9136b297524SAndrew Lunn 9146b297524SAndrew Lunn int dsa_devlink_param_get(struct devlink *dl, u32 id, 9156b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx); 9166b297524SAndrew Lunn int dsa_devlink_param_set(struct devlink *dl, u32 id, 9176b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx); 9186b297524SAndrew Lunn int dsa_devlink_params_register(struct dsa_switch *ds, 9196b297524SAndrew Lunn const struct devlink_param *params, 9206b297524SAndrew Lunn size_t params_count); 9216b297524SAndrew Lunn void dsa_devlink_params_unregister(struct dsa_switch *ds, 9226b297524SAndrew Lunn const struct devlink_param *params, 9236b297524SAndrew Lunn size_t params_count); 9245cd73fbdSAndrew Lunn int dsa_devlink_resource_register(struct dsa_switch *ds, 9255cd73fbdSAndrew Lunn const char *resource_name, 9265cd73fbdSAndrew Lunn u64 resource_size, 9275cd73fbdSAndrew Lunn u64 resource_id, 9285cd73fbdSAndrew Lunn u64 parent_resource_id, 9295cd73fbdSAndrew Lunn const struct devlink_resource_size_params *size_params); 9305cd73fbdSAndrew Lunn 9315cd73fbdSAndrew Lunn void dsa_devlink_resources_unregister(struct dsa_switch *ds); 9325cd73fbdSAndrew Lunn 9335cd73fbdSAndrew Lunn void dsa_devlink_resource_occ_get_register(struct dsa_switch *ds, 9345cd73fbdSAndrew Lunn u64 resource_id, 9355cd73fbdSAndrew Lunn devlink_resource_occ_get_t *occ_get, 9365cd73fbdSAndrew Lunn void *occ_get_priv); 9375cd73fbdSAndrew Lunn void dsa_devlink_resource_occ_get_unregister(struct dsa_switch *ds, 9385cd73fbdSAndrew Lunn u64 resource_id); 93997c82c23SAndrew Lunn struct devlink_region * 94097c82c23SAndrew Lunn dsa_devlink_region_create(struct dsa_switch *ds, 94197c82c23SAndrew Lunn const struct devlink_region_ops *ops, 94297c82c23SAndrew Lunn u32 region_max_snapshots, u64 region_size); 94308156ba4SAndrew Lunn struct devlink_region * 94408156ba4SAndrew Lunn dsa_devlink_port_region_create(struct dsa_switch *ds, 94508156ba4SAndrew Lunn int port, 94608156ba4SAndrew Lunn const struct devlink_port_region_ops *ops, 94708156ba4SAndrew Lunn u32 region_max_snapshots, u64 region_size); 94897c82c23SAndrew Lunn void dsa_devlink_region_destroy(struct devlink_region *region); 94997c82c23SAndrew Lunn 950e1eea811SVladimir Oltean struct dsa_port *dsa_port_from_netdev(struct net_device *netdev); 9515cd73fbdSAndrew Lunn 9526b297524SAndrew Lunn struct dsa_devlink_priv { 9536b297524SAndrew Lunn struct dsa_switch *ds; 954c8f0b869SBen Hutchings }; 955c8f0b869SBen Hutchings 956ccc3e6b0SAndrew Lunn static inline struct dsa_switch *dsa_devlink_to_ds(struct devlink *dl) 957ccc3e6b0SAndrew Lunn { 958ccc3e6b0SAndrew Lunn struct dsa_devlink_priv *dl_priv = devlink_priv(dl); 959ccc3e6b0SAndrew Lunn 960ccc3e6b0SAndrew Lunn return dl_priv->ds; 961ccc3e6b0SAndrew Lunn } 962ccc3e6b0SAndrew Lunn 9637d1e2a10SAndrew Lunn static inline 9647d1e2a10SAndrew Lunn struct dsa_switch *dsa_devlink_port_to_ds(struct devlink_port *port) 9657d1e2a10SAndrew Lunn { 9667d1e2a10SAndrew Lunn struct devlink *dl = port->devlink; 9677d1e2a10SAndrew Lunn struct dsa_devlink_priv *dl_priv = devlink_priv(dl); 9687d1e2a10SAndrew Lunn 9697d1e2a10SAndrew Lunn return dl_priv->ds; 9707d1e2a10SAndrew Lunn } 9717d1e2a10SAndrew Lunn 9727d1e2a10SAndrew Lunn static inline int dsa_devlink_port_to_port(struct devlink_port *port) 9737d1e2a10SAndrew Lunn { 9747d1e2a10SAndrew Lunn return port->index; 9757d1e2a10SAndrew Lunn } 9767d1e2a10SAndrew Lunn 977ab3d408dSFlorian Fainelli struct dsa_switch_driver { 978ab3d408dSFlorian Fainelli struct list_head list; 979a82f67afSFlorian Fainelli const struct dsa_switch_ops *ops; 980ab3d408dSFlorian Fainelli }; 981ab3d408dSFlorian Fainelli 98214b89f36SFlorian Fainelli struct net_device *dsa_dev_to_net_device(struct device *dev); 983c8f0b869SBen Hutchings 98473a7ece8SVivien Didelot /* Keep inline for faster access in hot path */ 9859eb8eff0SVladimir Oltean static inline bool netdev_uses_dsa(const struct net_device *dev) 986c6e970a0SAndrew Lunn { 987c6e970a0SAndrew Lunn #if IS_ENABLED(CONFIG_NET_DSA) 988717ffbfbSVivien Didelot return dev->dsa_ptr && dev->dsa_ptr->rcv; 989c6e970a0SAndrew Lunn #endif 990c6e970a0SAndrew Lunn return false; 991c6e970a0SAndrew Lunn } 992c6e970a0SAndrew Lunn 9939790cf20SVladimir Oltean /* All DSA tags that push the EtherType to the right (basically all except tail 9949790cf20SVladimir Oltean * tags, which don't break dissection) can be treated the same from the 9959790cf20SVladimir Oltean * perspective of the flow dissector. 9969790cf20SVladimir Oltean * 9979790cf20SVladimir Oltean * We need to return: 9989790cf20SVladimir Oltean * - offset: the (B - A) difference between: 9999790cf20SVladimir Oltean * A. the position of the real EtherType and 10009790cf20SVladimir Oltean * B. the current skb->data (aka ETH_HLEN bytes into the frame, aka 2 bytes 10019790cf20SVladimir Oltean * after the normal EtherType was supposed to be) 10029790cf20SVladimir Oltean * The offset in bytes is exactly equal to the tagger overhead (and half of 10039790cf20SVladimir Oltean * that, in __be16 shorts). 10049790cf20SVladimir Oltean * 10059790cf20SVladimir Oltean * - proto: the value of the real EtherType. 10069790cf20SVladimir Oltean */ 10079790cf20SVladimir Oltean static inline void dsa_tag_generic_flow_dissect(const struct sk_buff *skb, 10089790cf20SVladimir Oltean __be16 *proto, int *offset) 10099790cf20SVladimir Oltean { 10109790cf20SVladimir Oltean #if IS_ENABLED(CONFIG_NET_DSA) 10119790cf20SVladimir Oltean const struct dsa_device_ops *ops = skb->dev->dsa_ptr->tag_ops; 10124e500251SVladimir Oltean int tag_len = ops->needed_headroom; 10139790cf20SVladimir Oltean 10149790cf20SVladimir Oltean *offset = tag_len; 10159790cf20SVladimir Oltean *proto = ((__be16 *)skb->data)[(tag_len / 2) - 1]; 10169790cf20SVladimir Oltean #endif 10179790cf20SVladimir Oltean } 10189790cf20SVladimir Oltean 10194cfab356SFlorian Fainelli #if IS_ENABLED(CONFIG_NET_DSA) 10204cfab356SFlorian Fainelli static inline int __dsa_netdevice_ops_check(struct net_device *dev) 10214cfab356SFlorian Fainelli { 10224cfab356SFlorian Fainelli int err = -EOPNOTSUPP; 10234cfab356SFlorian Fainelli 10244cfab356SFlorian Fainelli if (!dev->dsa_ptr) 10254cfab356SFlorian Fainelli return err; 10264cfab356SFlorian Fainelli 10274cfab356SFlorian Fainelli if (!dev->dsa_ptr->netdev_ops) 10284cfab356SFlorian Fainelli return err; 10294cfab356SFlorian Fainelli 10304cfab356SFlorian Fainelli return 0; 10314cfab356SFlorian Fainelli } 10324cfab356SFlorian Fainelli 1033a7605370SArnd Bergmann static inline int dsa_ndo_eth_ioctl(struct net_device *dev, struct ifreq *ifr, 10344cfab356SFlorian Fainelli int cmd) 10354cfab356SFlorian Fainelli { 10364cfab356SFlorian Fainelli const struct dsa_netdevice_ops *ops; 10374cfab356SFlorian Fainelli int err; 10384cfab356SFlorian Fainelli 10394cfab356SFlorian Fainelli err = __dsa_netdevice_ops_check(dev); 10404cfab356SFlorian Fainelli if (err) 10414cfab356SFlorian Fainelli return err; 10424cfab356SFlorian Fainelli 10434cfab356SFlorian Fainelli ops = dev->dsa_ptr->netdev_ops; 10444cfab356SFlorian Fainelli 1045a7605370SArnd Bergmann return ops->ndo_eth_ioctl(dev, ifr, cmd); 10464cfab356SFlorian Fainelli } 10474cfab356SFlorian Fainelli #else 1048a7605370SArnd Bergmann static inline int dsa_ndo_eth_ioctl(struct net_device *dev, struct ifreq *ifr, 10494cfab356SFlorian Fainelli int cmd) 10504cfab356SFlorian Fainelli { 10514cfab356SFlorian Fainelli return -EOPNOTSUPP; 10524cfab356SFlorian Fainelli } 10534cfab356SFlorian Fainelli #endif 10544cfab356SFlorian Fainelli 105583c0afaeSAndrew Lunn void dsa_unregister_switch(struct dsa_switch *ds); 105623c9ee49SVivien Didelot int dsa_register_switch(struct dsa_switch *ds); 10570650bf52SVladimir Oltean void dsa_switch_shutdown(struct dsa_switch *ds); 10583b7bc1f0SVladimir Oltean struct dsa_switch *dsa_switch_find(int tree_index, int sw_index); 1059ea825e70SFlorian Fainelli #ifdef CONFIG_PM_SLEEP 1060ea825e70SFlorian Fainelli int dsa_switch_suspend(struct dsa_switch *ds); 1061ea825e70SFlorian Fainelli int dsa_switch_resume(struct dsa_switch *ds); 1062ea825e70SFlorian Fainelli #else 1063ea825e70SFlorian Fainelli static inline int dsa_switch_suspend(struct dsa_switch *ds) 1064ea825e70SFlorian Fainelli { 1065ea825e70SFlorian Fainelli return 0; 1066ea825e70SFlorian Fainelli } 1067ea825e70SFlorian Fainelli static inline int dsa_switch_resume(struct dsa_switch *ds) 1068ea825e70SFlorian Fainelli { 1069ea825e70SFlorian Fainelli return 0; 1070ea825e70SFlorian Fainelli } 1071ea825e70SFlorian Fainelli #endif /* CONFIG_PM_SLEEP */ 1072ea825e70SFlorian Fainelli 107360724d4bSFlorian Fainelli #if IS_ENABLED(CONFIG_NET_DSA) 1074a5e3c9baSVladimir Oltean bool dsa_slave_dev_check(const struct net_device *dev); 107560724d4bSFlorian Fainelli #else 1076a5e3c9baSVladimir Oltean static inline bool dsa_slave_dev_check(const struct net_device *dev) 1077a5e3c9baSVladimir Oltean { 1078a5e3c9baSVladimir Oltean return false; 1079a5e3c9baSVladimir Oltean } 108060724d4bSFlorian Fainelli #endif 108160724d4bSFlorian Fainelli 108297a69a0dSVladimir Oltean netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, struct net_device *dev); 1083cf963573SFlorian Fainelli int dsa_port_get_phy_strings(struct dsa_port *dp, uint8_t *data); 1084cf963573SFlorian Fainelli int dsa_port_get_ethtool_phy_stats(struct dsa_port *dp, uint64_t *data); 1085cf963573SFlorian Fainelli int dsa_port_get_phy_sset_count(struct dsa_port *dp); 108611d8f3ddSFlorian Fainelli void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up); 1087cf963573SFlorian Fainelli 1088d3b8c049SAndrew Lunn struct dsa_tag_driver { 1089d3b8c049SAndrew Lunn const struct dsa_device_ops *ops; 1090d3b8c049SAndrew Lunn struct list_head list; 1091d3b8c049SAndrew Lunn struct module *owner; 1092d3b8c049SAndrew Lunn }; 1093d3b8c049SAndrew Lunn 1094d3b8c049SAndrew Lunn void dsa_tag_drivers_register(struct dsa_tag_driver *dsa_tag_driver_array[], 1095d3b8c049SAndrew Lunn unsigned int count, 1096d3b8c049SAndrew Lunn struct module *owner); 1097d3b8c049SAndrew Lunn void dsa_tag_drivers_unregister(struct dsa_tag_driver *dsa_tag_driver_array[], 1098d3b8c049SAndrew Lunn unsigned int count); 1099d3b8c049SAndrew Lunn 1100d3b8c049SAndrew Lunn #define dsa_tag_driver_module_drivers(__dsa_tag_drivers_array, __count) \ 1101d3b8c049SAndrew Lunn static int __init dsa_tag_driver_module_init(void) \ 1102d3b8c049SAndrew Lunn { \ 1103d3b8c049SAndrew Lunn dsa_tag_drivers_register(__dsa_tag_drivers_array, __count, \ 1104d3b8c049SAndrew Lunn THIS_MODULE); \ 1105d3b8c049SAndrew Lunn return 0; \ 1106d3b8c049SAndrew Lunn } \ 1107d3b8c049SAndrew Lunn module_init(dsa_tag_driver_module_init); \ 1108d3b8c049SAndrew Lunn \ 1109d3b8c049SAndrew Lunn static void __exit dsa_tag_driver_module_exit(void) \ 1110d3b8c049SAndrew Lunn { \ 1111d3b8c049SAndrew Lunn dsa_tag_drivers_unregister(__dsa_tag_drivers_array, __count); \ 1112d3b8c049SAndrew Lunn } \ 1113d3b8c049SAndrew Lunn module_exit(dsa_tag_driver_module_exit) 1114d3b8c049SAndrew Lunn 1115d3b8c049SAndrew Lunn /** 1116d3b8c049SAndrew Lunn * module_dsa_tag_drivers() - Helper macro for registering DSA tag 1117d3b8c049SAndrew Lunn * drivers 1118d3b8c049SAndrew Lunn * @__ops_array: Array of tag driver strucutres 1119d3b8c049SAndrew Lunn * 1120d3b8c049SAndrew Lunn * Helper macro for DSA tag drivers which do not do anything special 1121d3b8c049SAndrew Lunn * in module init/exit. Each module may only use this macro once, and 1122d3b8c049SAndrew Lunn * calling it replaces module_init() and module_exit(). 1123d3b8c049SAndrew Lunn */ 1124d3b8c049SAndrew Lunn #define module_dsa_tag_drivers(__ops_array) \ 1125d3b8c049SAndrew Lunn dsa_tag_driver_module_drivers(__ops_array, ARRAY_SIZE(__ops_array)) 1126d3b8c049SAndrew Lunn 1127d3b8c049SAndrew Lunn #define DSA_TAG_DRIVER_NAME(__ops) dsa_tag_driver ## _ ## __ops 1128d3b8c049SAndrew Lunn 1129d3b8c049SAndrew Lunn /* Create a static structure we can build a linked list of dsa_tag 1130d3b8c049SAndrew Lunn * drivers 1131d3b8c049SAndrew Lunn */ 1132d3b8c049SAndrew Lunn #define DSA_TAG_DRIVER(__ops) \ 1133d3b8c049SAndrew Lunn static struct dsa_tag_driver DSA_TAG_DRIVER_NAME(__ops) = { \ 1134d3b8c049SAndrew Lunn .ops = &__ops, \ 1135d3b8c049SAndrew Lunn } 1136d3b8c049SAndrew Lunn 1137d3b8c049SAndrew Lunn /** 1138d3b8c049SAndrew Lunn * module_dsa_tag_driver() - Helper macro for registering a single DSA tag 1139d3b8c049SAndrew Lunn * driver 1140d3b8c049SAndrew Lunn * @__ops: Single tag driver structures 1141d3b8c049SAndrew Lunn * 1142d3b8c049SAndrew Lunn * Helper macro for DSA tag drivers which do not do anything special 1143d3b8c049SAndrew Lunn * in module init/exit. Each module may only use this macro once, and 1144d3b8c049SAndrew Lunn * calling it replaces module_init() and module_exit(). 1145d3b8c049SAndrew Lunn */ 1146d3b8c049SAndrew Lunn #define module_dsa_tag_driver(__ops) \ 1147d3b8c049SAndrew Lunn DSA_TAG_DRIVER(__ops); \ 1148d3b8c049SAndrew Lunn \ 1149d3b8c049SAndrew Lunn static struct dsa_tag_driver *dsa_tag_driver_array[] = { \ 1150d3b8c049SAndrew Lunn &DSA_TAG_DRIVER_NAME(__ops) \ 1151d3b8c049SAndrew Lunn }; \ 1152d3b8c049SAndrew Lunn module_dsa_tag_drivers(dsa_tag_driver_array) 115391da11f8SLennert Buytenhek #endif 1154d3b8c049SAndrew Lunn 1155