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 530b42f033SAndrew Lunn 54ac7a04c3SFlorian Fainelli enum dsa_tag_protocol { 550b42f033SAndrew Lunn DSA_TAG_PROTO_NONE = DSA_TAG_PROTO_NONE_VALUE, 560b42f033SAndrew Lunn DSA_TAG_PROTO_BRCM = DSA_TAG_PROTO_BRCM_VALUE, 57964dbf18SÁlvaro Fernández Rojas DSA_TAG_PROTO_BRCM_LEGACY = DSA_TAG_PROTO_BRCM_LEGACY_VALUE, 580b42f033SAndrew Lunn DSA_TAG_PROTO_BRCM_PREPEND = DSA_TAG_PROTO_BRCM_PREPEND_VALUE, 590b42f033SAndrew Lunn DSA_TAG_PROTO_DSA = DSA_TAG_PROTO_DSA_VALUE, 600b42f033SAndrew Lunn DSA_TAG_PROTO_EDSA = DSA_TAG_PROTO_EDSA_VALUE, 610b42f033SAndrew Lunn DSA_TAG_PROTO_GSWIP = DSA_TAG_PROTO_GSWIP_VALUE, 620b42f033SAndrew Lunn DSA_TAG_PROTO_KSZ9477 = DSA_TAG_PROTO_KSZ9477_VALUE, 630b42f033SAndrew Lunn DSA_TAG_PROTO_KSZ9893 = DSA_TAG_PROTO_KSZ9893_VALUE, 640b42f033SAndrew Lunn DSA_TAG_PROTO_LAN9303 = DSA_TAG_PROTO_LAN9303_VALUE, 650b42f033SAndrew Lunn DSA_TAG_PROTO_MTK = DSA_TAG_PROTO_MTK_VALUE, 660b42f033SAndrew Lunn DSA_TAG_PROTO_QCA = DSA_TAG_PROTO_QCA_VALUE, 670b42f033SAndrew Lunn DSA_TAG_PROTO_TRAILER = DSA_TAG_PROTO_TRAILER_VALUE, 68f9bbe447SVladimir Oltean DSA_TAG_PROTO_8021Q = DSA_TAG_PROTO_8021Q_VALUE, 69227d07a0SVladimir Oltean DSA_TAG_PROTO_SJA1105 = DSA_TAG_PROTO_SJA1105_VALUE, 70016e43a2STristram Ha DSA_TAG_PROTO_KSZ8795 = DSA_TAG_PROTO_KSZ8795_VALUE, 718dce89aaSVladimir Oltean DSA_TAG_PROTO_OCELOT = DSA_TAG_PROTO_OCELOT_VALUE, 7248fda74fSOleksij Rempel DSA_TAG_PROTO_AR9331 = DSA_TAG_PROTO_AR9331_VALUE, 73efd7fe68SLinus Walleij DSA_TAG_PROTO_RTL4_A = DSA_TAG_PROTO_RTL4_A_VALUE, 7401ef09caSKurt Kanzenbach DSA_TAG_PROTO_HELLCREEK = DSA_TAG_PROTO_HELLCREEK_VALUE, 7554a52823SGeorge McCollister DSA_TAG_PROTO_XRS700X = DSA_TAG_PROTO_XRS700X_VALUE, 767c83a7c5SVladimir Oltean DSA_TAG_PROTO_OCELOT_8021Q = DSA_TAG_PROTO_OCELOT_8021Q_VALUE, 777c4bb540SVladimir Oltean DSA_TAG_PROTO_SEVILLE = DSA_TAG_PROTO_SEVILLE_VALUE, 78ac7a04c3SFlorian Fainelli }; 795037d532SFlorian Fainelli 805075314eSAlexander Duyck struct packet_type; 8190af1059SBrandon Streiff struct dsa_switch; 823e8a72d1SFlorian Fainelli 8368277a2cSJohn Crispin struct dsa_device_ops { 8468277a2cSJohn Crispin struct sk_buff *(*xmit)(struct sk_buff *skb, struct net_device *dev); 8568277a2cSJohn Crispin struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev, 8689e49506SFlorian Westphal struct packet_type *pt); 872e8cb1b3SVladimir Oltean void (*flow_dissect)(const struct sk_buff *skb, __be16 *proto, 88598a9680SJohn Crispin int *offset); 89cc1939e4SVladimir Oltean /* Used to determine which traffic should match the DSA filter in 90cc1939e4SVladimir Oltean * eth_type_trans, and which, if any, should bypass it and be processed 91cc1939e4SVladimir Oltean * as regular on the master net device. 92cc1939e4SVladimir Oltean */ 93cc1939e4SVladimir Oltean bool (*filter)(const struct sk_buff *skb, struct net_device *dev); 94a5dd3087SAndrew Lunn unsigned int overhead; 95875138f8SAndrew Lunn const char *name; 96056eed2fSAndrew Lunn enum dsa_tag_protocol proto; 97c3975400SVladimir Oltean /* Some tagging protocols either mangle or shift the destination MAC 98c3975400SVladimir Oltean * address, in which case the DSA master would drop packets on ingress 99c3975400SVladimir Oltean * if what it understands out of the destination MAC address is not in 100c3975400SVladimir Oltean * its RX filter. 101c3975400SVladimir Oltean */ 102c3975400SVladimir Oltean bool promisc_on_master; 1037a6ffe76SVladimir Oltean bool tail_tag; 10468277a2cSJohn Crispin }; 10568277a2cSJohn Crispin 1064cfab356SFlorian Fainelli /* This structure defines the control interfaces that are overlayed by the 1074cfab356SFlorian Fainelli * DSA layer on top of the DSA CPU/management net_device instance. This is 1084cfab356SFlorian Fainelli * used by the core net_device layer while calling various net_device_ops 1094cfab356SFlorian Fainelli * function pointers. 1104cfab356SFlorian Fainelli */ 1114cfab356SFlorian Fainelli struct dsa_netdevice_ops { 1124cfab356SFlorian Fainelli int (*ndo_do_ioctl)(struct net_device *dev, struct ifreq *ifr, 1134cfab356SFlorian Fainelli int cmd); 1144cfab356SFlorian Fainelli }; 1154cfab356SFlorian Fainelli 1160b42f033SAndrew Lunn #define DSA_TAG_DRIVER_ALIAS "dsa_tag-" 1170b42f033SAndrew Lunn #define MODULE_ALIAS_DSA_TAG_DRIVER(__proto) \ 1180b42f033SAndrew Lunn MODULE_ALIAS(DSA_TAG_DRIVER_ALIAS __stringify(__proto##_VALUE)) 1190b42f033SAndrew Lunn 120b68b0dd0SVladimir Oltean struct dsa_skb_cb { 121b68b0dd0SVladimir Oltean struct sk_buff *clone; 122b68b0dd0SVladimir Oltean }; 123b68b0dd0SVladimir Oltean 124b68b0dd0SVladimir Oltean struct __dsa_skb_cb { 125b68b0dd0SVladimir Oltean struct dsa_skb_cb cb; 126b68b0dd0SVladimir Oltean u8 priv[48 - sizeof(struct dsa_skb_cb)]; 127b68b0dd0SVladimir Oltean }; 128b68b0dd0SVladimir Oltean 129b68b0dd0SVladimir Oltean #define DSA_SKB_CB(skb) ((struct dsa_skb_cb *)((skb)->cb)) 130b68b0dd0SVladimir Oltean 131b68b0dd0SVladimir Oltean #define DSA_SKB_CB_PRIV(skb) \ 132b68b0dd0SVladimir Oltean ((void *)(skb)->cb + offsetof(struct __dsa_skb_cb, priv)) 133b68b0dd0SVladimir Oltean 134cf50dcc2SBen Hutchings struct dsa_switch_tree { 13583c0afaeSAndrew Lunn struct list_head list; 13683c0afaeSAndrew Lunn 137f515f192SVivien Didelot /* Notifier chain for switch-wide events */ 138f515f192SVivien Didelot struct raw_notifier_head nh; 139f515f192SVivien Didelot 14083c0afaeSAndrew Lunn /* Tree identifier */ 14149463b7fSVivien Didelot unsigned int index; 14283c0afaeSAndrew Lunn 14383c0afaeSAndrew Lunn /* Number of switches attached to this tree */ 14483c0afaeSAndrew Lunn struct kref refcount; 14583c0afaeSAndrew Lunn 14683c0afaeSAndrew Lunn /* Has this tree been applied to the hardware? */ 147ec15dd42SVivien Didelot bool setup; 14883c0afaeSAndrew Lunn 149357f203bSVladimir Oltean /* Tagging protocol operations */ 150357f203bSVladimir Oltean const struct dsa_device_ops *tag_ops; 151357f203bSVladimir Oltean 152*deff7107STobias Waldekranz /* Default tagging protocol preferred by the switches in this 153*deff7107STobias Waldekranz * tree. 154*deff7107STobias Waldekranz */ 155*deff7107STobias Waldekranz enum dsa_tag_protocol default_proto; 156*deff7107STobias Waldekranz 157cf50dcc2SBen Hutchings /* 158cf50dcc2SBen Hutchings * Configuration data for the platform device that owns 159cf50dcc2SBen Hutchings * this dsa switch tree instance. 160cf50dcc2SBen Hutchings */ 161cf50dcc2SBen Hutchings struct dsa_platform_data *pd; 162cf85d08fSLennert Buytenhek 163ab8ccae1SVivien Didelot /* List of switch ports */ 164ab8ccae1SVivien Didelot struct list_head ports; 165ab8ccae1SVivien Didelot 166c5f51765SVivien Didelot /* List of DSA links composing the routing table */ 167c5f51765SVivien Didelot struct list_head rtable; 168058102a6STobias Waldekranz 169058102a6STobias Waldekranz /* Maps offloaded LAG netdevs to a zero-based linear ID for 170058102a6STobias Waldekranz * drivers that need it. 171058102a6STobias Waldekranz */ 172058102a6STobias Waldekranz struct net_device **lags; 173058102a6STobias Waldekranz unsigned int lags_len; 174cf50dcc2SBen Hutchings }; 175cf50dcc2SBen Hutchings 176058102a6STobias Waldekranz #define dsa_lags_foreach_id(_id, _dst) \ 177058102a6STobias Waldekranz for ((_id) = 0; (_id) < (_dst)->lags_len; (_id)++) \ 178058102a6STobias Waldekranz if ((_dst)->lags[(_id)]) 179058102a6STobias Waldekranz 180058102a6STobias Waldekranz #define dsa_lag_foreach_port(_dp, _dst, _lag) \ 181058102a6STobias Waldekranz list_for_each_entry((_dp), &(_dst)->ports, list) \ 182058102a6STobias Waldekranz if ((_dp)->lag_dev == (_lag)) 183058102a6STobias Waldekranz 18418596f50SGeorge McCollister #define dsa_hsr_foreach_port(_dp, _ds, _hsr) \ 18518596f50SGeorge McCollister list_for_each_entry((_dp), &(_ds)->dst->ports, list) \ 18618596f50SGeorge McCollister if ((_dp)->ds == (_ds) && (_dp)->hsr_dev == (_hsr)) 18718596f50SGeorge McCollister 188058102a6STobias Waldekranz static inline struct net_device *dsa_lag_dev(struct dsa_switch_tree *dst, 189058102a6STobias Waldekranz unsigned int id) 190058102a6STobias Waldekranz { 191058102a6STobias Waldekranz return dst->lags[id]; 192058102a6STobias Waldekranz } 193058102a6STobias Waldekranz 194058102a6STobias Waldekranz static inline int dsa_lag_id(struct dsa_switch_tree *dst, 195058102a6STobias Waldekranz struct net_device *lag) 196058102a6STobias Waldekranz { 197058102a6STobias Waldekranz unsigned int id; 198058102a6STobias Waldekranz 199058102a6STobias Waldekranz dsa_lags_foreach_id(id, dst) { 200058102a6STobias Waldekranz if (dsa_lag_dev(dst, id) == lag) 201058102a6STobias Waldekranz return id; 202058102a6STobias Waldekranz } 203058102a6STobias Waldekranz 204058102a6STobias Waldekranz return -ENODEV; 205058102a6STobias Waldekranz } 206058102a6STobias Waldekranz 20734297176SVladimir Oltean /* TC matchall action types */ 208f50f2127SFlorian Fainelli enum dsa_port_mall_action_type { 209f50f2127SFlorian Fainelli DSA_PORT_MALL_MIRROR, 21034297176SVladimir Oltean DSA_PORT_MALL_POLICER, 211f50f2127SFlorian Fainelli }; 212f50f2127SFlorian Fainelli 213f50f2127SFlorian Fainelli /* TC mirroring entry */ 214f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry { 215f50f2127SFlorian Fainelli u8 to_local_port; 216f50f2127SFlorian Fainelli bool ingress; 217f50f2127SFlorian Fainelli }; 218f50f2127SFlorian Fainelli 21934297176SVladimir Oltean /* TC port policer entry */ 22034297176SVladimir Oltean struct dsa_mall_policer_tc_entry { 2215f035af7SPo Liu u32 burst; 22234297176SVladimir Oltean u64 rate_bytes_per_sec; 22334297176SVladimir Oltean }; 22434297176SVladimir Oltean 225f50f2127SFlorian Fainelli /* TC matchall entry */ 226f50f2127SFlorian Fainelli struct dsa_mall_tc_entry { 227f50f2127SFlorian Fainelli struct list_head list; 228f50f2127SFlorian Fainelli unsigned long cookie; 229f50f2127SFlorian Fainelli enum dsa_port_mall_action_type type; 230f50f2127SFlorian Fainelli union { 231f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry mirror; 23234297176SVladimir Oltean struct dsa_mall_policer_tc_entry policer; 233f50f2127SFlorian Fainelli }; 234f50f2127SFlorian Fainelli }; 235f50f2127SFlorian Fainelli 236f50f2127SFlorian Fainelli 237c8b09808SAndrew Lunn struct dsa_port { 238f8b8b1cdSVivien Didelot /* A CPU port is physically connected to a master device. 239f8b8b1cdSVivien Didelot * A user port exposed to userspace has a slave device. 240f8b8b1cdSVivien Didelot */ 241f8b8b1cdSVivien Didelot union { 242f8b8b1cdSVivien Didelot struct net_device *master; 243f8b8b1cdSVivien Didelot struct net_device *slave; 244f8b8b1cdSVivien Didelot }; 245f8b8b1cdSVivien Didelot 246357f203bSVladimir Oltean /* Copy of the tagging protocol operations, for quicker access 247357f203bSVladimir Oltean * in the data path. Valid only for the CPU ports. 248357f203bSVladimir Oltean */ 24915240248SVivien Didelot const struct dsa_device_ops *tag_ops; 25015240248SVivien Didelot 2513e41f93bSVivien Didelot /* Copies for faster access in master receive hot path */ 2523e41f93bSVivien Didelot struct dsa_switch_tree *dst; 2533e41f93bSVivien Didelot struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev, 2543e41f93bSVivien Didelot struct packet_type *pt); 255cc1939e4SVladimir Oltean bool (*filter)(const struct sk_buff *skb, struct net_device *dev); 2563e41f93bSVivien Didelot 257057cad2cSVivien Didelot enum { 258057cad2cSVivien Didelot DSA_PORT_TYPE_UNUSED = 0, 259057cad2cSVivien Didelot DSA_PORT_TYPE_CPU, 260057cad2cSVivien Didelot DSA_PORT_TYPE_DSA, 261057cad2cSVivien Didelot DSA_PORT_TYPE_USER, 262057cad2cSVivien Didelot } type; 263057cad2cSVivien Didelot 264818be848SVivien Didelot struct dsa_switch *ds; 265818be848SVivien Didelot unsigned int index; 26671e0bbdeSFlorian Fainelli const char *name; 26768b2d4a8SVivien Didelot struct dsa_port *cpu_dp; 26883216e39SMichael Walle u8 mac[ETH_ALEN]; 269189b0d93SAndrew Lunn struct device_node *dn; 27034a79f63SVivien Didelot unsigned int ageing_time; 27133162e9aSVladimir Oltean bool vlan_filtering; 272732f794cSVivien Didelot u8 stp_state; 273a5e9a02eSVivien Didelot struct net_device *bridge_dev; 27496567d5dSAndrew Lunn struct devlink_port devlink_port; 2753122433eSAndrew Lunn bool devlink_port_setup; 276aab9c406SFlorian Fainelli struct phylink *pl; 27744cc27e4SIoana Ciornei struct phylink_config pl_config; 278058102a6STobias Waldekranz struct net_device *lag_dev; 279058102a6STobias Waldekranz bool lag_tx_enabled; 28018596f50SGeorge McCollister struct net_device *hsr_dev; 28197a69a0dSVladimir Oltean 282ab8ccae1SVivien Didelot struct list_head list; 283ab8ccae1SVivien Didelot 28467dbb9d4SFlorian Fainelli /* 285c362beb0SVladimir Oltean * Give the switch driver somewhere to hang its per-port private data 286c362beb0SVladimir Oltean * structures (accessible from the tagger). 287c362beb0SVladimir Oltean */ 288c362beb0SVladimir Oltean void *priv; 289c362beb0SVladimir Oltean 290c362beb0SVladimir Oltean /* 29167dbb9d4SFlorian Fainelli * Original copy of the master netdev ethtool_ops 29267dbb9d4SFlorian Fainelli */ 29367dbb9d4SFlorian Fainelli const struct ethtool_ops *orig_ethtool_ops; 294da7b9e9bSFlorian Fainelli 295da7b9e9bSFlorian Fainelli /* 296da7b9e9bSFlorian Fainelli * Original copy of the master netdev net_device_ops 297da7b9e9bSFlorian Fainelli */ 2984cfab356SFlorian Fainelli const struct dsa_netdevice_ops *netdev_ops; 299fb35c60cSVivien Didelot 300fb35c60cSVivien Didelot bool setup; 301c8b09808SAndrew Lunn }; 302c8b09808SAndrew Lunn 303c5f51765SVivien Didelot /* TODO: ideally DSA ports would have a single dp->link_dp member, 304c5f51765SVivien Didelot * and no dst->rtable nor this struct dsa_link would be needed, 305c5f51765SVivien Didelot * but this would require some more complex tree walking, 306c5f51765SVivien Didelot * so keep it stupid at the moment and list them all. 307c5f51765SVivien Didelot */ 308c5f51765SVivien Didelot struct dsa_link { 309c5f51765SVivien Didelot struct dsa_port *dp; 310c5f51765SVivien Didelot struct dsa_port *link_dp; 311c5f51765SVivien Didelot struct list_head list; 312c5f51765SVivien Didelot }; 313c5f51765SVivien Didelot 314c8f0b869SBen Hutchings struct dsa_switch { 315fb35c60cSVivien Didelot bool setup; 316fb35c60cSVivien Didelot 317c33063d6SAndrew Lunn struct device *dev; 318c33063d6SAndrew Lunn 319c8f0b869SBen Hutchings /* 320c8f0b869SBen Hutchings * Parent switch tree, and switch index. 321c8f0b869SBen Hutchings */ 322c8f0b869SBen Hutchings struct dsa_switch_tree *dst; 32399feaafcSVivien Didelot unsigned int index; 324c8f0b869SBen Hutchings 325f515f192SVivien Didelot /* Listener for switch fabric events */ 326f515f192SVivien Didelot struct notifier_block nb; 327f515f192SVivien Didelot 328c8f0b869SBen Hutchings /* 3297543a6d5SAndrew Lunn * Give the switch driver somewhere to hang its private data 3307543a6d5SAndrew Lunn * structure. 3317543a6d5SAndrew Lunn */ 3327543a6d5SAndrew Lunn void *priv; 3337543a6d5SAndrew Lunn 3347543a6d5SAndrew Lunn /* 335c8f0b869SBen Hutchings * Configuration data for this switch. 336c8f0b869SBen Hutchings */ 337ff04955cSAndrew Lunn struct dsa_chip_data *cd; 338c8f0b869SBen Hutchings 339c8f0b869SBen Hutchings /* 3409d490b4eSVivien Didelot * The switch operations. 341c8f0b869SBen Hutchings */ 342a82f67afSFlorian Fainelli const struct dsa_switch_ops *ops; 343c8f0b869SBen Hutchings 34466472fc0SAndrew Lunn /* 345c8f0b869SBen Hutchings * Slave mii_bus and devices for the individual ports. 346c8f0b869SBen Hutchings */ 3470d8bcdd3SFlorian Fainelli u32 phys_mii_mask; 348c8f0b869SBen Hutchings struct mii_bus *slave_mii_bus; 349a0c02161SVivien Didelot 3500f3da6afSVivien Didelot /* Ageing Time limits in msecs */ 3510f3da6afSVivien Didelot unsigned int ageing_time_min; 3520f3da6afSVivien Didelot unsigned int ageing_time_max; 3530f3da6afSVivien Didelot 35496567d5dSAndrew Lunn /* devlink used to represent this switch device */ 35596567d5dSAndrew Lunn struct devlink *devlink; 35696567d5dSAndrew Lunn 35755199df6SFlorian Fainelli /* Number of switch port queues */ 35855199df6SFlorian Fainelli unsigned int num_tx_queues; 35955199df6SFlorian Fainelli 3608f5d16f6SVladimir Oltean /* Disallow bridge core from requesting different VLAN awareness 3618f5d16f6SVladimir Oltean * settings on ports if not hardware-supported 3628f5d16f6SVladimir Oltean */ 3638f5d16f6SVladimir Oltean bool vlan_filtering_is_global; 3648f5d16f6SVladimir Oltean 36554a0ed0dSRussell King /* Pass .port_vlan_add and .port_vlan_del to drivers even for bridges 36654a0ed0dSRussell King * that have vlan_filtering=0. All drivers should ideally set this (and 36754a0ed0dSRussell King * then the option would get removed), but it is unknown whether this 36854a0ed0dSRussell King * would break things or not. 36954a0ed0dSRussell King */ 37054a0ed0dSRussell King bool configure_vlan_while_not_filtering; 37154a0ed0dSRussell King 3721dc0408cSFlorian Fainelli /* If the switch driver always programs the CPU port as egress tagged 3731dc0408cSFlorian Fainelli * despite the VLAN configuration indicating otherwise, then setting 3741dc0408cSFlorian Fainelli * @untag_bridge_pvid will force the DSA receive path to pop the bridge's 3751dc0408cSFlorian Fainelli * default_pvid VLAN tagged frames to offer a consistent behavior 3761dc0408cSFlorian Fainelli * between a vlan_filtering=0 and vlan_filtering=1 bridge device. 3771dc0408cSFlorian Fainelli */ 3781dc0408cSFlorian Fainelli bool untag_bridge_pvid; 3791dc0408cSFlorian Fainelli 380d5f19486SVladimir Oltean /* Let DSA manage the FDB entries towards the CPU, based on the 381d5f19486SVladimir Oltean * software bridge database. 382d5f19486SVladimir Oltean */ 383d5f19486SVladimir Oltean bool assisted_learning_on_cpu_port; 384d5f19486SVladimir Oltean 38514574676SVladimir Oltean /* In case vlan_filtering_is_global is set, the VLAN awareness state 38614574676SVladimir Oltean * should be retrieved from here and not from the per-port settings. 38714574676SVladimir Oltean */ 38814574676SVladimir Oltean bool vlan_filtering; 38914574676SVladimir Oltean 390787cac3fSVladimir Oltean /* MAC PCS does not provide link state change interrupt, and requires 391787cac3fSVladimir Oltean * polling. Flag passed on to PHYLINK. 392787cac3fSVladimir Oltean */ 393787cac3fSVladimir Oltean bool pcs_poll; 394787cac3fSVladimir Oltean 395bff33f7eSVladimir Oltean /* For switches that only have the MRU configurable. To ensure the 396bff33f7eSVladimir Oltean * configured MTU is not exceeded, normalization of MRU on all bridged 397bff33f7eSVladimir Oltean * interfaces is needed. 398bff33f7eSVladimir Oltean */ 399bff33f7eSVladimir Oltean bool mtu_enforcement_ingress; 400bff33f7eSVladimir Oltean 401058102a6STobias Waldekranz /* Drivers that benefit from having an ID associated with each 402058102a6STobias Waldekranz * offloaded LAG should set this to the maximum number of 403058102a6STobias Waldekranz * supported IDs. DSA will then maintain a mapping of _at 404058102a6STobias Waldekranz * least_ these many IDs, accessible to drivers via 405058102a6STobias Waldekranz * dsa_lag_id(). 406058102a6STobias Waldekranz */ 407058102a6STobias Waldekranz unsigned int num_lag_ids; 408058102a6STobias Waldekranz 409a0c02161SVivien Didelot size_t num_ports; 410c8f0b869SBen Hutchings }; 411c8f0b869SBen Hutchings 41268bb8ea8SVivien Didelot static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p) 413c38c5a66SVivien Didelot { 414b96ddf25SVivien Didelot struct dsa_switch_tree *dst = ds->dst; 415d607525bSVivien Didelot struct dsa_port *dp; 416b96ddf25SVivien Didelot 417b96ddf25SVivien Didelot list_for_each_entry(dp, &dst->ports, list) 418b96ddf25SVivien Didelot if (dp->ds == ds && dp->index == p) 419b96ddf25SVivien Didelot return dp; 420d607525bSVivien Didelot 421d607525bSVivien Didelot return NULL; 422c38c5a66SVivien Didelot } 423c38c5a66SVivien Didelot 424bff7b688SVivien Didelot static inline bool dsa_is_unused_port(struct dsa_switch *ds, int p) 425bff7b688SVivien Didelot { 426c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_UNUSED; 427bff7b688SVivien Didelot } 428bff7b688SVivien Didelot 429c8f0b869SBen Hutchings static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p) 430c8f0b869SBen Hutchings { 431c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_CPU; 432c8f0b869SBen Hutchings } 433c8f0b869SBen Hutchings 43460045cbfSAndrew Lunn static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p) 43560045cbfSAndrew Lunn { 436c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_DSA; 43760045cbfSAndrew Lunn } 43860045cbfSAndrew Lunn 4392b3e9891SVivien Didelot static inline bool dsa_is_user_port(struct dsa_switch *ds, int p) 4406cd456f3SVivien Didelot { 441c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_USER; 4426cd456f3SVivien Didelot } 4436cd456f3SVivien Didelot 44402bc6e54SVivien Didelot static inline u32 dsa_user_ports(struct dsa_switch *ds) 44502bc6e54SVivien Didelot { 446c38c5a66SVivien Didelot u32 mask = 0; 447c38c5a66SVivien Didelot int p; 44802bc6e54SVivien Didelot 449c38c5a66SVivien Didelot for (p = 0; p < ds->num_ports; p++) 450c38c5a66SVivien Didelot if (dsa_is_user_port(ds, p)) 451c38c5a66SVivien Didelot mask |= BIT(p); 452c38c5a66SVivien Didelot 453c38c5a66SVivien Didelot return mask; 454c8652c83SVivien Didelot } 455c8652c83SVivien Didelot 456c5f51765SVivien Didelot /* Return the local port used to reach an arbitrary switch device */ 457c5f51765SVivien Didelot static inline unsigned int dsa_routing_port(struct dsa_switch *ds, int device) 458c5f51765SVivien Didelot { 459c5f51765SVivien Didelot struct dsa_switch_tree *dst = ds->dst; 460c5f51765SVivien Didelot struct dsa_link *dl; 461c5f51765SVivien Didelot 462c5f51765SVivien Didelot list_for_each_entry(dl, &dst->rtable, list) 463c5f51765SVivien Didelot if (dl->dp->ds == ds && dl->link_dp->ds->index == device) 464c5f51765SVivien Didelot return dl->dp->index; 465c5f51765SVivien Didelot 466c5f51765SVivien Didelot return ds->num_ports; 467c5f51765SVivien Didelot } 468c5f51765SVivien Didelot 4693b8fac5dSVivien Didelot /* Return the local port used to reach an arbitrary switch port */ 4703b8fac5dSVivien Didelot static inline unsigned int dsa_towards_port(struct dsa_switch *ds, int device, 4713b8fac5dSVivien Didelot int port) 4723b8fac5dSVivien Didelot { 4733b8fac5dSVivien Didelot if (device == ds->index) 4743b8fac5dSVivien Didelot return port; 4753b8fac5dSVivien Didelot else 476c5f51765SVivien Didelot return dsa_routing_port(ds, device); 4773b8fac5dSVivien Didelot } 4783b8fac5dSVivien Didelot 4793b8fac5dSVivien Didelot /* Return the local port used to reach the dedicated CPU port */ 48007073c79SVivien Didelot static inline unsigned int dsa_upstream_port(struct dsa_switch *ds, int port) 481c8f0b869SBen Hutchings { 48207073c79SVivien Didelot const struct dsa_port *dp = dsa_to_port(ds, port); 48307073c79SVivien Didelot const struct dsa_port *cpu_dp = dp->cpu_dp; 48407073c79SVivien Didelot 48507073c79SVivien Didelot if (!cpu_dp) 48607073c79SVivien Didelot return port; 487c8f0b869SBen Hutchings 4883b8fac5dSVivien Didelot return dsa_towards_port(ds, cpu_dp->ds->index, cpu_dp->index); 489c8f0b869SBen Hutchings } 490c8f0b869SBen Hutchings 491cf2d45f5SVladimir Oltean static inline bool dsa_port_is_vlan_filtering(const struct dsa_port *dp) 492cf2d45f5SVladimir Oltean { 493cf2d45f5SVladimir Oltean const struct dsa_switch *ds = dp->ds; 494cf2d45f5SVladimir Oltean 495cf2d45f5SVladimir Oltean if (ds->vlan_filtering_is_global) 496cf2d45f5SVladimir Oltean return ds->vlan_filtering; 497cf2d45f5SVladimir Oltean else 498cf2d45f5SVladimir Oltean return dp->vlan_filtering; 499cf2d45f5SVladimir Oltean } 500cf2d45f5SVladimir Oltean 501cc76ce9eSTobias Waldekranz static inline 502cc76ce9eSTobias Waldekranz struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp) 503cc76ce9eSTobias Waldekranz { 504cc76ce9eSTobias Waldekranz if (!dp->bridge_dev) 505cc76ce9eSTobias Waldekranz return NULL; 506cc76ce9eSTobias Waldekranz 507cc76ce9eSTobias Waldekranz if (dp->lag_dev) 508cc76ce9eSTobias Waldekranz return dp->lag_dev; 509cc76ce9eSTobias Waldekranz else if (dp->hsr_dev) 510cc76ce9eSTobias Waldekranz return dp->hsr_dev; 511cc76ce9eSTobias Waldekranz 512cc76ce9eSTobias Waldekranz return dp->slave; 513cc76ce9eSTobias Waldekranz } 514cc76ce9eSTobias Waldekranz 5152bedde1aSArkadi Sharshevsky typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid, 5162bedde1aSArkadi Sharshevsky bool is_static, void *data); 5179d490b4eSVivien Didelot struct dsa_switch_ops { 51853da0ebaSVladimir Oltean /* 51953da0ebaSVladimir Oltean * Tagging protocol helpers called for the CPU ports and DSA links. 52053da0ebaSVladimir Oltean * @get_tag_protocol retrieves the initial tagging protocol and is 52153da0ebaSVladimir Oltean * mandatory. Switches which can operate using multiple tagging 52253da0ebaSVladimir Oltean * protocols should implement @change_tag_protocol and report in 52353da0ebaSVladimir Oltean * @get_tag_protocol the tagger in current use. 52453da0ebaSVladimir Oltean */ 5255ed4e3ebSFlorian Fainelli enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds, 5264d776482SFlorian Fainelli int port, 5274d776482SFlorian Fainelli enum dsa_tag_protocol mprot); 52853da0ebaSVladimir Oltean int (*change_tag_protocol)(struct dsa_switch *ds, int port, 52953da0ebaSVladimir Oltean enum dsa_tag_protocol proto); 5307b314362SAndrew Lunn 531c8f0b869SBen Hutchings int (*setup)(struct dsa_switch *ds); 5325e3f847aSVladimir Oltean void (*teardown)(struct dsa_switch *ds); 5336819563eSFlorian Fainelli u32 (*get_phy_flags)(struct dsa_switch *ds, int port); 534c8f0b869SBen Hutchings 535c8f0b869SBen Hutchings /* 536c8f0b869SBen Hutchings * Access to the switch's PHY registers. 537c8f0b869SBen Hutchings */ 538c8f0b869SBen Hutchings int (*phy_read)(struct dsa_switch *ds, int port, int regnum); 539c8f0b869SBen Hutchings int (*phy_write)(struct dsa_switch *ds, int port, 540c8f0b869SBen Hutchings int regnum, u16 val); 541c8f0b869SBen Hutchings 542c8f0b869SBen Hutchings /* 543ec9436baSFlorian Fainelli * Link state adjustment (called from libphy) 544ec9436baSFlorian Fainelli */ 545ec9436baSFlorian Fainelli void (*adjust_link)(struct dsa_switch *ds, int port, 546ec9436baSFlorian Fainelli struct phy_device *phydev); 547ce31b31cSFlorian Fainelli void (*fixed_link_update)(struct dsa_switch *ds, int port, 548ce31b31cSFlorian Fainelli struct fixed_phy_status *st); 549ec9436baSFlorian Fainelli 550ec9436baSFlorian Fainelli /* 55111d8f3ddSFlorian Fainelli * PHYLINK integration 55211d8f3ddSFlorian Fainelli */ 55311d8f3ddSFlorian Fainelli void (*phylink_validate)(struct dsa_switch *ds, int port, 55411d8f3ddSFlorian Fainelli unsigned long *supported, 55511d8f3ddSFlorian Fainelli struct phylink_link_state *state); 55611d8f3ddSFlorian Fainelli int (*phylink_mac_link_state)(struct dsa_switch *ds, int port, 55711d8f3ddSFlorian Fainelli struct phylink_link_state *state); 55811d8f3ddSFlorian Fainelli void (*phylink_mac_config)(struct dsa_switch *ds, int port, 55911d8f3ddSFlorian Fainelli unsigned int mode, 56011d8f3ddSFlorian Fainelli const struct phylink_link_state *state); 56111d8f3ddSFlorian Fainelli void (*phylink_mac_an_restart)(struct dsa_switch *ds, int port); 56211d8f3ddSFlorian Fainelli void (*phylink_mac_link_down)(struct dsa_switch *ds, int port, 56311d8f3ddSFlorian Fainelli unsigned int mode, 56411d8f3ddSFlorian Fainelli phy_interface_t interface); 56511d8f3ddSFlorian Fainelli void (*phylink_mac_link_up)(struct dsa_switch *ds, int port, 56611d8f3ddSFlorian Fainelli unsigned int mode, 56711d8f3ddSFlorian Fainelli phy_interface_t interface, 5685b502a7bSRussell King struct phy_device *phydev, 5695b502a7bSRussell King int speed, int duplex, 5705b502a7bSRussell King bool tx_pause, bool rx_pause); 57111d8f3ddSFlorian Fainelli void (*phylink_fixed_state)(struct dsa_switch *ds, int port, 57211d8f3ddSFlorian Fainelli struct phylink_link_state *state); 57311d8f3ddSFlorian Fainelli /* 574c2ec5f2eSOleksij Rempel * Port statistics counters. 575c8f0b869SBen Hutchings */ 57689f09048SFlorian Fainelli void (*get_strings)(struct dsa_switch *ds, int port, 57789f09048SFlorian Fainelli u32 stringset, uint8_t *data); 578c8f0b869SBen Hutchings void (*get_ethtool_stats)(struct dsa_switch *ds, 579c8f0b869SBen Hutchings int port, uint64_t *data); 58089f09048SFlorian Fainelli int (*get_sset_count)(struct dsa_switch *ds, int port, int sset); 581cf963573SFlorian Fainelli void (*get_ethtool_phy_stats)(struct dsa_switch *ds, 582cf963573SFlorian Fainelli int port, uint64_t *data); 583c2ec5f2eSOleksij Rempel void (*get_stats64)(struct dsa_switch *ds, int port, 584c2ec5f2eSOleksij Rempel struct rtnl_link_stats64 *s); 585a71acad9SOleksij Rempel void (*self_test)(struct dsa_switch *ds, int port, 586a71acad9SOleksij Rempel struct ethtool_test *etest, u64 *data); 58724462549SFlorian Fainelli 58824462549SFlorian Fainelli /* 58919e57c4eSFlorian Fainelli * ethtool Wake-on-LAN 59019e57c4eSFlorian Fainelli */ 59119e57c4eSFlorian Fainelli void (*get_wol)(struct dsa_switch *ds, int port, 59219e57c4eSFlorian Fainelli struct ethtool_wolinfo *w); 59319e57c4eSFlorian Fainelli int (*set_wol)(struct dsa_switch *ds, int port, 59419e57c4eSFlorian Fainelli struct ethtool_wolinfo *w); 59519e57c4eSFlorian Fainelli 59619e57c4eSFlorian Fainelli /* 5970336369dSBrandon Streiff * ethtool timestamp info 5980336369dSBrandon Streiff */ 5990336369dSBrandon Streiff int (*get_ts_info)(struct dsa_switch *ds, int port, 6000336369dSBrandon Streiff struct ethtool_ts_info *ts); 6010336369dSBrandon Streiff 6020336369dSBrandon Streiff /* 60324462549SFlorian Fainelli * Suspend and resume 60424462549SFlorian Fainelli */ 60524462549SFlorian Fainelli int (*suspend)(struct dsa_switch *ds); 60624462549SFlorian Fainelli int (*resume)(struct dsa_switch *ds); 607b2f2af21SFlorian Fainelli 608b2f2af21SFlorian Fainelli /* 609b2f2af21SFlorian Fainelli * Port enable/disable 610b2f2af21SFlorian Fainelli */ 611b2f2af21SFlorian Fainelli int (*port_enable)(struct dsa_switch *ds, int port, 612b2f2af21SFlorian Fainelli struct phy_device *phy); 61375104db0SAndrew Lunn void (*port_disable)(struct dsa_switch *ds, int port); 6147905288fSFlorian Fainelli 6157905288fSFlorian Fainelli /* 61608f50061SVivien Didelot * Port's MAC EEE settings 6177905288fSFlorian Fainelli */ 61808f50061SVivien Didelot int (*set_mac_eee)(struct dsa_switch *ds, int port, 6197905288fSFlorian Fainelli struct ethtool_eee *e); 62008f50061SVivien Didelot int (*get_mac_eee)(struct dsa_switch *ds, int port, 6217905288fSFlorian Fainelli struct ethtool_eee *e); 62251579c3fSGuenter Roeck 6236793abb4SGuenter Roeck /* EEPROM access */ 6246793abb4SGuenter Roeck int (*get_eeprom_len)(struct dsa_switch *ds); 6256793abb4SGuenter Roeck int (*get_eeprom)(struct dsa_switch *ds, 6266793abb4SGuenter Roeck struct ethtool_eeprom *eeprom, u8 *data); 6276793abb4SGuenter Roeck int (*set_eeprom)(struct dsa_switch *ds, 6286793abb4SGuenter Roeck struct ethtool_eeprom *eeprom, u8 *data); 6293d762a0fSGuenter Roeck 6303d762a0fSGuenter Roeck /* 6313d762a0fSGuenter Roeck * Register access. 6323d762a0fSGuenter Roeck */ 6333d762a0fSGuenter Roeck int (*get_regs_len)(struct dsa_switch *ds, int port); 6343d762a0fSGuenter Roeck void (*get_regs)(struct dsa_switch *ds, int port, 6353d762a0fSGuenter Roeck struct ethtool_regs *regs, void *p); 636b73adef6SFlorian Fainelli 637b73adef6SFlorian Fainelli /* 638e358bef7SVladimir Oltean * Upper device tracking. 639e358bef7SVladimir Oltean */ 640e358bef7SVladimir Oltean int (*port_prechangeupper)(struct dsa_switch *ds, int port, 641e358bef7SVladimir Oltean struct netdev_notifier_changeupper_info *info); 642e358bef7SVladimir Oltean 643e358bef7SVladimir Oltean /* 644b73adef6SFlorian Fainelli * Bridge integration 645b73adef6SFlorian Fainelli */ 64634a79f63SVivien Didelot int (*set_ageing_time)(struct dsa_switch *ds, unsigned int msecs); 64771327a4eSVivien Didelot int (*port_bridge_join)(struct dsa_switch *ds, int port, 648a6692754SVivien Didelot struct net_device *bridge); 649f123f2fbSVivien Didelot void (*port_bridge_leave)(struct dsa_switch *ds, int port, 650f123f2fbSVivien Didelot struct net_device *bridge); 65143c44a9fSVivien Didelot void (*port_stp_state_set)(struct dsa_switch *ds, int port, 652b73adef6SFlorian Fainelli u8 state); 653732f794cSVivien Didelot void (*port_fast_age)(struct dsa_switch *ds, int port); 654a8b659e7SVladimir Oltean int (*port_pre_bridge_flags)(struct dsa_switch *ds, int port, 655a8b659e7SVladimir Oltean struct switchdev_brport_flags flags, 656a8b659e7SVladimir Oltean struct netlink_ext_ack *extack); 657a8b659e7SVladimir Oltean int (*port_bridge_flags)(struct dsa_switch *ds, int port, 658a8b659e7SVladimir Oltean struct switchdev_brport_flags flags, 659a8b659e7SVladimir Oltean struct netlink_ext_ack *extack); 660a8b659e7SVladimir Oltean int (*port_set_mrouter)(struct dsa_switch *ds, int port, bool mrouter, 661a8b659e7SVladimir Oltean struct netlink_ext_ack *extack); 6622a778e1bSVivien Didelot 6632a778e1bSVivien Didelot /* 66411149536SVivien Didelot * VLAN support 66511149536SVivien Didelot */ 666fb2dabadSVivien Didelot int (*port_vlan_filtering)(struct dsa_switch *ds, int port, 66789153ed6SVladimir Oltean bool vlan_filtering, 66889153ed6SVladimir Oltean struct netlink_ext_ack *extack); 6691958d581SVladimir Oltean int (*port_vlan_add)(struct dsa_switch *ds, int port, 67031046a5fSVladimir Oltean const struct switchdev_obj_port_vlan *vlan, 67131046a5fSVladimir Oltean struct netlink_ext_ack *extack); 67276e398a6SVivien Didelot int (*port_vlan_del)(struct dsa_switch *ds, int port, 67376e398a6SVivien Didelot const struct switchdev_obj_port_vlan *vlan); 67411149536SVivien Didelot /* 6752a778e1bSVivien Didelot * Forwarding database 6762a778e1bSVivien Didelot */ 6771b6dd556SArkadi Sharshevsky int (*port_fdb_add)(struct dsa_switch *ds, int port, 6786c2c1dcbSArkadi Sharshevsky const unsigned char *addr, u16 vid); 6792a778e1bSVivien Didelot int (*port_fdb_del)(struct dsa_switch *ds, int port, 6806c2c1dcbSArkadi Sharshevsky const unsigned char *addr, u16 vid); 681ea70ba98SVivien Didelot int (*port_fdb_dump)(struct dsa_switch *ds, int port, 6822bedde1aSArkadi Sharshevsky dsa_fdb_dump_cb_t *cb, void *data); 6838df30255SVivien Didelot 6848df30255SVivien Didelot /* 6858df30255SVivien Didelot * Multicast database 6868df30255SVivien Didelot */ 687a52b2da7SVladimir Oltean int (*port_mdb_add)(struct dsa_switch *ds, int port, 6883709aadcSVivien Didelot const struct switchdev_obj_port_mdb *mdb); 6898df30255SVivien Didelot int (*port_mdb_del)(struct dsa_switch *ds, int port, 6908df30255SVivien Didelot const struct switchdev_obj_port_mdb *mdb); 691bf9f2648SFlorian Fainelli /* 692bf9f2648SFlorian Fainelli * RXNFC 693bf9f2648SFlorian Fainelli */ 694bf9f2648SFlorian Fainelli int (*get_rxnfc)(struct dsa_switch *ds, int port, 695bf9f2648SFlorian Fainelli struct ethtool_rxnfc *nfc, u32 *rule_locs); 696bf9f2648SFlorian Fainelli int (*set_rxnfc)(struct dsa_switch *ds, int port, 697bf9f2648SFlorian Fainelli struct ethtool_rxnfc *nfc); 698f50f2127SFlorian Fainelli 699f50f2127SFlorian Fainelli /* 700f50f2127SFlorian Fainelli * TC integration 701f50f2127SFlorian Fainelli */ 702ed11bb1fSVladimir Oltean int (*cls_flower_add)(struct dsa_switch *ds, int port, 703ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, bool ingress); 704ed11bb1fSVladimir Oltean int (*cls_flower_del)(struct dsa_switch *ds, int port, 705ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, bool ingress); 706ed11bb1fSVladimir Oltean int (*cls_flower_stats)(struct dsa_switch *ds, int port, 707ed11bb1fSVladimir Oltean struct flow_cls_offload *cls, bool ingress); 708f50f2127SFlorian Fainelli int (*port_mirror_add)(struct dsa_switch *ds, int port, 709f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror, 710f50f2127SFlorian Fainelli bool ingress); 711f50f2127SFlorian Fainelli void (*port_mirror_del)(struct dsa_switch *ds, int port, 712f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror); 71334297176SVladimir Oltean int (*port_policer_add)(struct dsa_switch *ds, int port, 71434297176SVladimir Oltean struct dsa_mall_policer_tc_entry *policer); 71534297176SVladimir Oltean void (*port_policer_del)(struct dsa_switch *ds, int port); 71647d23af2SVladimir Oltean int (*port_setup_tc)(struct dsa_switch *ds, int port, 71747d23af2SVladimir Oltean enum tc_setup_type type, void *type_data); 71840ef2c93SVivien Didelot 71940ef2c93SVivien Didelot /* 72040ef2c93SVivien Didelot * Cross-chip operations 72140ef2c93SVivien Didelot */ 722f66a6a69SVladimir Oltean int (*crosschip_bridge_join)(struct dsa_switch *ds, int tree_index, 723f66a6a69SVladimir Oltean int sw_index, int port, 724f66a6a69SVladimir Oltean struct net_device *br); 725f66a6a69SVladimir Oltean void (*crosschip_bridge_leave)(struct dsa_switch *ds, int tree_index, 726f66a6a69SVladimir Oltean int sw_index, int port, 727f66a6a69SVladimir Oltean struct net_device *br); 728058102a6STobias Waldekranz int (*crosschip_lag_change)(struct dsa_switch *ds, int sw_index, 729058102a6STobias Waldekranz int port); 730058102a6STobias Waldekranz int (*crosschip_lag_join)(struct dsa_switch *ds, int sw_index, 731058102a6STobias Waldekranz int port, struct net_device *lag, 732058102a6STobias Waldekranz struct netdev_lag_upper_info *info); 733058102a6STobias Waldekranz int (*crosschip_lag_leave)(struct dsa_switch *ds, int sw_index, 734058102a6STobias Waldekranz int port, struct net_device *lag); 7350336369dSBrandon Streiff 7360336369dSBrandon Streiff /* 7370336369dSBrandon Streiff * PTP functionality 7380336369dSBrandon Streiff */ 7390336369dSBrandon Streiff int (*port_hwtstamp_get)(struct dsa_switch *ds, int port, 7400336369dSBrandon Streiff struct ifreq *ifr); 7410336369dSBrandon Streiff int (*port_hwtstamp_set)(struct dsa_switch *ds, int port, 7420336369dSBrandon Streiff struct ifreq *ifr); 74390af1059SBrandon Streiff bool (*port_txtstamp)(struct dsa_switch *ds, int port, 74490af1059SBrandon Streiff struct sk_buff *clone, unsigned int type); 74590af1059SBrandon Streiff bool (*port_rxtstamp)(struct dsa_switch *ds, int port, 74690af1059SBrandon Streiff struct sk_buff *skb, unsigned int type); 74797a69a0dSVladimir Oltean 7480f06b855SAndrew Lunn /* Devlink parameters, etc */ 7496b297524SAndrew Lunn int (*devlink_param_get)(struct dsa_switch *ds, u32 id, 7506b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx); 7516b297524SAndrew Lunn int (*devlink_param_set)(struct dsa_switch *ds, u32 id, 7526b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx); 7530f06b855SAndrew Lunn int (*devlink_info_get)(struct dsa_switch *ds, 7540f06b855SAndrew Lunn struct devlink_info_req *req, 7550f06b855SAndrew Lunn struct netlink_ext_ack *extack); 7562a6ef763SVladimir Oltean int (*devlink_sb_pool_get)(struct dsa_switch *ds, 7572a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index, 7582a6ef763SVladimir Oltean struct devlink_sb_pool_info *pool_info); 7592a6ef763SVladimir Oltean int (*devlink_sb_pool_set)(struct dsa_switch *ds, unsigned int sb_index, 7602a6ef763SVladimir Oltean u16 pool_index, u32 size, 7612a6ef763SVladimir Oltean enum devlink_sb_threshold_type threshold_type, 7622a6ef763SVladimir Oltean struct netlink_ext_ack *extack); 7632a6ef763SVladimir Oltean int (*devlink_sb_port_pool_get)(struct dsa_switch *ds, int port, 7642a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index, 7652a6ef763SVladimir Oltean u32 *p_threshold); 7662a6ef763SVladimir Oltean int (*devlink_sb_port_pool_set)(struct dsa_switch *ds, int port, 7672a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index, 7682a6ef763SVladimir Oltean u32 threshold, 7692a6ef763SVladimir Oltean struct netlink_ext_ack *extack); 7702a6ef763SVladimir Oltean int (*devlink_sb_tc_pool_bind_get)(struct dsa_switch *ds, int port, 7712a6ef763SVladimir Oltean unsigned int sb_index, u16 tc_index, 7722a6ef763SVladimir Oltean enum devlink_sb_pool_type pool_type, 7732a6ef763SVladimir Oltean u16 *p_pool_index, u32 *p_threshold); 7742a6ef763SVladimir Oltean int (*devlink_sb_tc_pool_bind_set)(struct dsa_switch *ds, int port, 7752a6ef763SVladimir Oltean unsigned int sb_index, u16 tc_index, 7762a6ef763SVladimir Oltean enum devlink_sb_pool_type pool_type, 7772a6ef763SVladimir Oltean u16 pool_index, u32 threshold, 7782a6ef763SVladimir Oltean struct netlink_ext_ack *extack); 7792a6ef763SVladimir Oltean int (*devlink_sb_occ_snapshot)(struct dsa_switch *ds, 7802a6ef763SVladimir Oltean unsigned int sb_index); 7812a6ef763SVladimir Oltean int (*devlink_sb_occ_max_clear)(struct dsa_switch *ds, 7822a6ef763SVladimir Oltean unsigned int sb_index); 7832a6ef763SVladimir Oltean int (*devlink_sb_occ_port_pool_get)(struct dsa_switch *ds, int port, 7842a6ef763SVladimir Oltean unsigned int sb_index, u16 pool_index, 7852a6ef763SVladimir Oltean u32 *p_cur, u32 *p_max); 7862a6ef763SVladimir Oltean int (*devlink_sb_occ_tc_port_bind_get)(struct dsa_switch *ds, int port, 7872a6ef763SVladimir Oltean unsigned int sb_index, u16 tc_index, 7882a6ef763SVladimir Oltean enum devlink_sb_pool_type pool_type, 7892a6ef763SVladimir Oltean u32 *p_cur, u32 *p_max); 790bfcb8132SVladimir Oltean 791bfcb8132SVladimir Oltean /* 792bfcb8132SVladimir Oltean * MTU change functionality. Switches can also adjust their MRU through 793bfcb8132SVladimir Oltean * this method. By MTU, one understands the SDU (L2 payload) length. 794bfcb8132SVladimir Oltean * If the switch needs to account for the DSA tag on the CPU port, this 795ab88d64aSRandy Dunlap * method needs to do so privately. 796bfcb8132SVladimir Oltean */ 797bfcb8132SVladimir Oltean int (*port_change_mtu)(struct dsa_switch *ds, int port, 798bfcb8132SVladimir Oltean int new_mtu); 799bfcb8132SVladimir Oltean int (*port_max_mtu)(struct dsa_switch *ds, int port); 800058102a6STobias Waldekranz 801058102a6STobias Waldekranz /* 802058102a6STobias Waldekranz * LAG integration 803058102a6STobias Waldekranz */ 804058102a6STobias Waldekranz int (*port_lag_change)(struct dsa_switch *ds, int port); 805058102a6STobias Waldekranz int (*port_lag_join)(struct dsa_switch *ds, int port, 806058102a6STobias Waldekranz struct net_device *lag, 807058102a6STobias Waldekranz struct netdev_lag_upper_info *info); 808058102a6STobias Waldekranz int (*port_lag_leave)(struct dsa_switch *ds, int port, 809058102a6STobias Waldekranz struct net_device *lag); 81018596f50SGeorge McCollister 81118596f50SGeorge McCollister /* 81218596f50SGeorge McCollister * HSR integration 81318596f50SGeorge McCollister */ 81418596f50SGeorge McCollister int (*port_hsr_join)(struct dsa_switch *ds, int port, 81518596f50SGeorge McCollister struct net_device *hsr); 81618596f50SGeorge McCollister int (*port_hsr_leave)(struct dsa_switch *ds, int port, 81718596f50SGeorge McCollister struct net_device *hsr); 818c595c433SHoratiu Vultur 819c595c433SHoratiu Vultur /* 820c595c433SHoratiu Vultur * MRP integration 821c595c433SHoratiu Vultur */ 822c595c433SHoratiu Vultur int (*port_mrp_add)(struct dsa_switch *ds, int port, 823c595c433SHoratiu Vultur const struct switchdev_obj_mrp *mrp); 824c595c433SHoratiu Vultur int (*port_mrp_del)(struct dsa_switch *ds, int port, 825c595c433SHoratiu Vultur const struct switchdev_obj_mrp *mrp); 826c595c433SHoratiu Vultur int (*port_mrp_add_ring_role)(struct dsa_switch *ds, int port, 827c595c433SHoratiu Vultur const struct switchdev_obj_ring_role_mrp *mrp); 828c595c433SHoratiu Vultur int (*port_mrp_del_ring_role)(struct dsa_switch *ds, int port, 829c595c433SHoratiu Vultur const struct switchdev_obj_ring_role_mrp *mrp); 8306b297524SAndrew Lunn }; 8316b297524SAndrew Lunn 8326b297524SAndrew Lunn #define DSA_DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes) \ 8336b297524SAndrew Lunn DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, \ 8346b297524SAndrew Lunn dsa_devlink_param_get, dsa_devlink_param_set, NULL) 8356b297524SAndrew Lunn 8366b297524SAndrew Lunn int dsa_devlink_param_get(struct devlink *dl, u32 id, 8376b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx); 8386b297524SAndrew Lunn int dsa_devlink_param_set(struct devlink *dl, u32 id, 8396b297524SAndrew Lunn struct devlink_param_gset_ctx *ctx); 8406b297524SAndrew Lunn int dsa_devlink_params_register(struct dsa_switch *ds, 8416b297524SAndrew Lunn const struct devlink_param *params, 8426b297524SAndrew Lunn size_t params_count); 8436b297524SAndrew Lunn void dsa_devlink_params_unregister(struct dsa_switch *ds, 8446b297524SAndrew Lunn const struct devlink_param *params, 8456b297524SAndrew Lunn size_t params_count); 8465cd73fbdSAndrew Lunn int dsa_devlink_resource_register(struct dsa_switch *ds, 8475cd73fbdSAndrew Lunn const char *resource_name, 8485cd73fbdSAndrew Lunn u64 resource_size, 8495cd73fbdSAndrew Lunn u64 resource_id, 8505cd73fbdSAndrew Lunn u64 parent_resource_id, 8515cd73fbdSAndrew Lunn const struct devlink_resource_size_params *size_params); 8525cd73fbdSAndrew Lunn 8535cd73fbdSAndrew Lunn void dsa_devlink_resources_unregister(struct dsa_switch *ds); 8545cd73fbdSAndrew Lunn 8555cd73fbdSAndrew Lunn void dsa_devlink_resource_occ_get_register(struct dsa_switch *ds, 8565cd73fbdSAndrew Lunn u64 resource_id, 8575cd73fbdSAndrew Lunn devlink_resource_occ_get_t *occ_get, 8585cd73fbdSAndrew Lunn void *occ_get_priv); 8595cd73fbdSAndrew Lunn void dsa_devlink_resource_occ_get_unregister(struct dsa_switch *ds, 8605cd73fbdSAndrew Lunn u64 resource_id); 86197c82c23SAndrew Lunn struct devlink_region * 86297c82c23SAndrew Lunn dsa_devlink_region_create(struct dsa_switch *ds, 86397c82c23SAndrew Lunn const struct devlink_region_ops *ops, 86497c82c23SAndrew Lunn u32 region_max_snapshots, u64 region_size); 86508156ba4SAndrew Lunn struct devlink_region * 86608156ba4SAndrew Lunn dsa_devlink_port_region_create(struct dsa_switch *ds, 86708156ba4SAndrew Lunn int port, 86808156ba4SAndrew Lunn const struct devlink_port_region_ops *ops, 86908156ba4SAndrew Lunn u32 region_max_snapshots, u64 region_size); 87097c82c23SAndrew Lunn void dsa_devlink_region_destroy(struct devlink_region *region); 87197c82c23SAndrew Lunn 872e1eea811SVladimir Oltean struct dsa_port *dsa_port_from_netdev(struct net_device *netdev); 8735cd73fbdSAndrew Lunn 8746b297524SAndrew Lunn struct dsa_devlink_priv { 8756b297524SAndrew Lunn struct dsa_switch *ds; 876c8f0b869SBen Hutchings }; 877c8f0b869SBen Hutchings 878ccc3e6b0SAndrew Lunn static inline struct dsa_switch *dsa_devlink_to_ds(struct devlink *dl) 879ccc3e6b0SAndrew Lunn { 880ccc3e6b0SAndrew Lunn struct dsa_devlink_priv *dl_priv = devlink_priv(dl); 881ccc3e6b0SAndrew Lunn 882ccc3e6b0SAndrew Lunn return dl_priv->ds; 883ccc3e6b0SAndrew Lunn } 884ccc3e6b0SAndrew Lunn 8857d1e2a10SAndrew Lunn static inline 8867d1e2a10SAndrew Lunn struct dsa_switch *dsa_devlink_port_to_ds(struct devlink_port *port) 8877d1e2a10SAndrew Lunn { 8887d1e2a10SAndrew Lunn struct devlink *dl = port->devlink; 8897d1e2a10SAndrew Lunn struct dsa_devlink_priv *dl_priv = devlink_priv(dl); 8907d1e2a10SAndrew Lunn 8917d1e2a10SAndrew Lunn return dl_priv->ds; 8927d1e2a10SAndrew Lunn } 8937d1e2a10SAndrew Lunn 8947d1e2a10SAndrew Lunn static inline int dsa_devlink_port_to_port(struct devlink_port *port) 8957d1e2a10SAndrew Lunn { 8967d1e2a10SAndrew Lunn return port->index; 8977d1e2a10SAndrew Lunn } 8987d1e2a10SAndrew Lunn 899ab3d408dSFlorian Fainelli struct dsa_switch_driver { 900ab3d408dSFlorian Fainelli struct list_head list; 901a82f67afSFlorian Fainelli const struct dsa_switch_ops *ops; 902ab3d408dSFlorian Fainelli }; 903ab3d408dSFlorian Fainelli 90414b89f36SFlorian Fainelli struct net_device *dsa_dev_to_net_device(struct device *dev); 905c8f0b869SBen Hutchings 90673a7ece8SVivien Didelot /* Keep inline for faster access in hot path */ 9079eb8eff0SVladimir Oltean static inline bool netdev_uses_dsa(const struct net_device *dev) 908c6e970a0SAndrew Lunn { 909c6e970a0SAndrew Lunn #if IS_ENABLED(CONFIG_NET_DSA) 910717ffbfbSVivien Didelot return dev->dsa_ptr && dev->dsa_ptr->rcv; 911c6e970a0SAndrew Lunn #endif 912c6e970a0SAndrew Lunn return false; 913c6e970a0SAndrew Lunn } 914c6e970a0SAndrew Lunn 915cc1939e4SVladimir Oltean static inline bool dsa_can_decode(const struct sk_buff *skb, 916cc1939e4SVladimir Oltean struct net_device *dev) 917cc1939e4SVladimir Oltean { 918cc1939e4SVladimir Oltean #if IS_ENABLED(CONFIG_NET_DSA) 919cc1939e4SVladimir Oltean return !dev->dsa_ptr->filter || dev->dsa_ptr->filter(skb, dev); 920cc1939e4SVladimir Oltean #endif 921cc1939e4SVladimir Oltean return false; 922cc1939e4SVladimir Oltean } 923cc1939e4SVladimir Oltean 9249790cf20SVladimir Oltean /* All DSA tags that push the EtherType to the right (basically all except tail 9259790cf20SVladimir Oltean * tags, which don't break dissection) can be treated the same from the 9269790cf20SVladimir Oltean * perspective of the flow dissector. 9279790cf20SVladimir Oltean * 9289790cf20SVladimir Oltean * We need to return: 9299790cf20SVladimir Oltean * - offset: the (B - A) difference between: 9309790cf20SVladimir Oltean * A. the position of the real EtherType and 9319790cf20SVladimir Oltean * B. the current skb->data (aka ETH_HLEN bytes into the frame, aka 2 bytes 9329790cf20SVladimir Oltean * after the normal EtherType was supposed to be) 9339790cf20SVladimir Oltean * The offset in bytes is exactly equal to the tagger overhead (and half of 9349790cf20SVladimir Oltean * that, in __be16 shorts). 9359790cf20SVladimir Oltean * 9369790cf20SVladimir Oltean * - proto: the value of the real EtherType. 9379790cf20SVladimir Oltean */ 9389790cf20SVladimir Oltean static inline void dsa_tag_generic_flow_dissect(const struct sk_buff *skb, 9399790cf20SVladimir Oltean __be16 *proto, int *offset) 9409790cf20SVladimir Oltean { 9419790cf20SVladimir Oltean #if IS_ENABLED(CONFIG_NET_DSA) 9429790cf20SVladimir Oltean const struct dsa_device_ops *ops = skb->dev->dsa_ptr->tag_ops; 9439790cf20SVladimir Oltean int tag_len = ops->overhead; 9449790cf20SVladimir Oltean 9459790cf20SVladimir Oltean *offset = tag_len; 9469790cf20SVladimir Oltean *proto = ((__be16 *)skb->data)[(tag_len / 2) - 1]; 9479790cf20SVladimir Oltean #endif 9489790cf20SVladimir Oltean } 9499790cf20SVladimir Oltean 9504cfab356SFlorian Fainelli #if IS_ENABLED(CONFIG_NET_DSA) 9514cfab356SFlorian Fainelli static inline int __dsa_netdevice_ops_check(struct net_device *dev) 9524cfab356SFlorian Fainelli { 9534cfab356SFlorian Fainelli int err = -EOPNOTSUPP; 9544cfab356SFlorian Fainelli 9554cfab356SFlorian Fainelli if (!dev->dsa_ptr) 9564cfab356SFlorian Fainelli return err; 9574cfab356SFlorian Fainelli 9584cfab356SFlorian Fainelli if (!dev->dsa_ptr->netdev_ops) 9594cfab356SFlorian Fainelli return err; 9604cfab356SFlorian Fainelli 9614cfab356SFlorian Fainelli return 0; 9624cfab356SFlorian Fainelli } 9634cfab356SFlorian Fainelli 9644cfab356SFlorian Fainelli static inline int dsa_ndo_do_ioctl(struct net_device *dev, struct ifreq *ifr, 9654cfab356SFlorian Fainelli int cmd) 9664cfab356SFlorian Fainelli { 9674cfab356SFlorian Fainelli const struct dsa_netdevice_ops *ops; 9684cfab356SFlorian Fainelli int err; 9694cfab356SFlorian Fainelli 9704cfab356SFlorian Fainelli err = __dsa_netdevice_ops_check(dev); 9714cfab356SFlorian Fainelli if (err) 9724cfab356SFlorian Fainelli return err; 9734cfab356SFlorian Fainelli 9744cfab356SFlorian Fainelli ops = dev->dsa_ptr->netdev_ops; 9754cfab356SFlorian Fainelli 9764cfab356SFlorian Fainelli return ops->ndo_do_ioctl(dev, ifr, cmd); 9774cfab356SFlorian Fainelli } 9784cfab356SFlorian Fainelli #else 9794cfab356SFlorian Fainelli static inline int dsa_ndo_do_ioctl(struct net_device *dev, struct ifreq *ifr, 9804cfab356SFlorian Fainelli int cmd) 9814cfab356SFlorian Fainelli { 9824cfab356SFlorian Fainelli return -EOPNOTSUPP; 9834cfab356SFlorian Fainelli } 9844cfab356SFlorian Fainelli #endif 9854cfab356SFlorian Fainelli 98683c0afaeSAndrew Lunn void dsa_unregister_switch(struct dsa_switch *ds); 98723c9ee49SVivien Didelot int dsa_register_switch(struct dsa_switch *ds); 9883b7bc1f0SVladimir Oltean struct dsa_switch *dsa_switch_find(int tree_index, int sw_index); 989ea825e70SFlorian Fainelli #ifdef CONFIG_PM_SLEEP 990ea825e70SFlorian Fainelli int dsa_switch_suspend(struct dsa_switch *ds); 991ea825e70SFlorian Fainelli int dsa_switch_resume(struct dsa_switch *ds); 992ea825e70SFlorian Fainelli #else 993ea825e70SFlorian Fainelli static inline int dsa_switch_suspend(struct dsa_switch *ds) 994ea825e70SFlorian Fainelli { 995ea825e70SFlorian Fainelli return 0; 996ea825e70SFlorian Fainelli } 997ea825e70SFlorian Fainelli static inline int dsa_switch_resume(struct dsa_switch *ds) 998ea825e70SFlorian Fainelli { 999ea825e70SFlorian Fainelli return 0; 1000ea825e70SFlorian Fainelli } 1001ea825e70SFlorian Fainelli #endif /* CONFIG_PM_SLEEP */ 1002ea825e70SFlorian Fainelli 100360724d4bSFlorian Fainelli #if IS_ENABLED(CONFIG_NET_DSA) 1004a5e3c9baSVladimir Oltean bool dsa_slave_dev_check(const struct net_device *dev); 100560724d4bSFlorian Fainelli #else 1006a5e3c9baSVladimir Oltean static inline bool dsa_slave_dev_check(const struct net_device *dev) 1007a5e3c9baSVladimir Oltean { 1008a5e3c9baSVladimir Oltean return false; 1009a5e3c9baSVladimir Oltean } 101060724d4bSFlorian Fainelli #endif 101160724d4bSFlorian Fainelli 101297a69a0dSVladimir Oltean netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, struct net_device *dev); 1013cf963573SFlorian Fainelli int dsa_port_get_phy_strings(struct dsa_port *dp, uint8_t *data); 1014cf963573SFlorian Fainelli int dsa_port_get_ethtool_phy_stats(struct dsa_port *dp, uint64_t *data); 1015cf963573SFlorian Fainelli int dsa_port_get_phy_sset_count(struct dsa_port *dp); 101611d8f3ddSFlorian Fainelli void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up); 1017cf963573SFlorian Fainelli 1018d3b8c049SAndrew Lunn struct dsa_tag_driver { 1019d3b8c049SAndrew Lunn const struct dsa_device_ops *ops; 1020d3b8c049SAndrew Lunn struct list_head list; 1021d3b8c049SAndrew Lunn struct module *owner; 1022d3b8c049SAndrew Lunn }; 1023d3b8c049SAndrew Lunn 1024d3b8c049SAndrew Lunn void dsa_tag_drivers_register(struct dsa_tag_driver *dsa_tag_driver_array[], 1025d3b8c049SAndrew Lunn unsigned int count, 1026d3b8c049SAndrew Lunn struct module *owner); 1027d3b8c049SAndrew Lunn void dsa_tag_drivers_unregister(struct dsa_tag_driver *dsa_tag_driver_array[], 1028d3b8c049SAndrew Lunn unsigned int count); 1029d3b8c049SAndrew Lunn 1030d3b8c049SAndrew Lunn #define dsa_tag_driver_module_drivers(__dsa_tag_drivers_array, __count) \ 1031d3b8c049SAndrew Lunn static int __init dsa_tag_driver_module_init(void) \ 1032d3b8c049SAndrew Lunn { \ 1033d3b8c049SAndrew Lunn dsa_tag_drivers_register(__dsa_tag_drivers_array, __count, \ 1034d3b8c049SAndrew Lunn THIS_MODULE); \ 1035d3b8c049SAndrew Lunn return 0; \ 1036d3b8c049SAndrew Lunn } \ 1037d3b8c049SAndrew Lunn module_init(dsa_tag_driver_module_init); \ 1038d3b8c049SAndrew Lunn \ 1039d3b8c049SAndrew Lunn static void __exit dsa_tag_driver_module_exit(void) \ 1040d3b8c049SAndrew Lunn { \ 1041d3b8c049SAndrew Lunn dsa_tag_drivers_unregister(__dsa_tag_drivers_array, __count); \ 1042d3b8c049SAndrew Lunn } \ 1043d3b8c049SAndrew Lunn module_exit(dsa_tag_driver_module_exit) 1044d3b8c049SAndrew Lunn 1045d3b8c049SAndrew Lunn /** 1046d3b8c049SAndrew Lunn * module_dsa_tag_drivers() - Helper macro for registering DSA tag 1047d3b8c049SAndrew Lunn * drivers 1048d3b8c049SAndrew Lunn * @__ops_array: Array of tag driver strucutres 1049d3b8c049SAndrew Lunn * 1050d3b8c049SAndrew Lunn * Helper macro for DSA tag drivers which do not do anything special 1051d3b8c049SAndrew Lunn * in module init/exit. Each module may only use this macro once, and 1052d3b8c049SAndrew Lunn * calling it replaces module_init() and module_exit(). 1053d3b8c049SAndrew Lunn */ 1054d3b8c049SAndrew Lunn #define module_dsa_tag_drivers(__ops_array) \ 1055d3b8c049SAndrew Lunn dsa_tag_driver_module_drivers(__ops_array, ARRAY_SIZE(__ops_array)) 1056d3b8c049SAndrew Lunn 1057d3b8c049SAndrew Lunn #define DSA_TAG_DRIVER_NAME(__ops) dsa_tag_driver ## _ ## __ops 1058d3b8c049SAndrew Lunn 1059d3b8c049SAndrew Lunn /* Create a static structure we can build a linked list of dsa_tag 1060d3b8c049SAndrew Lunn * drivers 1061d3b8c049SAndrew Lunn */ 1062d3b8c049SAndrew Lunn #define DSA_TAG_DRIVER(__ops) \ 1063d3b8c049SAndrew Lunn static struct dsa_tag_driver DSA_TAG_DRIVER_NAME(__ops) = { \ 1064d3b8c049SAndrew Lunn .ops = &__ops, \ 1065d3b8c049SAndrew Lunn } 1066d3b8c049SAndrew Lunn 1067d3b8c049SAndrew Lunn /** 1068d3b8c049SAndrew Lunn * module_dsa_tag_driver() - Helper macro for registering a single DSA tag 1069d3b8c049SAndrew Lunn * driver 1070d3b8c049SAndrew Lunn * @__ops: Single tag driver structures 1071d3b8c049SAndrew Lunn * 1072d3b8c049SAndrew Lunn * Helper macro for DSA tag drivers which do not do anything special 1073d3b8c049SAndrew Lunn * in module init/exit. Each module may only use this macro once, and 1074d3b8c049SAndrew Lunn * calling it replaces module_init() and module_exit(). 1075d3b8c049SAndrew Lunn */ 1076d3b8c049SAndrew Lunn #define module_dsa_tag_driver(__ops) \ 1077d3b8c049SAndrew Lunn DSA_TAG_DRIVER(__ops); \ 1078d3b8c049SAndrew Lunn \ 1079d3b8c049SAndrew Lunn static struct dsa_tag_driver *dsa_tag_driver_array[] = { \ 1080d3b8c049SAndrew Lunn &DSA_TAG_DRIVER_NAME(__ops) \ 1081d3b8c049SAndrew Lunn }; \ 1082d3b8c049SAndrew Lunn module_dsa_tag_drivers(dsa_tag_driver_array) 108391da11f8SLennert Buytenhek #endif 1084d3b8c049SAndrew Lunn 1085