12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 291da11f8SLennert Buytenhek /* 391da11f8SLennert Buytenhek * include/net/dsa.h - Driver for Distributed Switch Architecture switch chips 4e84665c9SLennert Buytenhek * Copyright (c) 2008-2009 Marvell Semiconductor 591da11f8SLennert Buytenhek */ 691da11f8SLennert Buytenhek 791da11f8SLennert Buytenhek #ifndef __LINUX_NET_DSA_H 891da11f8SLennert Buytenhek #define __LINUX_NET_DSA_H 991da11f8SLennert Buytenhek 104d56a29fSRussell King #include <linux/if.h> 11ea1f51beSAxel Lin #include <linux/if_ether.h> 12c8f0b869SBen Hutchings #include <linux/list.h> 13f515f192SVivien Didelot #include <linux/notifier.h> 14cf50dcc2SBen Hutchings #include <linux/timer.h> 15cf50dcc2SBen Hutchings #include <linux/workqueue.h> 16fa981d9aSFlorian Fainelli #include <linux/of.h> 17a2820543SFlorian Fainelli #include <linux/ethtool.h> 180336369dSBrandon Streiff #include <linux/net_tstamp.h> 1911d8f3ddSFlorian Fainelli #include <linux/phy.h> 20ecfc9372SFlorian Fainelli #include <linux/platform_data/dsa.h> 2144cc27e4SIoana Ciornei #include <linux/phylink.h> 2296567d5dSAndrew Lunn #include <net/devlink.h> 23f0c24ccfSVivien Didelot #include <net/switchdev.h> 24cf50dcc2SBen Hutchings 2519d05ea7SVladimir Oltean struct dsa_8021q_context; 26f50f2127SFlorian Fainelli struct tc_action; 274d56a29fSRussell King struct phy_device; 284d56a29fSRussell King struct fixed_phy_status; 2911d8f3ddSFlorian Fainelli struct phylink_link_state; 30f50f2127SFlorian Fainelli 310b42f033SAndrew Lunn #define DSA_TAG_PROTO_NONE_VALUE 0 320b42f033SAndrew Lunn #define DSA_TAG_PROTO_BRCM_VALUE 1 330b42f033SAndrew Lunn #define DSA_TAG_PROTO_BRCM_PREPEND_VALUE 2 340b42f033SAndrew Lunn #define DSA_TAG_PROTO_DSA_VALUE 3 350b42f033SAndrew Lunn #define DSA_TAG_PROTO_EDSA_VALUE 4 360b42f033SAndrew Lunn #define DSA_TAG_PROTO_GSWIP_VALUE 5 370b42f033SAndrew Lunn #define DSA_TAG_PROTO_KSZ9477_VALUE 6 380b42f033SAndrew Lunn #define DSA_TAG_PROTO_KSZ9893_VALUE 7 390b42f033SAndrew Lunn #define DSA_TAG_PROTO_LAN9303_VALUE 8 400b42f033SAndrew Lunn #define DSA_TAG_PROTO_MTK_VALUE 9 410b42f033SAndrew Lunn #define DSA_TAG_PROTO_QCA_VALUE 10 420b42f033SAndrew Lunn #define DSA_TAG_PROTO_TRAILER_VALUE 11 43f9bbe447SVladimir Oltean #define DSA_TAG_PROTO_8021Q_VALUE 12 44227d07a0SVladimir Oltean #define DSA_TAG_PROTO_SJA1105_VALUE 13 45016e43a2STristram Ha #define DSA_TAG_PROTO_KSZ8795_VALUE 14 468dce89aaSVladimir Oltean #define DSA_TAG_PROTO_OCELOT_VALUE 15 4748fda74fSOleksij Rempel #define DSA_TAG_PROTO_AR9331_VALUE 16 48efd7fe68SLinus Walleij #define DSA_TAG_PROTO_RTL4_A_VALUE 17 4901ef09caSKurt Kanzenbach #define DSA_TAG_PROTO_HELLCREEK_VALUE 18 5054a52823SGeorge McCollister #define DSA_TAG_PROTO_XRS700X_VALUE 19 517c83a7c5SVladimir Oltean #define DSA_TAG_PROTO_OCELOT_8021Q_VALUE 20 527c4bb540SVladimir Oltean #define DSA_TAG_PROTO_SEVILLE_VALUE 21 53964dbf18SÁlvaro Fernández Rojas #define DSA_TAG_PROTO_BRCM_LEGACY_VALUE 22 544913b8ebSVladimir Oltean #define DSA_TAG_PROTO_SJA1110_VALUE 23 551521d5adSAlvin Šipraga #define DSA_TAG_PROTO_RTL8_4_VALUE 24 56cd87fecdSLuiz Angelo Daros de Luca #define DSA_TAG_PROTO_RTL8_4T_VALUE 25 57a08d6a6dSClément Léger #define DSA_TAG_PROTO_RZN1_A5PSW_VALUE 26 58092f8751SPrasanna Vengateshan #define DSA_TAG_PROTO_LAN937X_VALUE 27 590b42f033SAndrew Lunn 60ac7a04c3SFlorian Fainelli enum dsa_tag_protocol { 610b42f033SAndrew Lunn DSA_TAG_PROTO_NONE = DSA_TAG_PROTO_NONE_VALUE, 620b42f033SAndrew Lunn DSA_TAG_PROTO_BRCM = DSA_TAG_PROTO_BRCM_VALUE, 63964dbf18SÁlvaro Fernández Rojas DSA_TAG_PROTO_BRCM_LEGACY = DSA_TAG_PROTO_BRCM_LEGACY_VALUE, 640b42f033SAndrew Lunn DSA_TAG_PROTO_BRCM_PREPEND = DSA_TAG_PROTO_BRCM_PREPEND_VALUE, 650b42f033SAndrew Lunn DSA_TAG_PROTO_DSA = DSA_TAG_PROTO_DSA_VALUE, 660b42f033SAndrew Lunn DSA_TAG_PROTO_EDSA = DSA_TAG_PROTO_EDSA_VALUE, 670b42f033SAndrew Lunn DSA_TAG_PROTO_GSWIP = DSA_TAG_PROTO_GSWIP_VALUE, 680b42f033SAndrew Lunn DSA_TAG_PROTO_KSZ9477 = DSA_TAG_PROTO_KSZ9477_VALUE, 690b42f033SAndrew Lunn DSA_TAG_PROTO_KSZ9893 = DSA_TAG_PROTO_KSZ9893_VALUE, 700b42f033SAndrew Lunn DSA_TAG_PROTO_LAN9303 = DSA_TAG_PROTO_LAN9303_VALUE, 710b42f033SAndrew Lunn DSA_TAG_PROTO_MTK = DSA_TAG_PROTO_MTK_VALUE, 720b42f033SAndrew Lunn DSA_TAG_PROTO_QCA = DSA_TAG_PROTO_QCA_VALUE, 730b42f033SAndrew Lunn DSA_TAG_PROTO_TRAILER = DSA_TAG_PROTO_TRAILER_VALUE, 74f9bbe447SVladimir Oltean DSA_TAG_PROTO_8021Q = DSA_TAG_PROTO_8021Q_VALUE, 75227d07a0SVladimir Oltean DSA_TAG_PROTO_SJA1105 = DSA_TAG_PROTO_SJA1105_VALUE, 76016e43a2STristram Ha DSA_TAG_PROTO_KSZ8795 = DSA_TAG_PROTO_KSZ8795_VALUE, 778dce89aaSVladimir Oltean DSA_TAG_PROTO_OCELOT = DSA_TAG_PROTO_OCELOT_VALUE, 7848fda74fSOleksij Rempel DSA_TAG_PROTO_AR9331 = DSA_TAG_PROTO_AR9331_VALUE, 79efd7fe68SLinus Walleij DSA_TAG_PROTO_RTL4_A = DSA_TAG_PROTO_RTL4_A_VALUE, 8001ef09caSKurt Kanzenbach DSA_TAG_PROTO_HELLCREEK = DSA_TAG_PROTO_HELLCREEK_VALUE, 8154a52823SGeorge McCollister DSA_TAG_PROTO_XRS700X = DSA_TAG_PROTO_XRS700X_VALUE, 827c83a7c5SVladimir Oltean DSA_TAG_PROTO_OCELOT_8021Q = DSA_TAG_PROTO_OCELOT_8021Q_VALUE, 837c4bb540SVladimir Oltean DSA_TAG_PROTO_SEVILLE = DSA_TAG_PROTO_SEVILLE_VALUE, 844913b8ebSVladimir Oltean DSA_TAG_PROTO_SJA1110 = DSA_TAG_PROTO_SJA1110_VALUE, 851521d5adSAlvin Šipraga DSA_TAG_PROTO_RTL8_4 = DSA_TAG_PROTO_RTL8_4_VALUE, 86cd87fecdSLuiz Angelo Daros de Luca DSA_TAG_PROTO_RTL8_4T = DSA_TAG_PROTO_RTL8_4T_VALUE, 87a08d6a6dSClément Léger DSA_TAG_PROTO_RZN1_A5PSW = DSA_TAG_PROTO_RZN1_A5PSW_VALUE, 88092f8751SPrasanna Vengateshan DSA_TAG_PROTO_LAN937X = DSA_TAG_PROTO_LAN937X_VALUE, 89ac7a04c3SFlorian Fainelli }; 905037d532SFlorian Fainelli 9190af1059SBrandon Streiff struct dsa_switch; 923e8a72d1SFlorian Fainelli 9368277a2cSJohn Crispin struct dsa_device_ops { 9468277a2cSJohn Crispin struct sk_buff *(*xmit)(struct sk_buff *skb, struct net_device *dev); 9529a097b7SVladimir Oltean struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev); 962e8cb1b3SVladimir Oltean void (*flow_dissect)(const struct sk_buff *skb, __be16 *proto, 97598a9680SJohn Crispin int *offset); 987f297314SVladimir Oltean int (*connect)(struct dsa_switch *ds); 997f297314SVladimir Oltean void (*disconnect)(struct dsa_switch *ds); 1004e500251SVladimir Oltean unsigned int needed_headroom; 1014e500251SVladimir Oltean unsigned int needed_tailroom; 102875138f8SAndrew Lunn const char *name; 103056eed2fSAndrew Lunn enum dsa_tag_protocol proto; 104c3975400SVladimir Oltean /* Some tagging protocols either mangle or shift the destination MAC 105c3975400SVladimir Oltean * address, in which case the DSA master would drop packets on ingress 106c3975400SVladimir Oltean * if what it understands out of the destination MAC address is not in 107c3975400SVladimir Oltean * its RX filter. 108c3975400SVladimir Oltean */ 109c3975400SVladimir Oltean bool promisc_on_master; 11068277a2cSJohn Crispin }; 11168277a2cSJohn Crispin 112dedd6a00SVladimir Oltean struct dsa_lag { 113dedd6a00SVladimir Oltean struct net_device *dev; 114dedd6a00SVladimir Oltean unsigned int id; 115e212fa7cSVladimir Oltean struct mutex fdb_lock; 116e212fa7cSVladimir Oltean struct list_head fdbs; 117dedd6a00SVladimir Oltean refcount_t refcount; 118dedd6a00SVladimir Oltean }; 119dedd6a00SVladimir Oltean 120cf50dcc2SBen Hutchings struct dsa_switch_tree { 12183c0afaeSAndrew Lunn struct list_head list; 12283c0afaeSAndrew Lunn 123b035c88cSVladimir Oltean /* List of switch ports */ 124b035c88cSVladimir Oltean struct list_head ports; 125b035c88cSVladimir Oltean 126f515f192SVivien Didelot /* Notifier chain for switch-wide events */ 127f515f192SVivien Didelot struct raw_notifier_head nh; 128f515f192SVivien Didelot 12983c0afaeSAndrew Lunn /* Tree identifier */ 13049463b7fSVivien Didelot unsigned int index; 13183c0afaeSAndrew Lunn 13283c0afaeSAndrew Lunn /* Number of switches attached to this tree */ 13383c0afaeSAndrew Lunn struct kref refcount; 13483c0afaeSAndrew Lunn 135b035c88cSVladimir Oltean /* Maps offloaded LAG netdevs to a zero-based linear ID for 136b035c88cSVladimir Oltean * drivers that need it. 137b035c88cSVladimir Oltean */ 138dedd6a00SVladimir Oltean struct dsa_lag **lags; 139b035c88cSVladimir Oltean 140357f203bSVladimir Oltean /* Tagging protocol operations */ 141357f203bSVladimir Oltean const struct dsa_device_ops *tag_ops; 142357f203bSVladimir Oltean 143deff7107STobias Waldekranz /* Default tagging protocol preferred by the switches in this 144deff7107STobias Waldekranz * tree. 145deff7107STobias Waldekranz */ 146deff7107STobias Waldekranz enum dsa_tag_protocol default_proto; 147deff7107STobias Waldekranz 1484b026e82SVladimir Oltean /* Has this tree been applied to the hardware? */ 1494b026e82SVladimir Oltean bool setup; 1504b026e82SVladimir Oltean 151cf50dcc2SBen Hutchings /* 152cf50dcc2SBen Hutchings * Configuration data for the platform device that owns 153cf50dcc2SBen Hutchings * this dsa switch tree instance. 154cf50dcc2SBen Hutchings */ 155cf50dcc2SBen Hutchings struct dsa_platform_data *pd; 156cf85d08fSLennert Buytenhek 157c5f51765SVivien Didelot /* List of DSA links composing the routing table */ 158c5f51765SVivien Didelot struct list_head rtable; 159058102a6STobias Waldekranz 160b035c88cSVladimir Oltean /* Length of "lags" array */ 161058102a6STobias Waldekranz unsigned int lags_len; 1625b22d366SVladimir Oltean 1635b22d366SVladimir Oltean /* Track the largest switch index within a tree */ 1645b22d366SVladimir Oltean unsigned int last_switch; 165cf50dcc2SBen Hutchings }; 166cf50dcc2SBen Hutchings 1673d4a0a2aSVladimir Oltean /* LAG IDs are one-based, the dst->lags array is zero-based */ 168058102a6STobias Waldekranz #define dsa_lags_foreach_id(_id, _dst) \ 1693d4a0a2aSVladimir Oltean for ((_id) = 1; (_id) <= (_dst)->lags_len; (_id)++) \ 1703d4a0a2aSVladimir Oltean if ((_dst)->lags[(_id) - 1]) 171058102a6STobias Waldekranz 172058102a6STobias Waldekranz #define dsa_lag_foreach_port(_dp, _dst, _lag) \ 173058102a6STobias Waldekranz list_for_each_entry((_dp), &(_dst)->ports, list) \ 174dedd6a00SVladimir Oltean if (dsa_port_offloads_lag((_dp), (_lag))) 175058102a6STobias Waldekranz 17618596f50SGeorge McCollister #define dsa_hsr_foreach_port(_dp, _ds, _hsr) \ 17718596f50SGeorge McCollister list_for_each_entry((_dp), &(_ds)->dst->ports, list) \ 17818596f50SGeorge McCollister if ((_dp)->ds == (_ds) && (_dp)->hsr_dev == (_hsr)) 17918596f50SGeorge McCollister 180dedd6a00SVladimir Oltean static inline struct dsa_lag *dsa_lag_by_id(struct dsa_switch_tree *dst, 181058102a6STobias Waldekranz unsigned int id) 182058102a6STobias Waldekranz { 1833d4a0a2aSVladimir Oltean /* DSA LAG IDs are one-based, dst->lags is zero-based */ 1843d4a0a2aSVladimir Oltean return dst->lags[id - 1]; 185058102a6STobias Waldekranz } 186058102a6STobias Waldekranz 187058102a6STobias Waldekranz static inline int dsa_lag_id(struct dsa_switch_tree *dst, 18846a76724SVladimir Oltean struct net_device *lag_dev) 189058102a6STobias Waldekranz { 190058102a6STobias Waldekranz unsigned int id; 191058102a6STobias Waldekranz 192058102a6STobias Waldekranz dsa_lags_foreach_id(id, dst) { 193dedd6a00SVladimir Oltean struct dsa_lag *lag = dsa_lag_by_id(dst, id); 194dedd6a00SVladimir Oltean 195dedd6a00SVladimir Oltean if (lag->dev == lag_dev) 196dedd6a00SVladimir Oltean return lag->id; 197058102a6STobias Waldekranz } 198058102a6STobias Waldekranz 199058102a6STobias Waldekranz return -ENODEV; 200058102a6STobias Waldekranz } 201058102a6STobias Waldekranz 20234297176SVladimir Oltean /* TC matchall action types */ 203f50f2127SFlorian Fainelli enum dsa_port_mall_action_type { 204f50f2127SFlorian Fainelli DSA_PORT_MALL_MIRROR, 20534297176SVladimir Oltean DSA_PORT_MALL_POLICER, 206f50f2127SFlorian Fainelli }; 207f50f2127SFlorian Fainelli 208f50f2127SFlorian Fainelli /* TC mirroring entry */ 209f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry { 210f50f2127SFlorian Fainelli u8 to_local_port; 211f50f2127SFlorian Fainelli bool ingress; 212f50f2127SFlorian Fainelli }; 213f50f2127SFlorian Fainelli 21434297176SVladimir Oltean /* TC port policer entry */ 21534297176SVladimir Oltean struct dsa_mall_policer_tc_entry { 2165f035af7SPo Liu u32 burst; 21734297176SVladimir Oltean u64 rate_bytes_per_sec; 21834297176SVladimir Oltean }; 21934297176SVladimir Oltean 220f50f2127SFlorian Fainelli /* TC matchall entry */ 221f50f2127SFlorian Fainelli struct dsa_mall_tc_entry { 222f50f2127SFlorian Fainelli struct list_head list; 223f50f2127SFlorian Fainelli unsigned long cookie; 224f50f2127SFlorian Fainelli enum dsa_port_mall_action_type type; 225f50f2127SFlorian Fainelli union { 226f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry mirror; 22734297176SVladimir Oltean struct dsa_mall_policer_tc_entry policer; 228f50f2127SFlorian Fainelli }; 229f50f2127SFlorian Fainelli }; 230f50f2127SFlorian Fainelli 231d3eed0e5SVladimir Oltean struct dsa_bridge { 232d3eed0e5SVladimir Oltean struct net_device *dev; 233d3eed0e5SVladimir Oltean unsigned int num; 234857fdd74SVladimir Oltean bool tx_fwd_offload; 235d3eed0e5SVladimir Oltean refcount_t refcount; 236d3eed0e5SVladimir Oltean }; 237f50f2127SFlorian Fainelli 238c8b09808SAndrew Lunn struct dsa_port { 239f8b8b1cdSVivien Didelot /* A CPU port is physically connected to a master device. 240f8b8b1cdSVivien Didelot * A user port exposed to userspace has a slave device. 241f8b8b1cdSVivien Didelot */ 242f8b8b1cdSVivien Didelot union { 243f8b8b1cdSVivien Didelot struct net_device *master; 244f8b8b1cdSVivien Didelot struct net_device *slave; 245f8b8b1cdSVivien Didelot }; 246f8b8b1cdSVivien Didelot 247357f203bSVladimir Oltean /* Copy of the tagging protocol operations, for quicker access 248357f203bSVladimir Oltean * in the data path. Valid only for the CPU ports. 249357f203bSVladimir Oltean */ 25015240248SVivien Didelot const struct dsa_device_ops *tag_ops; 25115240248SVivien Didelot 2523e41f93bSVivien Didelot /* Copies for faster access in master receive hot path */ 2533e41f93bSVivien Didelot struct dsa_switch_tree *dst; 25429a097b7SVladimir Oltean struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev); 2553e41f93bSVivien Didelot 25606251258SVladimir Oltean struct dsa_switch *ds; 25706251258SVladimir Oltean 25806251258SVladimir Oltean unsigned int index; 25906251258SVladimir Oltean 260057cad2cSVivien Didelot enum { 261057cad2cSVivien Didelot DSA_PORT_TYPE_UNUSED = 0, 262057cad2cSVivien Didelot DSA_PORT_TYPE_CPU, 263057cad2cSVivien Didelot DSA_PORT_TYPE_DSA, 264057cad2cSVivien Didelot DSA_PORT_TYPE_USER, 265057cad2cSVivien Didelot } type; 266057cad2cSVivien Didelot 26771e0bbdeSFlorian Fainelli const char *name; 26868b2d4a8SVivien Didelot struct dsa_port *cpu_dp; 26983216e39SMichael Walle u8 mac[ETH_ALEN]; 270b08db33dSVladimir Oltean 271b08db33dSVladimir Oltean u8 stp_state; 272b08db33dSVladimir Oltean 2731b26d364SVladimir Oltean /* Warning: the following bit fields are not atomic, and updating them 2741b26d364SVladimir Oltean * can only be done from code paths where concurrency is not possible 2751b26d364SVladimir Oltean * (probe time or under rtnl_lock). 2761b26d364SVladimir Oltean */ 27763cfc657SVladimir Oltean u8 vlan_filtering:1; 27863cfc657SVladimir Oltean 27963cfc657SVladimir Oltean /* Managed by DSA on user ports and by drivers on CPU and DSA ports */ 28063cfc657SVladimir Oltean u8 learning:1; 28163cfc657SVladimir Oltean 28263cfc657SVladimir Oltean u8 lag_tx_enabled:1; 28363cfc657SVladimir Oltean 284295ab96fSVladimir Oltean /* Master state bits, valid only on CPU ports */ 285295ab96fSVladimir Oltean u8 master_admin_up:1; 286295ab96fSVladimir Oltean u8 master_oper_up:1; 287295ab96fSVladimir Oltean 288acc43b7bSVladimir Oltean /* Valid only on user ports */ 289acc43b7bSVladimir Oltean u8 cpu_port_in_lag:1; 290acc43b7bSVladimir Oltean 29163cfc657SVladimir Oltean u8 setup:1; 292bde82f38SVladimir Oltean 293189b0d93SAndrew Lunn struct device_node *dn; 29434a79f63SVivien Didelot unsigned int ageing_time; 295bde82f38SVladimir Oltean 296d3eed0e5SVladimir Oltean struct dsa_bridge *bridge; 29796567d5dSAndrew Lunn struct devlink_port devlink_port; 298aab9c406SFlorian Fainelli struct phylink *pl; 29944cc27e4SIoana Ciornei struct phylink_config pl_config; 300dedd6a00SVladimir Oltean struct dsa_lag *lag; 30118596f50SGeorge McCollister struct net_device *hsr_dev; 30297a69a0dSVladimir Oltean 303ab8ccae1SVivien Didelot struct list_head list; 304ab8ccae1SVivien Didelot 30567dbb9d4SFlorian Fainelli /* 30667dbb9d4SFlorian Fainelli * Original copy of the master netdev ethtool_ops 30767dbb9d4SFlorian Fainelli */ 30867dbb9d4SFlorian Fainelli const struct ethtool_ops *orig_ethtool_ops; 309da7b9e9bSFlorian Fainelli 310161ca59dSVladimir Oltean /* List of MAC addresses that must be forwarded on this port. 311161ca59dSVladimir Oltean * These are only valid on CPU ports and DSA links. 312161ca59dSVladimir Oltean */ 313338a3a47SVladimir Oltean struct mutex addr_lists_lock; 3143f6e32f9SVladimir Oltean struct list_head fdbs; 315161ca59dSVladimir Oltean struct list_head mdbs; 316134ef238SVladimir Oltean 317134ef238SVladimir Oltean /* List of VLANs that CPU and DSA ports are members of. */ 318134ef238SVladimir Oltean struct mutex vlans_lock; 319134ef238SVladimir Oltean struct list_head vlans; 320c8b09808SAndrew Lunn }; 321c8b09808SAndrew Lunn 322c5f51765SVivien Didelot /* TODO: ideally DSA ports would have a single dp->link_dp member, 323c5f51765SVivien Didelot * and no dst->rtable nor this struct dsa_link would be needed, 324c5f51765SVivien Didelot * but this would require some more complex tree walking, 325c5f51765SVivien Didelot * so keep it stupid at the moment and list them all. 326c5f51765SVivien Didelot */ 327c5f51765SVivien Didelot struct dsa_link { 328c5f51765SVivien Didelot struct dsa_port *dp; 329c5f51765SVivien Didelot struct dsa_port *link_dp; 330c5f51765SVivien Didelot struct list_head list; 331c5f51765SVivien Didelot }; 332c5f51765SVivien Didelot 333c2693363SVladimir Oltean enum dsa_db_type { 334c2693363SVladimir Oltean DSA_DB_PORT, 335c2693363SVladimir Oltean DSA_DB_LAG, 336c2693363SVladimir Oltean DSA_DB_BRIDGE, 337c2693363SVladimir Oltean }; 338c2693363SVladimir Oltean 339c2693363SVladimir Oltean struct dsa_db { 340c2693363SVladimir Oltean enum dsa_db_type type; 341c2693363SVladimir Oltean 342c2693363SVladimir Oltean union { 343c2693363SVladimir Oltean const struct dsa_port *dp; 344c2693363SVladimir Oltean struct dsa_lag lag; 345c2693363SVladimir Oltean struct dsa_bridge bridge; 346c2693363SVladimir Oltean }; 347c2693363SVladimir Oltean }; 348c2693363SVladimir Oltean 349161ca59dSVladimir Oltean struct dsa_mac_addr { 350161ca59dSVladimir Oltean unsigned char addr[ETH_ALEN]; 351161ca59dSVladimir Oltean u16 vid; 352161ca59dSVladimir Oltean refcount_t refcount; 353161ca59dSVladimir Oltean struct list_head list; 354c2693363SVladimir Oltean struct dsa_db db; 355161ca59dSVladimir Oltean }; 356161ca59dSVladimir Oltean 357134ef238SVladimir Oltean struct dsa_vlan { 358134ef238SVladimir Oltean u16 vid; 359134ef238SVladimir Oltean refcount_t refcount; 360134ef238SVladimir Oltean struct list_head list; 361134ef238SVladimir Oltean }; 362134ef238SVladimir Oltean 363c8f0b869SBen Hutchings struct dsa_switch { 364c33063d6SAndrew Lunn struct device *dev; 365c33063d6SAndrew Lunn 366c8f0b869SBen Hutchings /* 367c8f0b869SBen Hutchings * Parent switch tree, and switch index. 368c8f0b869SBen Hutchings */ 369c8f0b869SBen Hutchings struct dsa_switch_tree *dst; 37099feaafcSVivien Didelot unsigned int index; 371c8f0b869SBen Hutchings 3721b26d364SVladimir Oltean /* Warning: the following bit fields are not atomic, and updating them 3731b26d364SVladimir Oltean * can only be done from code paths where concurrency is not possible 3741b26d364SVladimir Oltean * (probe time or under rtnl_lock). 3751b26d364SVladimir Oltean */ 37663cfc657SVladimir Oltean u32 setup:1; 37763cfc657SVladimir Oltean 37863cfc657SVladimir Oltean /* Disallow bridge core from requesting different VLAN awareness 37963cfc657SVladimir Oltean * settings on ports if not hardware-supported 3807787ff77SVladimir Oltean */ 38163cfc657SVladimir Oltean u32 vlan_filtering_is_global:1; 38263cfc657SVladimir Oltean 38363cfc657SVladimir Oltean /* Keep VLAN filtering enabled on ports not offloading any upper */ 38463cfc657SVladimir Oltean u32 needs_standalone_vlan_filtering:1; 38563cfc657SVladimir Oltean 38663cfc657SVladimir Oltean /* Pass .port_vlan_add and .port_vlan_del to drivers even for bridges 38763cfc657SVladimir Oltean * that have vlan_filtering=0. All drivers should ideally set this (and 38863cfc657SVladimir Oltean * then the option would get removed), but it is unknown whether this 3897787ff77SVladimir Oltean * would break things or not. 3907787ff77SVladimir Oltean */ 39163cfc657SVladimir Oltean u32 configure_vlan_while_not_filtering:1; 39263cfc657SVladimir Oltean 39363cfc657SVladimir Oltean /* If the switch driver always programs the CPU port as egress tagged 39463cfc657SVladimir Oltean * despite the VLAN configuration indicating otherwise, then setting 39563cfc657SVladimir Oltean * @untag_bridge_pvid will force the DSA receive path to pop the 39663cfc657SVladimir Oltean * bridge's default_pvid VLAN tagged frames to offer a consistent 39763cfc657SVladimir Oltean * behavior between a vlan_filtering=0 and vlan_filtering=1 bridge 3987787ff77SVladimir Oltean * device. 3997787ff77SVladimir Oltean */ 40063cfc657SVladimir Oltean u32 untag_bridge_pvid:1; 40163cfc657SVladimir Oltean 4027787ff77SVladimir Oltean /* Let DSA manage the FDB entries towards the 4037787ff77SVladimir Oltean * CPU, based on the software bridge database. 4047787ff77SVladimir Oltean */ 40563cfc657SVladimir Oltean u32 assisted_learning_on_cpu_port:1; 40663cfc657SVladimir Oltean 40763cfc657SVladimir Oltean /* In case vlan_filtering_is_global is set, the VLAN awareness state 40863cfc657SVladimir Oltean * should be retrieved from here and not from the per-port settings. 4097787ff77SVladimir Oltean */ 41063cfc657SVladimir Oltean u32 vlan_filtering:1; 41163cfc657SVladimir Oltean 41263cfc657SVladimir Oltean /* For switches that only have the MRU configurable. To ensure the 41363cfc657SVladimir Oltean * configured MTU is not exceeded, normalization of MRU on all bridged 41463cfc657SVladimir Oltean * interfaces is needed. 4157787ff77SVladimir Oltean */ 41663cfc657SVladimir Oltean u32 mtu_enforcement_ingress:1; 4177787ff77SVladimir Oltean 418c2693363SVladimir Oltean /* Drivers that isolate the FDBs of multiple bridges must set this 419c2693363SVladimir Oltean * to true to receive the bridge as an argument in .port_fdb_{add,del} 420c2693363SVladimir Oltean * and .port_mdb_{add,del}. Otherwise, the bridge.num will always be 421c2693363SVladimir Oltean * passed as zero. 422c2693363SVladimir Oltean */ 423c2693363SVladimir Oltean u32 fdb_isolation:1; 424c2693363SVladimir Oltean 425f515f192SVivien Didelot /* Listener for switch fabric events */ 426f515f192SVivien Didelot struct notifier_block nb; 427f515f192SVivien Didelot 428c8f0b869SBen Hutchings /* 4297543a6d5SAndrew Lunn * Give the switch driver somewhere to hang its private data 4307543a6d5SAndrew Lunn * structure. 4317543a6d5SAndrew Lunn */ 4327543a6d5SAndrew Lunn void *priv; 4337543a6d5SAndrew Lunn 434dc452a47SVladimir Oltean void *tagger_data; 435dc452a47SVladimir Oltean 4367543a6d5SAndrew Lunn /* 437c8f0b869SBen Hutchings * Configuration data for this switch. 438c8f0b869SBen Hutchings */ 439ff04955cSAndrew Lunn struct dsa_chip_data *cd; 440c8f0b869SBen Hutchings 441c8f0b869SBen Hutchings /* 4429d490b4eSVivien Didelot * The switch operations. 443c8f0b869SBen Hutchings */ 444a82f67afSFlorian Fainelli const struct dsa_switch_ops *ops; 445c8f0b869SBen Hutchings 44666472fc0SAndrew Lunn /* 447c8f0b869SBen Hutchings * Slave mii_bus and devices for the individual ports. 448c8f0b869SBen Hutchings */ 4490d8bcdd3SFlorian Fainelli u32 phys_mii_mask; 450c8f0b869SBen Hutchings struct mii_bus *slave_mii_bus; 451a0c02161SVivien Didelot 4520f3da6afSVivien Didelot /* Ageing Time limits in msecs */ 4530f3da6afSVivien Didelot unsigned int ageing_time_min; 4540f3da6afSVivien Didelot unsigned int ageing_time_max; 4550f3da6afSVivien Didelot 456d7b1fd52SVladimir Oltean /* Storage for drivers using tag_8021q */ 457d7b1fd52SVladimir Oltean struct dsa_8021q_context *tag_8021q_ctx; 458d7b1fd52SVladimir Oltean 45996567d5dSAndrew Lunn /* devlink used to represent this switch device */ 46096567d5dSAndrew Lunn struct devlink *devlink; 46196567d5dSAndrew Lunn 46255199df6SFlorian Fainelli /* Number of switch port queues */ 46355199df6SFlorian Fainelli unsigned int num_tx_queues; 46455199df6SFlorian Fainelli 465058102a6STobias Waldekranz /* Drivers that benefit from having an ID associated with each 466058102a6STobias Waldekranz * offloaded LAG should set this to the maximum number of 467058102a6STobias Waldekranz * supported IDs. DSA will then maintain a mapping of _at 468058102a6STobias Waldekranz * least_ these many IDs, accessible to drivers via 469058102a6STobias Waldekranz * dsa_lag_id(). 470058102a6STobias Waldekranz */ 471058102a6STobias Waldekranz unsigned int num_lag_ids; 472058102a6STobias Waldekranz 473947c8746SVladimir Oltean /* Drivers that support bridge forwarding offload or FDB isolation 474947c8746SVladimir Oltean * should set this to the maximum number of bridges spanning the same 475947c8746SVladimir Oltean * switch tree (or all trees, in the case of cross-tree bridging 476947c8746SVladimir Oltean * support) that can be offloaded. 477123abc06SVladimir Oltean */ 478947c8746SVladimir Oltean unsigned int max_num_bridges; 479123abc06SVladimir Oltean 480258030acSVladimir Oltean unsigned int num_ports; 481c8f0b869SBen Hutchings }; 482c8f0b869SBen Hutchings 48368bb8ea8SVivien Didelot static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p) 484c38c5a66SVivien Didelot { 485b96ddf25SVivien Didelot struct dsa_switch_tree *dst = ds->dst; 486d607525bSVivien Didelot struct dsa_port *dp; 487b96ddf25SVivien Didelot 488b96ddf25SVivien Didelot list_for_each_entry(dp, &dst->ports, list) 489b96ddf25SVivien Didelot if (dp->ds == ds && dp->index == p) 490b96ddf25SVivien Didelot return dp; 491d607525bSVivien Didelot 492d607525bSVivien Didelot return NULL; 493c38c5a66SVivien Didelot } 494c38c5a66SVivien Didelot 495a8986681SVladimir Oltean static inline bool dsa_port_is_dsa(struct dsa_port *port) 496a8986681SVladimir Oltean { 497a8986681SVladimir Oltean return port->type == DSA_PORT_TYPE_DSA; 498a8986681SVladimir Oltean } 499a8986681SVladimir Oltean 500a8986681SVladimir Oltean static inline bool dsa_port_is_cpu(struct dsa_port *port) 501a8986681SVladimir Oltean { 502a8986681SVladimir Oltean return port->type == DSA_PORT_TYPE_CPU; 503a8986681SVladimir Oltean } 504a8986681SVladimir Oltean 505a8986681SVladimir Oltean static inline bool dsa_port_is_user(struct dsa_port *dp) 506a8986681SVladimir Oltean { 507a8986681SVladimir Oltean return dp->type == DSA_PORT_TYPE_USER; 508a8986681SVladimir Oltean } 509a8986681SVladimir Oltean 510a57d8c21SVladimir Oltean static inline bool dsa_port_is_unused(struct dsa_port *dp) 511a57d8c21SVladimir Oltean { 512a57d8c21SVladimir Oltean return dp->type == DSA_PORT_TYPE_UNUSED; 513a57d8c21SVladimir Oltean } 514a57d8c21SVladimir Oltean 515295ab96fSVladimir Oltean static inline bool dsa_port_master_is_operational(struct dsa_port *dp) 516295ab96fSVladimir Oltean { 517295ab96fSVladimir Oltean return dsa_port_is_cpu(dp) && dp->master_admin_up && 518295ab96fSVladimir Oltean dp->master_oper_up; 519295ab96fSVladimir Oltean } 520295ab96fSVladimir Oltean 521bff7b688SVivien Didelot static inline bool dsa_is_unused_port(struct dsa_switch *ds, int p) 522bff7b688SVivien Didelot { 523c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_UNUSED; 524bff7b688SVivien Didelot } 525bff7b688SVivien Didelot 526c8f0b869SBen Hutchings static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p) 527c8f0b869SBen Hutchings { 528c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_CPU; 529c8f0b869SBen Hutchings } 530c8f0b869SBen Hutchings 53160045cbfSAndrew Lunn static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p) 53260045cbfSAndrew Lunn { 533c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_DSA; 53460045cbfSAndrew Lunn } 53560045cbfSAndrew Lunn 5362b3e9891SVivien Didelot static inline bool dsa_is_user_port(struct dsa_switch *ds, int p) 5376cd456f3SVivien Didelot { 538c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_USER; 5396cd456f3SVivien Didelot } 5406cd456f3SVivien Didelot 54182b31898SVladimir Oltean #define dsa_tree_for_each_user_port(_dp, _dst) \ 54282b31898SVladimir Oltean list_for_each_entry((_dp), &(_dst)->ports, list) \ 54382b31898SVladimir Oltean if (dsa_port_is_user((_dp))) 54482b31898SVladimir Oltean 54595f510d0SVladimir Oltean #define dsa_tree_for_each_user_port_continue_reverse(_dp, _dst) \ 54695f510d0SVladimir Oltean list_for_each_entry_continue_reverse((_dp), &(_dst)->ports, list) \ 54795f510d0SVladimir Oltean if (dsa_port_is_user((_dp))) 54895f510d0SVladimir Oltean 5495dc760d1SVladimir Oltean #define dsa_tree_for_each_cpu_port(_dp, _dst) \ 5505dc760d1SVladimir Oltean list_for_each_entry((_dp), &(_dst)->ports, list) \ 5515dc760d1SVladimir Oltean if (dsa_port_is_cpu((_dp))) 5525dc760d1SVladimir Oltean 55382b31898SVladimir Oltean #define dsa_switch_for_each_port(_dp, _ds) \ 55482b31898SVladimir Oltean list_for_each_entry((_dp), &(_ds)->dst->ports, list) \ 55582b31898SVladimir Oltean if ((_dp)->ds == (_ds)) 55682b31898SVladimir Oltean 55782b31898SVladimir Oltean #define dsa_switch_for_each_port_safe(_dp, _next, _ds) \ 55882b31898SVladimir Oltean list_for_each_entry_safe((_dp), (_next), &(_ds)->dst->ports, list) \ 55982b31898SVladimir Oltean if ((_dp)->ds == (_ds)) 56082b31898SVladimir Oltean 56182b31898SVladimir Oltean #define dsa_switch_for_each_port_continue_reverse(_dp, _ds) \ 56282b31898SVladimir Oltean list_for_each_entry_continue_reverse((_dp), &(_ds)->dst->ports, list) \ 56382b31898SVladimir Oltean if ((_dp)->ds == (_ds)) 56482b31898SVladimir Oltean 56582b31898SVladimir Oltean #define dsa_switch_for_each_available_port(_dp, _ds) \ 56682b31898SVladimir Oltean dsa_switch_for_each_port((_dp), (_ds)) \ 56782b31898SVladimir Oltean if (!dsa_port_is_unused((_dp))) 56882b31898SVladimir Oltean 56982b31898SVladimir Oltean #define dsa_switch_for_each_user_port(_dp, _ds) \ 57082b31898SVladimir Oltean dsa_switch_for_each_port((_dp), (_ds)) \ 57182b31898SVladimir Oltean if (dsa_port_is_user((_dp))) 57282b31898SVladimir Oltean 57382b31898SVladimir Oltean #define dsa_switch_for_each_cpu_port(_dp, _ds) \ 57482b31898SVladimir Oltean dsa_switch_for_each_port((_dp), (_ds)) \ 57582b31898SVladimir Oltean if (dsa_port_is_cpu((_dp))) 57682b31898SVladimir Oltean 577bacf93b0SVladimir Oltean #define dsa_switch_for_each_cpu_port_continue_reverse(_dp, _ds) \ 578bacf93b0SVladimir Oltean dsa_switch_for_each_port_continue_reverse((_dp), (_ds)) \ 579bacf93b0SVladimir Oltean if (dsa_port_is_cpu((_dp))) 580bacf93b0SVladimir Oltean 58102bc6e54SVivien Didelot static inline u32 dsa_user_ports(struct dsa_switch *ds) 58202bc6e54SVivien Didelot { 583d0004a02SVladimir Oltean struct dsa_port *dp; 584c38c5a66SVivien Didelot u32 mask = 0; 58502bc6e54SVivien Didelot 586d0004a02SVladimir Oltean dsa_switch_for_each_user_port(dp, ds) 587d0004a02SVladimir Oltean mask |= BIT(dp->index); 588c38c5a66SVivien Didelot 589c38c5a66SVivien Didelot return mask; 590c8652c83SVivien Didelot } 591c8652c83SVivien Didelot 592465c3de4SVladimir Oltean static inline u32 dsa_cpu_ports(struct dsa_switch *ds) 593465c3de4SVladimir Oltean { 594465c3de4SVladimir Oltean struct dsa_port *cpu_dp; 595465c3de4SVladimir Oltean u32 mask = 0; 596465c3de4SVladimir Oltean 597465c3de4SVladimir Oltean dsa_switch_for_each_cpu_port(cpu_dp, ds) 598465c3de4SVladimir Oltean mask |= BIT(cpu_dp->index); 599465c3de4SVladimir Oltean 600465c3de4SVladimir Oltean return mask; 601465c3de4SVladimir Oltean } 602465c3de4SVladimir Oltean 603c5f51765SVivien Didelot /* Return the local port used to reach an arbitrary switch device */ 604c5f51765SVivien Didelot static inline unsigned int dsa_routing_port(struct dsa_switch *ds, int device) 605c5f51765SVivien Didelot { 606c5f51765SVivien Didelot struct dsa_switch_tree *dst = ds->dst; 607c5f51765SVivien Didelot struct dsa_link *dl; 608c5f51765SVivien Didelot 609c5f51765SVivien Didelot list_for_each_entry(dl, &dst->rtable, list) 610c5f51765SVivien Didelot if (dl->dp->ds == ds && dl->link_dp->ds->index == device) 611c5f51765SVivien Didelot return dl->dp->index; 612c5f51765SVivien Didelot 613c5f51765SVivien Didelot return ds->num_ports; 614c5f51765SVivien Didelot } 615c5f51765SVivien Didelot 6163b8fac5dSVivien Didelot /* Return the local port used to reach an arbitrary switch port */ 6173b8fac5dSVivien Didelot static inline unsigned int dsa_towards_port(struct dsa_switch *ds, int device, 6183b8fac5dSVivien Didelot int port) 6193b8fac5dSVivien Didelot { 6203b8fac5dSVivien Didelot if (device == ds->index) 6213b8fac5dSVivien Didelot return port; 6223b8fac5dSVivien Didelot else 623c5f51765SVivien Didelot return dsa_routing_port(ds, device); 6243b8fac5dSVivien Didelot } 6253b8fac5dSVivien Didelot 6263b8fac5dSVivien Didelot /* Return the local port used to reach the dedicated CPU port */ 62707073c79SVivien Didelot static inline unsigned int dsa_upstream_port(struct dsa_switch *ds, int port) 628c8f0b869SBen Hutchings { 62907073c79SVivien Didelot const struct dsa_port *dp = dsa_to_port(ds, port); 63007073c79SVivien Didelot const struct dsa_port *cpu_dp = dp->cpu_dp; 63107073c79SVivien Didelot 63207073c79SVivien Didelot if (!cpu_dp) 63307073c79SVivien Didelot return port; 634c8f0b869SBen Hutchings 6353b8fac5dSVivien Didelot return dsa_towards_port(ds, cpu_dp->ds->index, cpu_dp->index); 636c8f0b869SBen Hutchings } 637c8f0b869SBen Hutchings 63863609c8fSVladimir Oltean /* Return true if this is the local port used to reach the CPU port */ 63963609c8fSVladimir Oltean static inline bool dsa_is_upstream_port(struct dsa_switch *ds, int port) 64063609c8fSVladimir Oltean { 64163609c8fSVladimir Oltean if (dsa_is_unused_port(ds, port)) 64263609c8fSVladimir Oltean return false; 64363609c8fSVladimir Oltean 64463609c8fSVladimir Oltean return port == dsa_upstream_port(ds, port); 64563609c8fSVladimir Oltean } 64663609c8fSVladimir Oltean 647d352b20fSTobias Waldekranz /* Return true if this is a DSA port leading away from the CPU */ 648d352b20fSTobias Waldekranz static inline bool dsa_is_downstream_port(struct dsa_switch *ds, int port) 649d352b20fSTobias Waldekranz { 650d352b20fSTobias Waldekranz return dsa_is_dsa_port(ds, port) && !dsa_is_upstream_port(ds, port); 651d352b20fSTobias Waldekranz } 652d352b20fSTobias Waldekranz 6537af4a361STobias Waldekranz /* Return the local port used to reach the CPU port */ 6547af4a361STobias Waldekranz static inline unsigned int dsa_switch_upstream_port(struct dsa_switch *ds) 6557af4a361STobias Waldekranz { 6567af4a361STobias Waldekranz struct dsa_port *dp; 6577af4a361STobias Waldekranz 6587af4a361STobias Waldekranz dsa_switch_for_each_available_port(dp, ds) { 6597af4a361STobias Waldekranz return dsa_upstream_port(ds, dp->index); 6607af4a361STobias Waldekranz } 6617af4a361STobias Waldekranz 6627af4a361STobias Waldekranz return ds->num_ports; 6637af4a361STobias Waldekranz } 6647af4a361STobias Waldekranz 66563609c8fSVladimir Oltean /* Return true if @upstream_ds is an upstream switch of @downstream_ds, meaning 66663609c8fSVladimir Oltean * that the routing port from @downstream_ds to @upstream_ds is also the port 66763609c8fSVladimir Oltean * which @downstream_ds uses to reach its dedicated CPU. 66863609c8fSVladimir Oltean */ 66963609c8fSVladimir Oltean static inline bool dsa_switch_is_upstream_of(struct dsa_switch *upstream_ds, 67063609c8fSVladimir Oltean struct dsa_switch *downstream_ds) 67163609c8fSVladimir Oltean { 67263609c8fSVladimir Oltean int routing_port; 67363609c8fSVladimir Oltean 67463609c8fSVladimir Oltean if (upstream_ds == downstream_ds) 67563609c8fSVladimir Oltean return true; 67663609c8fSVladimir Oltean 67763609c8fSVladimir Oltean routing_port = dsa_routing_port(downstream_ds, upstream_ds->index); 67863609c8fSVladimir Oltean 67963609c8fSVladimir Oltean return dsa_is_upstream_port(downstream_ds, routing_port); 68063609c8fSVladimir Oltean } 68163609c8fSVladimir Oltean 682cf2d45f5SVladimir Oltean static inline bool dsa_port_is_vlan_filtering(const struct dsa_port *dp) 683cf2d45f5SVladimir Oltean { 684cf2d45f5SVladimir Oltean const struct dsa_switch *ds = dp->ds; 685cf2d45f5SVladimir Oltean 686cf2d45f5SVladimir Oltean if (ds->vlan_filtering_is_global) 687cf2d45f5SVladimir Oltean return ds->vlan_filtering; 688cf2d45f5SVladimir Oltean else 689cf2d45f5SVladimir Oltean return dp->vlan_filtering; 690cf2d45f5SVladimir Oltean } 691cf2d45f5SVladimir Oltean 692dedd6a00SVladimir Oltean static inline unsigned int dsa_port_lag_id_get(struct dsa_port *dp) 693dedd6a00SVladimir Oltean { 694dedd6a00SVladimir Oltean return dp->lag ? dp->lag->id : 0; 695dedd6a00SVladimir Oltean } 696dedd6a00SVladimir Oltean 697dedd6a00SVladimir Oltean static inline struct net_device *dsa_port_lag_dev_get(struct dsa_port *dp) 698dedd6a00SVladimir Oltean { 699dedd6a00SVladimir Oltean return dp->lag ? dp->lag->dev : NULL; 700dedd6a00SVladimir Oltean } 701dedd6a00SVladimir Oltean 702dedd6a00SVladimir Oltean static inline bool dsa_port_offloads_lag(struct dsa_port *dp, 703dedd6a00SVladimir Oltean const struct dsa_lag *lag) 704dedd6a00SVladimir Oltean { 705dedd6a00SVladimir Oltean return dsa_port_lag_dev_get(dp) == lag->dev; 706dedd6a00SVladimir Oltean } 707dedd6a00SVladimir Oltean 7088f6a19c0SVladimir Oltean static inline struct net_device *dsa_port_to_master(const struct dsa_port *dp) 7098f6a19c0SVladimir Oltean { 710acc43b7bSVladimir Oltean if (dp->cpu_port_in_lag) 711acc43b7bSVladimir Oltean return dsa_port_lag_dev_get(dp->cpu_dp); 712acc43b7bSVladimir Oltean 7138f6a19c0SVladimir Oltean return dp->cpu_dp->master; 7148f6a19c0SVladimir Oltean } 7158f6a19c0SVladimir Oltean 716cc76ce9eSTobias Waldekranz static inline 717cc76ce9eSTobias Waldekranz struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp) 718cc76ce9eSTobias Waldekranz { 719d3eed0e5SVladimir Oltean if (!dp->bridge) 720cc76ce9eSTobias Waldekranz return NULL; 721cc76ce9eSTobias Waldekranz 722dedd6a00SVladimir Oltean if (dp->lag) 723dedd6a00SVladimir Oltean return dp->lag->dev; 724cc76ce9eSTobias Waldekranz else if (dp->hsr_dev) 725cc76ce9eSTobias Waldekranz return dp->hsr_dev; 726cc76ce9eSTobias Waldekranz 727cc76ce9eSTobias Waldekranz return dp->slave; 728cc76ce9eSTobias Waldekranz } 729cc76ce9eSTobias Waldekranz 73036cbf39bSVladimir Oltean static inline struct net_device * 73136cbf39bSVladimir Oltean dsa_port_bridge_dev_get(const struct dsa_port *dp) 73236cbf39bSVladimir Oltean { 733d3eed0e5SVladimir Oltean return dp->bridge ? dp->bridge->dev : NULL; 73436cbf39bSVladimir Oltean } 73536cbf39bSVladimir Oltean 73636cbf39bSVladimir Oltean static inline unsigned int dsa_port_bridge_num_get(struct dsa_port *dp) 73736cbf39bSVladimir Oltean { 738d3eed0e5SVladimir Oltean return dp->bridge ? dp->bridge->num : 0; 73936cbf39bSVladimir Oltean } 74036cbf39bSVladimir Oltean 74136cbf39bSVladimir Oltean static inline bool dsa_port_bridge_same(const struct dsa_port *a, 74236cbf39bSVladimir Oltean const struct dsa_port *b) 74336cbf39bSVladimir Oltean { 74436cbf39bSVladimir Oltean struct net_device *br_a = dsa_port_bridge_dev_get(a); 74536cbf39bSVladimir Oltean struct net_device *br_b = dsa_port_bridge_dev_get(b); 74636cbf39bSVladimir Oltean 74736cbf39bSVladimir Oltean /* Standalone ports are not in the same bridge with one another */ 74836cbf39bSVladimir Oltean return (!br_a || !br_b) ? false : (br_a == br_b); 74936cbf39bSVladimir Oltean } 75036cbf39bSVladimir Oltean 7516a43cba3SVladimir Oltean static inline bool dsa_port_offloads_bridge_port(struct dsa_port *dp, 7526a43cba3SVladimir Oltean const struct net_device *dev) 7536a43cba3SVladimir Oltean { 7546a43cba3SVladimir Oltean return dsa_port_to_bridge_port(dp) == dev; 7556a43cba3SVladimir Oltean } 7566a43cba3SVladimir Oltean 7576a43cba3SVladimir Oltean static inline bool 7586a43cba3SVladimir Oltean dsa_port_offloads_bridge_dev(struct dsa_port *dp, 7596a43cba3SVladimir Oltean const struct net_device *bridge_dev) 7606a43cba3SVladimir Oltean { 7616a43cba3SVladimir Oltean /* DSA ports connected to a bridge, and event was emitted 7626a43cba3SVladimir Oltean * for the bridge. 7636a43cba3SVladimir Oltean */ 7646a43cba3SVladimir Oltean return dsa_port_bridge_dev_get(dp) == bridge_dev; 7656a43cba3SVladimir Oltean } 7666a43cba3SVladimir Oltean 767d3eed0e5SVladimir Oltean static inline bool dsa_port_offloads_bridge(struct dsa_port *dp, 768d3eed0e5SVladimir Oltean const struct dsa_bridge *bridge) 769d3eed0e5SVladimir Oltean { 770d3eed0e5SVladimir Oltean return dsa_port_bridge_dev_get(dp) == bridge->dev; 771d3eed0e5SVladimir Oltean } 772d3eed0e5SVladimir Oltean 7736a43cba3SVladimir Oltean /* Returns true if any port of this tree offloads the given net_device */ 7746a43cba3SVladimir Oltean static inline bool dsa_tree_offloads_bridge_port(struct dsa_switch_tree *dst, 7756a43cba3SVladimir Oltean const struct net_device *dev) 7766a43cba3SVladimir Oltean { 7776a43cba3SVladimir Oltean struct dsa_port *dp; 7786a43cba3SVladimir Oltean 7796a43cba3SVladimir Oltean list_for_each_entry(dp, &dst->ports, list) 7806a43cba3SVladimir Oltean if (dsa_port_offloads_bridge_port(dp, dev)) 7816a43cba3SVladimir Oltean return true; 7826a43cba3SVladimir Oltean 7836a43cba3SVladimir Oltean return false; 7846a43cba3SVladimir Oltean } 7856a43cba3SVladimir Oltean 7866a43cba3SVladimir Oltean /* Returns true if any port of this tree offloads the given bridge */ 7876a43cba3SVladimir Oltean static inline bool 7886a43cba3SVladimir Oltean dsa_tree_offloads_bridge_dev(struct dsa_switch_tree *dst, 7896a43cba3SVladimir Oltean const struct net_device *bridge_dev) 7906a43cba3SVladimir Oltean { 7916a43cba3SVladimir Oltean struct dsa_port *dp; 7926a43cba3SVladimir Oltean 7936a43cba3SVladimir Oltean list_for_each_entry(dp, &dst->ports, list) 7946a43cba3SVladimir Oltean if (dsa_port_offloads_bridge_dev(dp, bridge_dev)) 7956a43cba3SVladimir Oltean return true; 7966a43cba3SVladimir Oltean 7976a43cba3SVladimir Oltean return false; 7986a43cba3SVladimir Oltean } 7996a43cba3SVladimir Oltean 800acc43b7bSVladimir Oltean static inline bool dsa_port_tree_same(const struct dsa_port *a, 801acc43b7bSVladimir Oltean const struct dsa_port *b) 802acc43b7bSVladimir Oltean { 803acc43b7bSVladimir Oltean return a->ds->dst == b->ds->dst; 804acc43b7bSVladimir Oltean } 805acc43b7bSVladimir Oltean 8062bedde1aSArkadi Sharshevsky typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid, 8072bedde1aSArkadi Sharshevsky bool is_static, void *data); 8089d490b4eSVivien Didelot struct dsa_switch_ops { 80953da0ebaSVladimir Oltean /* 81053da0ebaSVladimir Oltean * Tagging protocol helpers called for the CPU ports and DSA links. 81153da0ebaSVladimir Oltean * @get_tag_protocol retrieves the initial tagging protocol and is 81253da0ebaSVladimir Oltean * mandatory. Switches which can operate using multiple tagging 81353da0ebaSVladimir Oltean * protocols should implement @change_tag_protocol and report in 81453da0ebaSVladimir Oltean * @get_tag_protocol the tagger in current use. 81553da0ebaSVladimir Oltean */ 8165ed4e3ebSFlorian Fainelli enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds, 8174d776482SFlorian Fainelli int port, 8184d776482SFlorian Fainelli enum dsa_tag_protocol mprot); 819bacf93b0SVladimir Oltean int (*change_tag_protocol)(struct dsa_switch *ds, 82053da0ebaSVladimir Oltean enum dsa_tag_protocol proto); 821dc452a47SVladimir Oltean /* 822dc452a47SVladimir Oltean * Method for switch drivers to connect to the tagging protocol driver 823dc452a47SVladimir Oltean * in current use. The switch driver can provide handlers for certain 824dc452a47SVladimir Oltean * types of packets for switch management. 825dc452a47SVladimir Oltean */ 826dc452a47SVladimir Oltean int (*connect_tag_protocol)(struct dsa_switch *ds, 827dc452a47SVladimir Oltean enum dsa_tag_protocol proto); 8287b314362SAndrew Lunn 82995f510d0SVladimir Oltean int (*port_change_master)(struct dsa_switch *ds, int port, 83095f510d0SVladimir Oltean struct net_device *master, 83195f510d0SVladimir Oltean struct netlink_ext_ack *extack); 83295f510d0SVladimir Oltean 833fd292c18SVladimir Oltean /* Optional switch-wide initialization and destruction methods */ 834c8f0b869SBen Hutchings int (*setup)(struct dsa_switch *ds); 8355e3f847aSVladimir Oltean void (*teardown)(struct dsa_switch *ds); 836fd292c18SVladimir Oltean 837fd292c18SVladimir Oltean /* Per-port initialization and destruction methods. Mandatory if the 838fd292c18SVladimir Oltean * driver registers devlink port regions, optional otherwise. 839fd292c18SVladimir Oltean */ 840fd292c18SVladimir Oltean int (*port_setup)(struct dsa_switch *ds, int port); 841fd292c18SVladimir Oltean void (*port_teardown)(struct dsa_switch *ds, int port); 842fd292c18SVladimir Oltean 8436819563eSFlorian Fainelli u32 (*get_phy_flags)(struct dsa_switch *ds, int port); 844c8f0b869SBen Hutchings 845c8f0b869SBen Hutchings /* 846c8f0b869SBen Hutchings * Access to the switch's PHY registers. 847c8f0b869SBen Hutchings */ 848c8f0b869SBen Hutchings int (*phy_read)(struct dsa_switch *ds, int port, int regnum); 849c8f0b869SBen Hutchings int (*phy_write)(struct dsa_switch *ds, int port, 850c8f0b869SBen Hutchings int regnum, u16 val); 851c8f0b869SBen Hutchings 852c8f0b869SBen Hutchings /* 853ec9436baSFlorian Fainelli * Link state adjustment (called from libphy) 854ec9436baSFlorian Fainelli */ 855ec9436baSFlorian Fainelli void (*adjust_link)(struct dsa_switch *ds, int port, 856ec9436baSFlorian Fainelli struct phy_device *phydev); 857ce31b31cSFlorian Fainelli void (*fixed_link_update)(struct dsa_switch *ds, int port, 858ce31b31cSFlorian Fainelli struct fixed_phy_status *st); 859ec9436baSFlorian Fainelli 860ec9436baSFlorian Fainelli /* 86111d8f3ddSFlorian Fainelli * PHYLINK integration 86211d8f3ddSFlorian Fainelli */ 863072eea6cSRussell King (Oracle) void (*phylink_get_caps)(struct dsa_switch *ds, int port, 864072eea6cSRussell King (Oracle) struct phylink_config *config); 865bde01822SRussell King (Oracle) struct phylink_pcs *(*phylink_mac_select_pcs)(struct dsa_switch *ds, 866bde01822SRussell King (Oracle) int port, 867bde01822SRussell King (Oracle) phy_interface_t iface); 86811d8f3ddSFlorian Fainelli int (*phylink_mac_link_state)(struct dsa_switch *ds, int port, 86911d8f3ddSFlorian Fainelli struct phylink_link_state *state); 870*dd805cf3SRussell King (Oracle) int (*phylink_mac_prepare)(struct dsa_switch *ds, int port, 871*dd805cf3SRussell King (Oracle) unsigned int mode, 872*dd805cf3SRussell King (Oracle) phy_interface_t interface); 87311d8f3ddSFlorian Fainelli void (*phylink_mac_config)(struct dsa_switch *ds, int port, 87411d8f3ddSFlorian Fainelli unsigned int mode, 87511d8f3ddSFlorian Fainelli const struct phylink_link_state *state); 876*dd805cf3SRussell King (Oracle) int (*phylink_mac_finish)(struct dsa_switch *ds, int port, 877*dd805cf3SRussell King (Oracle) unsigned int mode, 878*dd805cf3SRussell King (Oracle) phy_interface_t interface); 87911d8f3ddSFlorian Fainelli void (*phylink_mac_an_restart)(struct dsa_switch *ds, int port); 88011d8f3ddSFlorian Fainelli void (*phylink_mac_link_down)(struct dsa_switch *ds, int port, 88111d8f3ddSFlorian Fainelli unsigned int mode, 88211d8f3ddSFlorian Fainelli phy_interface_t interface); 88311d8f3ddSFlorian Fainelli void (*phylink_mac_link_up)(struct dsa_switch *ds, int port, 88411d8f3ddSFlorian Fainelli unsigned int mode, 88511d8f3ddSFlorian Fainelli phy_interface_t interface, 8865b502a7bSRussell King struct phy_device *phydev, 8875b502a7bSRussell King int speed, int duplex, 8885b502a7bSRussell King bool tx_pause, bool rx_pause); 88911d8f3ddSFlorian Fainelli void (*phylink_fixed_state)(struct dsa_switch *ds, int port, 89011d8f3ddSFlorian Fainelli struct phylink_link_state *state); 89111d8f3ddSFlorian Fainelli /* 892c2ec5f2eSOleksij Rempel * Port statistics counters. 893c8f0b869SBen Hutchings */ 89489f09048SFlorian Fainelli void (*get_strings)(struct dsa_switch *ds, int port, 89589f09048SFlorian Fainelli u32 stringset, uint8_t *data); 896c8f0b869SBen Hutchings void (*get_ethtool_stats)(struct dsa_switch *ds, 897c8f0b869SBen Hutchings int port, uint64_t *data); 89889f09048SFlorian Fainelli int (*get_sset_count)(struct dsa_switch *ds, int port, int sset); 899cf963573SFlorian Fainelli void (*get_ethtool_phy_stats)(struct dsa_switch *ds, 900cf963573SFlorian Fainelli int port, uint64_t *data); 901487d3855SAlvin Šipraga void (*get_eth_phy_stats)(struct dsa_switch *ds, int port, 902487d3855SAlvin Šipraga struct ethtool_eth_phy_stats *phy_stats); 903487d3855SAlvin Šipraga void (*get_eth_mac_stats)(struct dsa_switch *ds, int port, 904487d3855SAlvin Šipraga struct ethtool_eth_mac_stats *mac_stats); 905487d3855SAlvin Šipraga void (*get_eth_ctrl_stats)(struct dsa_switch *ds, int port, 906487d3855SAlvin Šipraga struct ethtool_eth_ctrl_stats *ctrl_stats); 90767f38b1cSClément Léger void (*get_rmon_stats)(struct dsa_switch *ds, int port, 90867f38b1cSClément Léger struct ethtool_rmon_stats *rmon_stats, 90967f38b1cSClément Léger const struct ethtool_rmon_hist_range **ranges); 910c2ec5f2eSOleksij Rempel void (*get_stats64)(struct dsa_switch *ds, int port, 911c2ec5f2eSOleksij Rempel struct rtnl_link_stats64 *s); 9123d410403SOleksij Rempel void (*get_pause_stats)(struct dsa_switch *ds, int port, 9133d410403SOleksij Rempel struct ethtool_pause_stats *pause_stats); 914a71acad9SOleksij Rempel void (*self_test)(struct dsa_switch *ds, int port, 915a71acad9SOleksij Rempel struct ethtool_test *etest, u64 *data); 91624462549SFlorian Fainelli 91724462549SFlorian Fainelli /* 91819e57c4eSFlorian Fainelli * ethtool Wake-on-LAN 91919e57c4eSFlorian Fainelli */ 92019e57c4eSFlorian Fainelli void (*get_wol)(struct dsa_switch *ds, int port, 92119e57c4eSFlorian Fainelli struct ethtool_wolinfo *w); 92219e57c4eSFlorian Fainelli int (*set_wol)(struct dsa_switch *ds, int port, 92319e57c4eSFlorian Fainelli struct ethtool_wolinfo *w); 92419e57c4eSFlorian Fainelli 92519e57c4eSFlorian Fainelli /* 9260336369dSBrandon Streiff * ethtool timestamp info 9270336369dSBrandon Streiff */ 9280336369dSBrandon Streiff int (*get_ts_info)(struct dsa_switch *ds, int port, 9290336369dSBrandon Streiff struct ethtool_ts_info *ts); 9300336369dSBrandon Streiff 9310336369dSBrandon Streiff /* 9325f6c2d49SVladimir Oltean * ethtool MAC merge layer 9335f6c2d49SVladimir Oltean */ 9345f6c2d49SVladimir Oltean int (*get_mm)(struct dsa_switch *ds, int port, 9355f6c2d49SVladimir Oltean struct ethtool_mm_state *state); 9365f6c2d49SVladimir Oltean int (*set_mm)(struct dsa_switch *ds, int port, 9375f6c2d49SVladimir Oltean struct ethtool_mm_cfg *cfg, 9385f6c2d49SVladimir Oltean struct netlink_ext_ack *extack); 9395f6c2d49SVladimir Oltean void (*get_mm_stats)(struct dsa_switch *ds, int port, 9405f6c2d49SVladimir Oltean struct ethtool_mm_stats *stats); 9415f6c2d49SVladimir Oltean 9425f6c2d49SVladimir Oltean /* 943d538eca8SVladimir Oltean * DCB ops 944d538eca8SVladimir Oltean */ 945d538eca8SVladimir Oltean int (*port_get_default_prio)(struct dsa_switch *ds, int port); 946d538eca8SVladimir Oltean int (*port_set_default_prio)(struct dsa_switch *ds, int port, 947d538eca8SVladimir Oltean u8 prio); 94847d75f78SVladimir Oltean int (*port_get_dscp_prio)(struct dsa_switch *ds, int port, u8 dscp); 94947d75f78SVladimir Oltean int (*port_add_dscp_prio)(struct dsa_switch *ds, int port, u8 dscp, 95047d75f78SVladimir Oltean u8 prio); 95147d75f78SVladimir Oltean int (*port_del_dscp_prio)(struct dsa_switch *ds, int port, u8 dscp, 95247d75f78SVladimir Oltean u8 prio); 953d538eca8SVladimir Oltean 954d538eca8SVladimir Oltean /* 95524462549SFlorian Fainelli * Suspend and resume 95624462549SFlorian Fainelli */ 95724462549SFlorian Fainelli int (*suspend)(struct dsa_switch *ds); 95824462549SFlorian Fainelli int (*resume)(struct dsa_switch *ds); 959b2f2af21SFlorian Fainelli 960b2f2af21SFlorian Fainelli /* 961b2f2af21SFlorian Fainelli * Port enable/disable 962b2f2af21SFlorian Fainelli */ 963b2f2af21SFlorian Fainelli int (*port_enable)(struct dsa_switch *ds, int port, 964b2f2af21SFlorian Fainelli struct phy_device *phy); 96575104db0SAndrew Lunn void (*port_disable)(struct dsa_switch *ds, int port); 9667905288fSFlorian Fainelli 9677905288fSFlorian Fainelli /* 96808f50061SVivien Didelot * Port's MAC EEE settings 9697905288fSFlorian Fainelli */ 97008f50061SVivien Didelot int (*set_mac_eee)(struct dsa_switch *ds, int port, 9717905288fSFlorian Fainelli struct ethtool_eee *e); 97208f50061SVivien Didelot int (*get_mac_eee)(struct dsa_switch *ds, int port, 9737905288fSFlorian Fainelli struct ethtool_eee *e); 97451579c3fSGuenter Roeck 9756793abb4SGuenter Roeck /* EEPROM access */ 9766793abb4SGuenter Roeck int (*get_eeprom_len)(struct dsa_switch *ds); 9776793abb4SGuenter Roeck int (*get_eeprom)(struct dsa_switch *ds, 9786793abb4SGuenter Roeck struct ethtool_eeprom *eeprom, u8 *data); 9796793abb4SGuenter Roeck int (*set_eeprom)(struct dsa_switch *ds, 9806793abb4SGuenter Roeck struct ethtool_eeprom *eeprom, u8 *data); 9813d762a0fSGuenter Roeck 9823d762a0fSGuenter Roeck /* 9833d762a0fSGuenter Roeck * Register access. 9843d762a0fSGuenter Roeck */ 9853d762a0fSGuenter Roeck int (*get_regs_len)(struct dsa_switch *ds, int port); 9863d762a0fSGuenter Roeck void (*get_regs)(struct dsa_switch *ds, int port, 9873d762a0fSGuenter Roeck struct ethtool_regs *regs, void *p); 988b73adef6SFlorian Fainelli 989b73adef6SFlorian Fainelli /* 990e358bef7SVladimir Oltean * Upper device tracking. 991e358bef7SVladimir Oltean */ 992e358bef7SVladimir Oltean int (*port_prechangeupper)(struct dsa_switch *ds, int port, 993e358bef7SVladimir Oltean struct netdev_notifier_changeupper_info *info); 994e358bef7SVladimir Oltean 995e358bef7SVladimir Oltean /* 996b73adef6SFlorian Fainelli * Bridge integration 997b73adef6SFlorian Fainelli */ 99834a79f63SVivien Didelot int (*set_ageing_time)(struct dsa_switch *ds, unsigned int msecs); 99971327a4eSVivien Didelot int (*port_bridge_join)(struct dsa_switch *ds, int port, 1000b079922bSVladimir Oltean struct dsa_bridge bridge, 100106b9cce4SVladimir Oltean bool *tx_fwd_offload, 100206b9cce4SVladimir Oltean struct netlink_ext_ack *extack); 1003f123f2fbSVivien Didelot void (*port_bridge_leave)(struct dsa_switch *ds, int port, 1004d3eed0e5SVladimir Oltean struct dsa_bridge bridge); 100543c44a9fSVivien Didelot void (*port_stp_state_set)(struct dsa_switch *ds, int port, 1006b73adef6SFlorian Fainelli u8 state); 10077414af30STobias Waldekranz int (*port_mst_state_set)(struct dsa_switch *ds, int port, 10087414af30STobias Waldekranz const struct switchdev_mst_state *state); 1009732f794cSVivien Didelot void (*port_fast_age)(struct dsa_switch *ds, int port); 10107414af30STobias Waldekranz int (*port_vlan_fast_age)(struct dsa_switch *ds, int port, u16 vid); 1011a8b659e7SVladimir Oltean int (*port_pre_bridge_flags)(struct dsa_switch *ds, int port, 1012a8b659e7SVladimir Oltean struct switchdev_brport_flags flags, 1013a8b659e7SVladimir Oltean struct netlink_ext_ack *extack); 1014a8b659e7SVladimir Oltean int (*port_bridge_flags)(struct dsa_switch *ds, int port, 1015a8b659e7SVladimir Oltean struct switchdev_brport_flags flags, 1016a8b659e7SVladimir Oltean struct netlink_ext_ack *extack); 101772c3b0c7SVladimir Oltean void (*port_set_host_flood)(struct dsa_switch *ds, int port, 101872c3b0c7SVladimir Oltean bool uc, bool mc); 10192a778e1bSVivien Didelot 10202a778e1bSVivien Didelot /* 102111149536SVivien Didelot * VLAN support 102211149536SVivien Didelot */ 1023fb2dabadSVivien Didelot int (*port_vlan_filtering)(struct dsa_switch *ds, int port, 102489153ed6SVladimir Oltean bool vlan_filtering, 102589153ed6SVladimir Oltean struct netlink_ext_ack *extack); 10261958d581SVladimir Oltean int (*port_vlan_add)(struct dsa_switch *ds, int port, 102731046a5fSVladimir Oltean const struct switchdev_obj_port_vlan *vlan, 102831046a5fSVladimir Oltean struct netlink_ext_ack *extack); 102976e398a6SVivien Didelot int (*port_vlan_del)(struct dsa_switch *ds, int port, 103076e398a6SVivien Didelot const struct switchdev_obj_port_vlan *vlan); 10318e6598a7STobias Waldekranz int (*vlan_msti_set)(struct dsa_switch *ds, struct dsa_bridge bridge, 10328e6598a7STobias Waldekranz const struct switchdev_vlan_msti *msti); 10338e6598a7STobias Waldekranz 103411149536SVivien Didelot /* 10352a778e1bSVivien Didelot * Forwarding database 10362a778e1bSVivien Didelot */ 10371b6dd556SArkadi Sharshevsky int (*port_fdb_add)(struct dsa_switch *ds, int port, 1038c2693363SVladimir Oltean const unsigned char *addr, u16 vid, 1039c2693363SVladimir Oltean struct dsa_db db); 10402a778e1bSVivien Didelot int (*port_fdb_del)(struct dsa_switch *ds, int port, 1041c2693363SVladimir Oltean const unsigned char *addr, u16 vid, 1042c2693363SVladimir Oltean struct dsa_db db); 1043ea70ba98SVivien Didelot int (*port_fdb_dump)(struct dsa_switch *ds, int port, 10442bedde1aSArkadi Sharshevsky dsa_fdb_dump_cb_t *cb, void *data); 1045e212fa7cSVladimir Oltean int (*lag_fdb_add)(struct dsa_switch *ds, struct dsa_lag lag, 1046c2693363SVladimir Oltean const unsigned char *addr, u16 vid, 1047c2693363SVladimir Oltean struct dsa_db db); 1048e212fa7cSVladimir Oltean int (*lag_fdb_del)(struct dsa_switch *ds, struct dsa_lag lag, 1049c2693363SVladimir Oltean const unsigned char *addr, u16 vid, 1050c2693363SVladimir Oltean struct dsa_db db); 10518df30255SVivien Didelot 10528df30255SVivien Didelot /* 10538df30255SVivien Didelot * Multicast database 10548df30255SVivien Didelot */ 1055a52b2da7SVladimir Oltean int (*port_mdb_add)(struct dsa_switch *ds, int port, 1056c2693363SVladimir Oltean const struct switchdev_obj_port_mdb *mdb, 1057c2693363SVladimir Oltean struct dsa_db db); 10588df30255SVivien Didelot int (*port_mdb_del)(struct dsa_switch *ds, int port, 1059c2693363SVladimir Oltean const struct switchdev_obj_port_mdb *mdb, 1060c2693363SVladimir Oltean struct dsa_db db); 1061bf9f2648SFlorian Fainelli /* 1062bf9f2648SFlorian Fainelli * RXNFC 1063bf9f2648SFlorian Fainelli */ 1064bf9f2648SFlorian Fainelli int (*get_rxnfc)(struct dsa_switch *ds, int port, 1065bf9f2648SFlorian Fainelli struct ethtool_rxnfc *nfc, u32 *rule_locs); 1066bf9f2648SFlorian Fainelli int (*set_rxnfc)(struct dsa_switch *ds, int port, 1067bf9f2648SFlorian Fainelli struct ethtool_rxnfc *nfc); 1068f50f2127SFlorian Fainelli 1069f50f2127SFlorian Fainelli /* 1070f50f2127SFlorian Fainelli * TC integration 1071f50f2127SFlorian Fainelli */ 1072ed11bb1fSVladimir Oltean int (*cls_flower_add)(struct dsa_switch *ds, int port, 1073ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, bool ingress); 1074ed11bb1fSVladimir Oltean int (*cls_flower_del)(struct dsa_switch *ds, int port, 1075ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, bool ingress); 1076ed11bb1fSVladimir Oltean int (*cls_flower_stats)(struct dsa_switch *ds, int port, 1077ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, bool ingress); 1078f50f2127SFlorian Fainelli int (*port_mirror_add)(struct dsa_switch *ds, int port, 1079f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror, 10800148bb50SVladimir Oltean bool ingress, struct netlink_ext_ack *extack); 1081f50f2127SFlorian Fainelli void (*port_mirror_del)(struct dsa_switch *ds, int port, 1082f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror); 108334297176SVladimir Oltean int (*port_policer_add)(struct dsa_switch *ds, int port, 108434297176SVladimir Oltean struct dsa_mall_policer_tc_entry *policer); 108534297176SVladimir Oltean void (*port_policer_del)(struct dsa_switch *ds, int port); 108647d23af2SVladimir Oltean int (*port_setup_tc)(struct dsa_switch *ds, int port, 108747d23af2SVladimir Oltean enum tc_setup_type type, void *type_data); 108840ef2c93SVivien Didelot 108940ef2c93SVivien Didelot /* 109040ef2c93SVivien Didelot * Cross-chip operations 109140ef2c93SVivien Didelot */ 1092f66a6a69SVladimir Oltean int (*crosschip_bridge_join)(struct dsa_switch *ds, int tree_index, 1093f66a6a69SVladimir Oltean int sw_index, int port, 109406b9cce4SVladimir Oltean struct dsa_bridge bridge, 109506b9cce4SVladimir Oltean struct netlink_ext_ack *extack); 1096f66a6a69SVladimir Oltean void (*crosschip_bridge_leave)(struct dsa_switch *ds, int tree_index, 1097f66a6a69SVladimir Oltean int sw_index, int port, 1098d3eed0e5SVladimir Oltean struct dsa_bridge bridge); 1099058102a6STobias Waldekranz int (*crosschip_lag_change)(struct dsa_switch *ds, int sw_index, 1100058102a6STobias Waldekranz int port); 1101058102a6STobias Waldekranz int (*crosschip_lag_join)(struct dsa_switch *ds, int sw_index, 1102dedd6a00SVladimir Oltean int port, struct dsa_lag lag, 11032e359b00SVladimir Oltean struct netdev_lag_upper_info *info, 11042e359b00SVladimir Oltean struct netlink_ext_ack *extack); 1105058102a6STobias Waldekranz int (*crosschip_lag_leave)(struct dsa_switch *ds, int sw_index, 1106dedd6a00SVladimir Oltean int port, struct dsa_lag lag); 11070336369dSBrandon Streiff 11080336369dSBrandon Streiff /* 11090336369dSBrandon Streiff * PTP functionality 11100336369dSBrandon Streiff */ 11110336369dSBrandon Streiff int (*port_hwtstamp_get)(struct dsa_switch *ds, int port, 11120336369dSBrandon Streiff struct ifreq *ifr); 11130336369dSBrandon Streiff int (*port_hwtstamp_set)(struct dsa_switch *ds, int port, 11140336369dSBrandon Streiff struct ifreq *ifr); 11155c5416f5SYangbo Lu void (*port_txtstamp)(struct dsa_switch *ds, int port, 11165c5416f5SYangbo Lu struct sk_buff *skb); 111790af1059SBrandon Streiff bool (*port_rxtstamp)(struct dsa_switch *ds, int port, 111890af1059SBrandon Streiff struct sk_buff *skb, unsigned int type); 111997a69a0dSVladimir Oltean 11200f06b855SAndrew Lunn /* Devlink parameters, etc */ 11216b297524SAndrew Lunn int (*devlink_param_get)(struct dsa_switch *ds, u32 id, 11226b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx); 11236b297524SAndrew Lunn int (*devlink_param_set)(struct dsa_switch *ds, u32 id, 11246b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx); 11250f06b855SAndrew Lunn int (*devlink_info_get)(struct dsa_switch *ds, 11260f06b855SAndrew Lunn struct devlink_info_req *req, 11270f06b855SAndrew Lunn struct netlink_ext_ack *extack); 11282a6ef763SVladimir Oltean int (*devlink_sb_pool_get)(struct dsa_switch *ds, 11292a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index, 11302a6ef763SVladimir Oltean struct devlink_sb_pool_info *pool_info); 11312a6ef763SVladimir Oltean int (*devlink_sb_pool_set)(struct dsa_switch *ds, unsigned int sb_index, 11322a6ef763SVladimir Oltean u16 pool_index, u32 size, 11332a6ef763SVladimir Oltean enum devlink_sb_threshold_type threshold_type, 11342a6ef763SVladimir Oltean struct netlink_ext_ack *extack); 11352a6ef763SVladimir Oltean int (*devlink_sb_port_pool_get)(struct dsa_switch *ds, int port, 11362a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index, 11372a6ef763SVladimir Oltean u32 *p_threshold); 11382a6ef763SVladimir Oltean int (*devlink_sb_port_pool_set)(struct dsa_switch *ds, int port, 11392a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index, 11402a6ef763SVladimir Oltean u32 threshold, 11412a6ef763SVladimir Oltean struct netlink_ext_ack *extack); 11422a6ef763SVladimir Oltean int (*devlink_sb_tc_pool_bind_get)(struct dsa_switch *ds, int port, 11432a6ef763SVladimir Oltean unsigned int sb_index, u16 tc_index, 11442a6ef763SVladimir Oltean enum devlink_sb_pool_type pool_type, 11452a6ef763SVladimir Oltean u16 *p_pool_index, u32 *p_threshold); 11462a6ef763SVladimir Oltean int (*devlink_sb_tc_pool_bind_set)(struct dsa_switch *ds, int port, 11472a6ef763SVladimir Oltean unsigned int sb_index, u16 tc_index, 11482a6ef763SVladimir Oltean enum devlink_sb_pool_type pool_type, 11492a6ef763SVladimir Oltean u16 pool_index, u32 threshold, 11502a6ef763SVladimir Oltean struct netlink_ext_ack *extack); 11512a6ef763SVladimir Oltean int (*devlink_sb_occ_snapshot)(struct dsa_switch *ds, 11522a6ef763SVladimir Oltean unsigned int sb_index); 11532a6ef763SVladimir Oltean int (*devlink_sb_occ_max_clear)(struct dsa_switch *ds, 11542a6ef763SVladimir Oltean unsigned int sb_index); 11552a6ef763SVladimir Oltean int (*devlink_sb_occ_port_pool_get)(struct dsa_switch *ds, int port, 11562a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index, 11572a6ef763SVladimir Oltean u32 *p_cur, u32 *p_max); 11582a6ef763SVladimir Oltean int (*devlink_sb_occ_tc_port_bind_get)(struct dsa_switch *ds, int port, 11592a6ef763SVladimir Oltean unsigned int sb_index, u16 tc_index, 11602a6ef763SVladimir Oltean enum devlink_sb_pool_type pool_type, 11612a6ef763SVladimir Oltean u32 *p_cur, u32 *p_max); 1162bfcb8132SVladimir Oltean 1163bfcb8132SVladimir Oltean /* 1164bfcb8132SVladimir Oltean * MTU change functionality. Switches can also adjust their MRU through 1165bfcb8132SVladimir Oltean * this method. By MTU, one understands the SDU (L2 payload) length. 1166bfcb8132SVladimir Oltean * If the switch needs to account for the DSA tag on the CPU port, this 1167ab88d64aSRandy Dunlap * method needs to do so privately. 1168bfcb8132SVladimir Oltean */ 1169bfcb8132SVladimir Oltean int (*port_change_mtu)(struct dsa_switch *ds, int port, 1170bfcb8132SVladimir Oltean int new_mtu); 1171bfcb8132SVladimir Oltean int (*port_max_mtu)(struct dsa_switch *ds, int port); 1172058102a6STobias Waldekranz 1173058102a6STobias Waldekranz /* 1174058102a6STobias Waldekranz * LAG integration 1175058102a6STobias Waldekranz */ 1176058102a6STobias Waldekranz int (*port_lag_change)(struct dsa_switch *ds, int port); 1177058102a6STobias Waldekranz int (*port_lag_join)(struct dsa_switch *ds, int port, 1178dedd6a00SVladimir Oltean struct dsa_lag lag, 11792e359b00SVladimir Oltean struct netdev_lag_upper_info *info, 11802e359b00SVladimir Oltean struct netlink_ext_ack *extack); 1181058102a6STobias Waldekranz int (*port_lag_leave)(struct dsa_switch *ds, int port, 1182dedd6a00SVladimir Oltean struct dsa_lag lag); 118318596f50SGeorge McCollister 118418596f50SGeorge McCollister /* 118518596f50SGeorge McCollister * HSR integration 118618596f50SGeorge McCollister */ 118718596f50SGeorge McCollister int (*port_hsr_join)(struct dsa_switch *ds, int port, 118818596f50SGeorge McCollister struct net_device *hsr); 118918596f50SGeorge McCollister int (*port_hsr_leave)(struct dsa_switch *ds, int port, 119018596f50SGeorge McCollister struct net_device *hsr); 1191c595c433SHoratiu Vultur 1192c595c433SHoratiu Vultur /* 1193c595c433SHoratiu Vultur * MRP integration 1194c595c433SHoratiu Vultur */ 1195c595c433SHoratiu Vultur int (*port_mrp_add)(struct dsa_switch *ds, int port, 1196c595c433SHoratiu Vultur const struct switchdev_obj_mrp *mrp); 1197c595c433SHoratiu Vultur int (*port_mrp_del)(struct dsa_switch *ds, int port, 1198c595c433SHoratiu Vultur const struct switchdev_obj_mrp *mrp); 1199c595c433SHoratiu Vultur int (*port_mrp_add_ring_role)(struct dsa_switch *ds, int port, 1200c595c433SHoratiu Vultur const struct switchdev_obj_ring_role_mrp *mrp); 1201c595c433SHoratiu Vultur int (*port_mrp_del_ring_role)(struct dsa_switch *ds, int port, 1202c595c433SHoratiu Vultur const struct switchdev_obj_ring_role_mrp *mrp); 12035da11eb4SVladimir Oltean 12045da11eb4SVladimir Oltean /* 12055da11eb4SVladimir Oltean * tag_8021q operations 12065da11eb4SVladimir Oltean */ 12075da11eb4SVladimir Oltean int (*tag_8021q_vlan_add)(struct dsa_switch *ds, int port, u16 vid, 12085da11eb4SVladimir Oltean u16 flags); 12095da11eb4SVladimir Oltean int (*tag_8021q_vlan_del)(struct dsa_switch *ds, int port, u16 vid); 1210295ab96fSVladimir Oltean 1211295ab96fSVladimir Oltean /* 1212295ab96fSVladimir Oltean * DSA master tracking operations 1213295ab96fSVladimir Oltean */ 1214295ab96fSVladimir Oltean void (*master_state_change)(struct dsa_switch *ds, 1215295ab96fSVladimir Oltean const struct net_device *master, 1216295ab96fSVladimir Oltean bool operational); 12176b297524SAndrew Lunn }; 12186b297524SAndrew Lunn 12196b297524SAndrew Lunn #define DSA_DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes) \ 12206b297524SAndrew Lunn DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, \ 12216b297524SAndrew Lunn dsa_devlink_param_get, dsa_devlink_param_set, NULL) 12226b297524SAndrew Lunn 12236b297524SAndrew Lunn int dsa_devlink_param_get(struct devlink *dl, u32 id, 12246b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx); 12256b297524SAndrew Lunn int dsa_devlink_param_set(struct devlink *dl, u32 id, 12266b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx); 12276b297524SAndrew Lunn int dsa_devlink_params_register(struct dsa_switch *ds, 12286b297524SAndrew Lunn const struct devlink_param *params, 12296b297524SAndrew Lunn size_t params_count); 12306b297524SAndrew Lunn void dsa_devlink_params_unregister(struct dsa_switch *ds, 12316b297524SAndrew Lunn const struct devlink_param *params, 12326b297524SAndrew Lunn size_t params_count); 12335cd73fbdSAndrew Lunn int dsa_devlink_resource_register(struct dsa_switch *ds, 12345cd73fbdSAndrew Lunn const char *resource_name, 12355cd73fbdSAndrew Lunn u64 resource_size, 12365cd73fbdSAndrew Lunn u64 resource_id, 12375cd73fbdSAndrew Lunn u64 parent_resource_id, 12385cd73fbdSAndrew Lunn const struct devlink_resource_size_params *size_params); 12395cd73fbdSAndrew Lunn 12405cd73fbdSAndrew Lunn void dsa_devlink_resources_unregister(struct dsa_switch *ds); 12415cd73fbdSAndrew Lunn 12425cd73fbdSAndrew Lunn void dsa_devlink_resource_occ_get_register(struct dsa_switch *ds, 12435cd73fbdSAndrew Lunn u64 resource_id, 12445cd73fbdSAndrew Lunn devlink_resource_occ_get_t *occ_get, 12455cd73fbdSAndrew Lunn void *occ_get_priv); 12465cd73fbdSAndrew Lunn void dsa_devlink_resource_occ_get_unregister(struct dsa_switch *ds, 12475cd73fbdSAndrew Lunn u64 resource_id); 124897c82c23SAndrew Lunn struct devlink_region * 124997c82c23SAndrew Lunn dsa_devlink_region_create(struct dsa_switch *ds, 125097c82c23SAndrew Lunn const struct devlink_region_ops *ops, 125197c82c23SAndrew Lunn u32 region_max_snapshots, u64 region_size); 125208156ba4SAndrew Lunn struct devlink_region * 125308156ba4SAndrew Lunn dsa_devlink_port_region_create(struct dsa_switch *ds, 125408156ba4SAndrew Lunn int port, 125508156ba4SAndrew Lunn const struct devlink_port_region_ops *ops, 125608156ba4SAndrew Lunn u32 region_max_snapshots, u64 region_size); 125797c82c23SAndrew Lunn void dsa_devlink_region_destroy(struct devlink_region *region); 125897c82c23SAndrew Lunn 1259e1eea811SVladimir Oltean struct dsa_port *dsa_port_from_netdev(struct net_device *netdev); 12605cd73fbdSAndrew Lunn 12616b297524SAndrew Lunn struct dsa_devlink_priv { 12626b297524SAndrew Lunn struct dsa_switch *ds; 1263c8f0b869SBen Hutchings }; 1264c8f0b869SBen Hutchings 1265ccc3e6b0SAndrew Lunn static inline struct dsa_switch *dsa_devlink_to_ds(struct devlink *dl) 1266ccc3e6b0SAndrew Lunn { 1267ccc3e6b0SAndrew Lunn struct dsa_devlink_priv *dl_priv = devlink_priv(dl); 1268ccc3e6b0SAndrew Lunn 1269ccc3e6b0SAndrew Lunn return dl_priv->ds; 1270ccc3e6b0SAndrew Lunn } 1271ccc3e6b0SAndrew Lunn 12727d1e2a10SAndrew Lunn static inline 12737d1e2a10SAndrew Lunn struct dsa_switch *dsa_devlink_port_to_ds(struct devlink_port *port) 12747d1e2a10SAndrew Lunn { 12757d1e2a10SAndrew Lunn struct devlink *dl = port->devlink; 12767d1e2a10SAndrew Lunn struct dsa_devlink_priv *dl_priv = devlink_priv(dl); 12777d1e2a10SAndrew Lunn 12787d1e2a10SAndrew Lunn return dl_priv->ds; 12797d1e2a10SAndrew Lunn } 12807d1e2a10SAndrew Lunn 12817d1e2a10SAndrew Lunn static inline int dsa_devlink_port_to_port(struct devlink_port *port) 12827d1e2a10SAndrew Lunn { 12837d1e2a10SAndrew Lunn return port->index; 12847d1e2a10SAndrew Lunn } 12857d1e2a10SAndrew Lunn 1286ab3d408dSFlorian Fainelli struct dsa_switch_driver { 1287ab3d408dSFlorian Fainelli struct list_head list; 1288a82f67afSFlorian Fainelli const struct dsa_switch_ops *ops; 1289ab3d408dSFlorian Fainelli }; 1290ab3d408dSFlorian Fainelli 12917e580490SVladimir Oltean bool dsa_fdb_present_in_other_db(struct dsa_switch *ds, int port, 12927e580490SVladimir Oltean const unsigned char *addr, u16 vid, 12937e580490SVladimir Oltean struct dsa_db db); 12947e580490SVladimir Oltean bool dsa_mdb_present_in_other_db(struct dsa_switch *ds, int port, 12957e580490SVladimir Oltean const struct switchdev_obj_port_mdb *mdb, 12967e580490SVladimir Oltean struct dsa_db db); 1297f9cef64fSVladimir Oltean 129873a7ece8SVivien Didelot /* Keep inline for faster access in hot path */ 12999eb8eff0SVladimir Oltean static inline bool netdev_uses_dsa(const struct net_device *dev) 1300c6e970a0SAndrew Lunn { 1301c6e970a0SAndrew Lunn #if IS_ENABLED(CONFIG_NET_DSA) 1302717ffbfbSVivien Didelot return dev->dsa_ptr && dev->dsa_ptr->rcv; 1303c6e970a0SAndrew Lunn #endif 1304c6e970a0SAndrew Lunn return false; 1305c6e970a0SAndrew Lunn } 1306c6e970a0SAndrew Lunn 13079790cf20SVladimir Oltean /* All DSA tags that push the EtherType to the right (basically all except tail 13089790cf20SVladimir Oltean * tags, which don't break dissection) can be treated the same from the 13099790cf20SVladimir Oltean * perspective of the flow dissector. 13109790cf20SVladimir Oltean * 13119790cf20SVladimir Oltean * We need to return: 13129790cf20SVladimir Oltean * - offset: the (B - A) difference between: 13139790cf20SVladimir Oltean * A. the position of the real EtherType and 13149790cf20SVladimir Oltean * B. the current skb->data (aka ETH_HLEN bytes into the frame, aka 2 bytes 13159790cf20SVladimir Oltean * after the normal EtherType was supposed to be) 13169790cf20SVladimir Oltean * The offset in bytes is exactly equal to the tagger overhead (and half of 13179790cf20SVladimir Oltean * that, in __be16 shorts). 13189790cf20SVladimir Oltean * 13199790cf20SVladimir Oltean * - proto: the value of the real EtherType. 13209790cf20SVladimir Oltean */ 13219790cf20SVladimir Oltean static inline void dsa_tag_generic_flow_dissect(const struct sk_buff *skb, 13229790cf20SVladimir Oltean __be16 *proto, int *offset) 13239790cf20SVladimir Oltean { 13249790cf20SVladimir Oltean #if IS_ENABLED(CONFIG_NET_DSA) 13259790cf20SVladimir Oltean const struct dsa_device_ops *ops = skb->dev->dsa_ptr->tag_ops; 13264e500251SVladimir Oltean int tag_len = ops->needed_headroom; 13279790cf20SVladimir Oltean 13289790cf20SVladimir Oltean *offset = tag_len; 13299790cf20SVladimir Oltean *proto = ((__be16 *)skb->data)[(tag_len / 2) - 1]; 13309790cf20SVladimir Oltean #endif 13319790cf20SVladimir Oltean } 13329790cf20SVladimir Oltean 133383c0afaeSAndrew Lunn void dsa_unregister_switch(struct dsa_switch *ds); 133423c9ee49SVivien Didelot int dsa_register_switch(struct dsa_switch *ds); 13350650bf52SVladimir Oltean void dsa_switch_shutdown(struct dsa_switch *ds); 13363b7bc1f0SVladimir Oltean struct dsa_switch *dsa_switch_find(int tree_index, int sw_index); 1337a2614140SVladimir Oltean void dsa_flush_workqueue(void); 1338ea825e70SFlorian Fainelli #ifdef CONFIG_PM_SLEEP 1339ea825e70SFlorian Fainelli int dsa_switch_suspend(struct dsa_switch *ds); 1340ea825e70SFlorian Fainelli int dsa_switch_resume(struct dsa_switch *ds); 1341ea825e70SFlorian Fainelli #else 1342ea825e70SFlorian Fainelli static inline int dsa_switch_suspend(struct dsa_switch *ds) 1343ea825e70SFlorian Fainelli { 1344ea825e70SFlorian Fainelli return 0; 1345ea825e70SFlorian Fainelli } 1346ea825e70SFlorian Fainelli static inline int dsa_switch_resume(struct dsa_switch *ds) 1347ea825e70SFlorian Fainelli { 1348ea825e70SFlorian Fainelli return 0; 1349ea825e70SFlorian Fainelli } 1350ea825e70SFlorian Fainelli #endif /* CONFIG_PM_SLEEP */ 1351ea825e70SFlorian Fainelli 135260724d4bSFlorian Fainelli #if IS_ENABLED(CONFIG_NET_DSA) 1353a5e3c9baSVladimir Oltean bool dsa_slave_dev_check(const struct net_device *dev); 135460724d4bSFlorian Fainelli #else 1355a5e3c9baSVladimir Oltean static inline bool dsa_slave_dev_check(const struct net_device *dev) 1356a5e3c9baSVladimir Oltean { 1357a5e3c9baSVladimir Oltean return false; 1358a5e3c9baSVladimir Oltean } 135960724d4bSFlorian Fainelli #endif 136060724d4bSFlorian Fainelli 136197a69a0dSVladimir Oltean netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, struct net_device *dev); 136211d8f3ddSFlorian Fainelli void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up); 1363cf963573SFlorian Fainelli 136491da11f8SLennert Buytenhek #endif 1365