191da11f8SLennert Buytenhek /* 291da11f8SLennert Buytenhek * include/net/dsa.h - Driver for Distributed Switch Architecture switch chips 3e84665c9SLennert Buytenhek * Copyright (c) 2008-2009 Marvell Semiconductor 491da11f8SLennert Buytenhek * 591da11f8SLennert Buytenhek * This program is free software; you can redistribute it and/or modify 691da11f8SLennert Buytenhek * it under the terms of the GNU General Public License as published by 791da11f8SLennert Buytenhek * the Free Software Foundation; either version 2 of the License, or 891da11f8SLennert Buytenhek * (at your option) any later version. 991da11f8SLennert Buytenhek */ 1091da11f8SLennert Buytenhek 1191da11f8SLennert Buytenhek #ifndef __LINUX_NET_DSA_H 1291da11f8SLennert Buytenhek #define __LINUX_NET_DSA_H 1391da11f8SLennert Buytenhek 144d56a29fSRussell King #include <linux/if.h> 15ea1f51beSAxel Lin #include <linux/if_ether.h> 16c8f0b869SBen Hutchings #include <linux/list.h> 17f515f192SVivien Didelot #include <linux/notifier.h> 18cf50dcc2SBen Hutchings #include <linux/timer.h> 19cf50dcc2SBen Hutchings #include <linux/workqueue.h> 20fa981d9aSFlorian Fainelli #include <linux/of.h> 21a2820543SFlorian Fainelli #include <linux/ethtool.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; 28f50f2127SFlorian Fainelli 29ac7a04c3SFlorian Fainelli enum dsa_tag_protocol { 30ac7a04c3SFlorian Fainelli DSA_TAG_PROTO_NONE = 0, 31ac7a04c3SFlorian Fainelli DSA_TAG_PROTO_BRCM, 32eb7b7211SAndrew Lunn DSA_TAG_PROTO_DSA, 33eb7b7211SAndrew Lunn DSA_TAG_PROTO_EDSA, 348b8010fbSWoojung Huh DSA_TAG_PROTO_KSZ, 35e8fe177aSJuergen Beisert DSA_TAG_PROTO_LAN9303, 36eb7b7211SAndrew Lunn DSA_TAG_PROTO_MTK, 37eb7b7211SAndrew Lunn DSA_TAG_PROTO_QCA, 38eb7b7211SAndrew Lunn DSA_TAG_PROTO_TRAILER, 3939a7f2a4SAndrew Lunn DSA_TAG_LAST, /* MUST BE LAST */ 40ac7a04c3SFlorian Fainelli }; 415037d532SFlorian Fainelli 42e84665c9SLennert Buytenhek #define DSA_MAX_SWITCHES 4 4391da11f8SLennert Buytenhek #define DSA_MAX_PORTS 12 4491da11f8SLennert Buytenhek 45d390238cSVivien Didelot #define DSA_RTABLE_NONE -1 46d390238cSVivien Didelot 47e84665c9SLennert Buytenhek struct dsa_chip_data { 48e84665c9SLennert Buytenhek /* 49e84665c9SLennert Buytenhek * How to access the switch configuration registers. 50e84665c9SLennert Buytenhek */ 51b4d2394dSAlexander Duyck struct device *host_dev; 52e84665c9SLennert Buytenhek int sw_addr; 53e84665c9SLennert Buytenhek 5471e0bbdeSFlorian Fainelli /* 5571e0bbdeSFlorian Fainelli * Reference to network devices 5671e0bbdeSFlorian Fainelli */ 5771e0bbdeSFlorian Fainelli struct device *netdev[DSA_MAX_PORTS]; 5871e0bbdeSFlorian Fainelli 596793abb4SGuenter Roeck /* set to size of eeprom if supported by the switch */ 606793abb4SGuenter Roeck int eeprom_len; 616793abb4SGuenter Roeck 62fa981d9aSFlorian Fainelli /* Device tree node pointer for this specific switch chip 63fa981d9aSFlorian Fainelli * used during switch setup in case additional properties 64fa981d9aSFlorian Fainelli * and resources needs to be used 65fa981d9aSFlorian Fainelli */ 66fa981d9aSFlorian Fainelli struct device_node *of_node; 67fa981d9aSFlorian Fainelli 68e84665c9SLennert Buytenhek /* 69e84665c9SLennert Buytenhek * The names of the switch's ports. Use "cpu" to 70e84665c9SLennert Buytenhek * designate the switch port that the cpu is connected to, 71e84665c9SLennert Buytenhek * "dsa" to indicate that this port is a DSA link to 72e84665c9SLennert Buytenhek * another switch, NULL to indicate the port is unused, 73e84665c9SLennert Buytenhek * or any other string to indicate this is a physical port. 74e84665c9SLennert Buytenhek */ 75e84665c9SLennert Buytenhek char *port_names[DSA_MAX_PORTS]; 76bd47497aSFlorian Fainelli struct device_node *port_dn[DSA_MAX_PORTS]; 77e84665c9SLennert Buytenhek 78e84665c9SLennert Buytenhek /* 794a7704ffSAndrew Lunn * An array of which element [a] indicates which port on this 804a7704ffSAndrew Lunn * switch should be used to send packets to that are destined 814a7704ffSAndrew Lunn * for switch a. Can be NULL if there is only one switch chip. 82e84665c9SLennert Buytenhek */ 834a7704ffSAndrew Lunn s8 rtable[DSA_MAX_SWITCHES]; 84e84665c9SLennert Buytenhek }; 85e84665c9SLennert Buytenhek 8691da11f8SLennert Buytenhek struct dsa_platform_data { 8791da11f8SLennert Buytenhek /* 8891da11f8SLennert Buytenhek * Reference to a Linux network interface that connects 89e84665c9SLennert Buytenhek * to the root switch chip of the tree. 9091da11f8SLennert Buytenhek */ 9191da11f8SLennert Buytenhek struct device *netdev; 92769a0202SFlorian Fainelli struct net_device *of_netdev; 9391da11f8SLennert Buytenhek 9491da11f8SLennert Buytenhek /* 95e84665c9SLennert Buytenhek * Info structs describing each of the switch chips 96e84665c9SLennert Buytenhek * connected via this network interface. 9791da11f8SLennert Buytenhek */ 98e84665c9SLennert Buytenhek int nr_chips; 99e84665c9SLennert Buytenhek struct dsa_chip_data *chip; 10091da11f8SLennert Buytenhek }; 10191da11f8SLennert Buytenhek 1025075314eSAlexander Duyck struct packet_type; 1033e8a72d1SFlorian Fainelli 10468277a2cSJohn Crispin struct dsa_device_ops { 10568277a2cSJohn Crispin struct sk_buff *(*xmit)(struct sk_buff *skb, struct net_device *dev); 10668277a2cSJohn Crispin struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev, 10789e49506SFlorian Westphal struct packet_type *pt); 108598a9680SJohn Crispin int (*flow_dissect)(const struct sk_buff *skb, __be16 *proto, 109598a9680SJohn Crispin int *offset); 11068277a2cSJohn Crispin }; 11168277a2cSJohn Crispin 112cf50dcc2SBen Hutchings struct dsa_switch_tree { 11383c0afaeSAndrew Lunn struct list_head list; 11483c0afaeSAndrew Lunn 115f515f192SVivien Didelot /* Notifier chain for switch-wide events */ 116f515f192SVivien Didelot struct raw_notifier_head nh; 117f515f192SVivien Didelot 11883c0afaeSAndrew Lunn /* Tree identifier */ 11949463b7fSVivien Didelot unsigned int index; 12083c0afaeSAndrew Lunn 12183c0afaeSAndrew Lunn /* Number of switches attached to this tree */ 12283c0afaeSAndrew Lunn struct kref refcount; 12383c0afaeSAndrew Lunn 12483c0afaeSAndrew Lunn /* Has this tree been applied to the hardware? */ 125ec15dd42SVivien Didelot bool setup; 12683c0afaeSAndrew Lunn 127cf50dcc2SBen Hutchings /* 128cf50dcc2SBen Hutchings * Configuration data for the platform device that owns 129cf50dcc2SBen Hutchings * this dsa switch tree instance. 130cf50dcc2SBen Hutchings */ 131cf50dcc2SBen Hutchings struct dsa_platform_data *pd; 132cf85d08fSLennert Buytenhek 133cf50dcc2SBen Hutchings /* 1348b0d3ea5SVivien Didelot * The switch port to which the CPU is attached. 135cf50dcc2SBen Hutchings */ 1368b0d3ea5SVivien Didelot struct dsa_port *cpu_dp; 137cf50dcc2SBen Hutchings 138cf50dcc2SBen Hutchings /* 139cf50dcc2SBen Hutchings * Data for the individual switch chips. 140cf50dcc2SBen Hutchings */ 141cf50dcc2SBen Hutchings struct dsa_switch *ds[DSA_MAX_SWITCHES]; 142cf50dcc2SBen Hutchings }; 143cf50dcc2SBen Hutchings 144f50f2127SFlorian Fainelli /* TC matchall action types, only mirroring for now */ 145f50f2127SFlorian Fainelli enum dsa_port_mall_action_type { 146f50f2127SFlorian Fainelli DSA_PORT_MALL_MIRROR, 147f50f2127SFlorian Fainelli }; 148f50f2127SFlorian Fainelli 149f50f2127SFlorian Fainelli /* TC mirroring entry */ 150f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry { 151f50f2127SFlorian Fainelli u8 to_local_port; 152f50f2127SFlorian Fainelli bool ingress; 153f50f2127SFlorian Fainelli }; 154f50f2127SFlorian Fainelli 155f50f2127SFlorian Fainelli /* TC matchall entry */ 156f50f2127SFlorian Fainelli struct dsa_mall_tc_entry { 157f50f2127SFlorian Fainelli struct list_head list; 158f50f2127SFlorian Fainelli unsigned long cookie; 159f50f2127SFlorian Fainelli enum dsa_port_mall_action_type type; 160f50f2127SFlorian Fainelli union { 161f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry mirror; 162f50f2127SFlorian Fainelli }; 163f50f2127SFlorian Fainelli }; 164f50f2127SFlorian Fainelli 165f50f2127SFlorian Fainelli 166c8b09808SAndrew Lunn struct dsa_port { 167f8b8b1cdSVivien Didelot /* A CPU port is physically connected to a master device. 168f8b8b1cdSVivien Didelot * A user port exposed to userspace has a slave device. 169f8b8b1cdSVivien Didelot */ 170f8b8b1cdSVivien Didelot union { 171f8b8b1cdSVivien Didelot struct net_device *master; 172f8b8b1cdSVivien Didelot struct net_device *slave; 173f8b8b1cdSVivien Didelot }; 174f8b8b1cdSVivien Didelot 17515240248SVivien Didelot /* CPU port tagging operations used by master or slave devices */ 17615240248SVivien Didelot const struct dsa_device_ops *tag_ops; 17715240248SVivien Didelot 1783e41f93bSVivien Didelot /* Copies for faster access in master receive hot path */ 1793e41f93bSVivien Didelot struct dsa_switch_tree *dst; 1803e41f93bSVivien Didelot struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev, 1813e41f93bSVivien Didelot struct packet_type *pt); 1823e41f93bSVivien Didelot 183057cad2cSVivien Didelot enum { 184057cad2cSVivien Didelot DSA_PORT_TYPE_UNUSED = 0, 185057cad2cSVivien Didelot DSA_PORT_TYPE_CPU, 186057cad2cSVivien Didelot DSA_PORT_TYPE_DSA, 187057cad2cSVivien Didelot DSA_PORT_TYPE_USER, 188057cad2cSVivien Didelot } type; 189057cad2cSVivien Didelot 190818be848SVivien Didelot struct dsa_switch *ds; 191818be848SVivien Didelot unsigned int index; 19271e0bbdeSFlorian Fainelli const char *name; 19324a9332aSVivien Didelot const struct dsa_port *cpu_dp; 194189b0d93SAndrew Lunn struct device_node *dn; 19534a79f63SVivien Didelot unsigned int ageing_time; 196732f794cSVivien Didelot u8 stp_state; 197a5e9a02eSVivien Didelot struct net_device *bridge_dev; 19896567d5dSAndrew Lunn struct devlink_port devlink_port; 19967dbb9d4SFlorian Fainelli /* 20067dbb9d4SFlorian Fainelli * Original copy of the master netdev ethtool_ops 20167dbb9d4SFlorian Fainelli */ 20267dbb9d4SFlorian Fainelli const struct ethtool_ops *orig_ethtool_ops; 203c8b09808SAndrew Lunn }; 204c8b09808SAndrew Lunn 205c8f0b869SBen Hutchings struct dsa_switch { 206c33063d6SAndrew Lunn struct device *dev; 207c33063d6SAndrew Lunn 208c8f0b869SBen Hutchings /* 209c8f0b869SBen Hutchings * Parent switch tree, and switch index. 210c8f0b869SBen Hutchings */ 211c8f0b869SBen Hutchings struct dsa_switch_tree *dst; 21299feaafcSVivien Didelot unsigned int index; 213c8f0b869SBen Hutchings 214f515f192SVivien Didelot /* Listener for switch fabric events */ 215f515f192SVivien Didelot struct notifier_block nb; 216f515f192SVivien Didelot 217c8f0b869SBen Hutchings /* 2187543a6d5SAndrew Lunn * Give the switch driver somewhere to hang its private data 2197543a6d5SAndrew Lunn * structure. 2207543a6d5SAndrew Lunn */ 2217543a6d5SAndrew Lunn void *priv; 2227543a6d5SAndrew Lunn 2237543a6d5SAndrew Lunn /* 224c8f0b869SBen Hutchings * Configuration data for this switch. 225c8f0b869SBen Hutchings */ 226ff04955cSAndrew Lunn struct dsa_chip_data *cd; 227c8f0b869SBen Hutchings 228c8f0b869SBen Hutchings /* 2299d490b4eSVivien Didelot * The switch operations. 230c8f0b869SBen Hutchings */ 231a82f67afSFlorian Fainelli const struct dsa_switch_ops *ops; 232c8f0b869SBen Hutchings 23366472fc0SAndrew Lunn /* 23466472fc0SAndrew Lunn * An array of which element [a] indicates which port on this 23566472fc0SAndrew Lunn * switch should be used to send packets to that are destined 23666472fc0SAndrew Lunn * for switch a. Can be NULL if there is only one switch chip. 23766472fc0SAndrew Lunn */ 23866472fc0SAndrew Lunn s8 rtable[DSA_MAX_SWITCHES]; 23966472fc0SAndrew Lunn 240c8f0b869SBen Hutchings /* 241c8f0b869SBen Hutchings * Slave mii_bus and devices for the individual ports. 242c8f0b869SBen Hutchings */ 2430d8bcdd3SFlorian Fainelli u32 phys_mii_mask; 244c8f0b869SBen Hutchings struct mii_bus *slave_mii_bus; 245a0c02161SVivien Didelot 2460f3da6afSVivien Didelot /* Ageing Time limits in msecs */ 2470f3da6afSVivien Didelot unsigned int ageing_time_min; 2480f3da6afSVivien Didelot unsigned int ageing_time_max; 2490f3da6afSVivien Didelot 25096567d5dSAndrew Lunn /* devlink used to represent this switch device */ 25196567d5dSAndrew Lunn struct devlink *devlink; 25296567d5dSAndrew Lunn 25355199df6SFlorian Fainelli /* Number of switch port queues */ 25455199df6SFlorian Fainelli unsigned int num_tx_queues; 25555199df6SFlorian Fainelli 256a0c02161SVivien Didelot /* Dynamically allocated ports, keep last */ 257a0c02161SVivien Didelot size_t num_ports; 258a0c02161SVivien Didelot struct dsa_port ports[]; 259c8f0b869SBen Hutchings }; 260c8f0b869SBen Hutchings 261c38c5a66SVivien Didelot static inline const struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p) 262c38c5a66SVivien Didelot { 263c38c5a66SVivien Didelot return &ds->ports[p]; 264c38c5a66SVivien Didelot } 265c38c5a66SVivien Didelot 266bff7b688SVivien Didelot static inline bool dsa_is_unused_port(struct dsa_switch *ds, int p) 267bff7b688SVivien Didelot { 268c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_UNUSED; 269bff7b688SVivien Didelot } 270bff7b688SVivien Didelot 271c8f0b869SBen Hutchings static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p) 272c8f0b869SBen Hutchings { 273c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_CPU; 274c8f0b869SBen Hutchings } 275c8f0b869SBen Hutchings 27660045cbfSAndrew Lunn static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p) 27760045cbfSAndrew Lunn { 278c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_DSA; 27960045cbfSAndrew Lunn } 28060045cbfSAndrew Lunn 2812b3e9891SVivien Didelot static inline bool dsa_is_user_port(struct dsa_switch *ds, int p) 2826cd456f3SVivien Didelot { 283c38c5a66SVivien Didelot return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_USER; 2846cd456f3SVivien Didelot } 2856cd456f3SVivien Didelot 28602bc6e54SVivien Didelot static inline u32 dsa_user_ports(struct dsa_switch *ds) 28702bc6e54SVivien Didelot { 288c38c5a66SVivien Didelot u32 mask = 0; 289c38c5a66SVivien Didelot int p; 29002bc6e54SVivien Didelot 291c38c5a66SVivien Didelot for (p = 0; p < ds->num_ports; p++) 292c38c5a66SVivien Didelot if (dsa_is_user_port(ds, p)) 293c38c5a66SVivien Didelot mask |= BIT(p); 294c38c5a66SVivien Didelot 295c38c5a66SVivien Didelot return mask; 296c8652c83SVivien Didelot } 297c8652c83SVivien Didelot 298c8f0b869SBen Hutchings static inline u8 dsa_upstream_port(struct dsa_switch *ds) 299c8f0b869SBen Hutchings { 300c8f0b869SBen Hutchings struct dsa_switch_tree *dst = ds->dst; 301c8f0b869SBen Hutchings 302c8f0b869SBen Hutchings /* 303c8f0b869SBen Hutchings * If this is the root switch (i.e. the switch that connects 304c8f0b869SBen Hutchings * to the CPU), return the cpu port number on this switch. 305c8f0b869SBen Hutchings * Else return the (DSA) port number that connects to the 306c8f0b869SBen Hutchings * switch that is one hop closer to the cpu. 307c8f0b869SBen Hutchings */ 3088b0d3ea5SVivien Didelot if (dst->cpu_dp->ds == ds) 3098b0d3ea5SVivien Didelot return dst->cpu_dp->index; 310c8f0b869SBen Hutchings else 3118b0d3ea5SVivien Didelot return ds->rtable[dst->cpu_dp->ds->index]; 312c8f0b869SBen Hutchings } 313c8f0b869SBen Hutchings 3142bedde1aSArkadi Sharshevsky typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid, 3152bedde1aSArkadi Sharshevsky bool is_static, void *data); 3169d490b4eSVivien Didelot struct dsa_switch_ops { 317c8f0b869SBen Hutchings /* 318a6a71f19SVivien Didelot * Legacy probing. 319c8f0b869SBen Hutchings */ 3200209d144SVivien Didelot const char *(*probe)(struct device *dsa_dev, 3210209d144SVivien Didelot struct device *host_dev, int sw_addr, 3220209d144SVivien Didelot void **priv); 3237b314362SAndrew Lunn 324*5ed4e3ebSFlorian Fainelli enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds, 325*5ed4e3ebSFlorian Fainelli int port); 3267b314362SAndrew Lunn 327c8f0b869SBen Hutchings int (*setup)(struct dsa_switch *ds); 3286819563eSFlorian Fainelli u32 (*get_phy_flags)(struct dsa_switch *ds, int port); 329c8f0b869SBen Hutchings 330c8f0b869SBen Hutchings /* 331c8f0b869SBen Hutchings * Access to the switch's PHY registers. 332c8f0b869SBen Hutchings */ 333c8f0b869SBen Hutchings int (*phy_read)(struct dsa_switch *ds, int port, int regnum); 334c8f0b869SBen Hutchings int (*phy_write)(struct dsa_switch *ds, int port, 335c8f0b869SBen Hutchings int regnum, u16 val); 336c8f0b869SBen Hutchings 337c8f0b869SBen Hutchings /* 338ec9436baSFlorian Fainelli * Link state adjustment (called from libphy) 339ec9436baSFlorian Fainelli */ 340ec9436baSFlorian Fainelli void (*adjust_link)(struct dsa_switch *ds, int port, 341ec9436baSFlorian Fainelli struct phy_device *phydev); 342ce31b31cSFlorian Fainelli void (*fixed_link_update)(struct dsa_switch *ds, int port, 343ce31b31cSFlorian Fainelli struct fixed_phy_status *st); 344ec9436baSFlorian Fainelli 345ec9436baSFlorian Fainelli /* 346c8f0b869SBen Hutchings * ethtool hardware statistics. 347c8f0b869SBen Hutchings */ 348c8f0b869SBen Hutchings void (*get_strings)(struct dsa_switch *ds, int port, uint8_t *data); 349c8f0b869SBen Hutchings void (*get_ethtool_stats)(struct dsa_switch *ds, 350c8f0b869SBen Hutchings int port, uint64_t *data); 351c8f0b869SBen Hutchings int (*get_sset_count)(struct dsa_switch *ds); 35224462549SFlorian Fainelli 35324462549SFlorian Fainelli /* 35419e57c4eSFlorian Fainelli * ethtool Wake-on-LAN 35519e57c4eSFlorian Fainelli */ 35619e57c4eSFlorian Fainelli void (*get_wol)(struct dsa_switch *ds, int port, 35719e57c4eSFlorian Fainelli struct ethtool_wolinfo *w); 35819e57c4eSFlorian Fainelli int (*set_wol)(struct dsa_switch *ds, int port, 35919e57c4eSFlorian Fainelli struct ethtool_wolinfo *w); 36019e57c4eSFlorian Fainelli 36119e57c4eSFlorian Fainelli /* 36224462549SFlorian Fainelli * Suspend and resume 36324462549SFlorian Fainelli */ 36424462549SFlorian Fainelli int (*suspend)(struct dsa_switch *ds); 36524462549SFlorian Fainelli int (*resume)(struct dsa_switch *ds); 366b2f2af21SFlorian Fainelli 367b2f2af21SFlorian Fainelli /* 368b2f2af21SFlorian Fainelli * Port enable/disable 369b2f2af21SFlorian Fainelli */ 370b2f2af21SFlorian Fainelli int (*port_enable)(struct dsa_switch *ds, int port, 371b2f2af21SFlorian Fainelli struct phy_device *phy); 372b2f2af21SFlorian Fainelli void (*port_disable)(struct dsa_switch *ds, int port, 373b2f2af21SFlorian Fainelli struct phy_device *phy); 3747905288fSFlorian Fainelli 3757905288fSFlorian Fainelli /* 37608f50061SVivien Didelot * Port's MAC EEE settings 3777905288fSFlorian Fainelli */ 37808f50061SVivien Didelot int (*set_mac_eee)(struct dsa_switch *ds, int port, 3797905288fSFlorian Fainelli struct ethtool_eee *e); 38008f50061SVivien Didelot int (*get_mac_eee)(struct dsa_switch *ds, int port, 3817905288fSFlorian Fainelli struct ethtool_eee *e); 38251579c3fSGuenter Roeck 3836793abb4SGuenter Roeck /* EEPROM access */ 3846793abb4SGuenter Roeck int (*get_eeprom_len)(struct dsa_switch *ds); 3856793abb4SGuenter Roeck int (*get_eeprom)(struct dsa_switch *ds, 3866793abb4SGuenter Roeck struct ethtool_eeprom *eeprom, u8 *data); 3876793abb4SGuenter Roeck int (*set_eeprom)(struct dsa_switch *ds, 3886793abb4SGuenter Roeck struct ethtool_eeprom *eeprom, u8 *data); 3893d762a0fSGuenter Roeck 3903d762a0fSGuenter Roeck /* 3913d762a0fSGuenter Roeck * Register access. 3923d762a0fSGuenter Roeck */ 3933d762a0fSGuenter Roeck int (*get_regs_len)(struct dsa_switch *ds, int port); 3943d762a0fSGuenter Roeck void (*get_regs)(struct dsa_switch *ds, int port, 3953d762a0fSGuenter Roeck struct ethtool_regs *regs, void *p); 396b73adef6SFlorian Fainelli 397b73adef6SFlorian Fainelli /* 398b73adef6SFlorian Fainelli * Bridge integration 399b73adef6SFlorian Fainelli */ 40034a79f63SVivien Didelot int (*set_ageing_time)(struct dsa_switch *ds, unsigned int msecs); 40171327a4eSVivien Didelot int (*port_bridge_join)(struct dsa_switch *ds, int port, 402a6692754SVivien Didelot struct net_device *bridge); 403f123f2fbSVivien Didelot void (*port_bridge_leave)(struct dsa_switch *ds, int port, 404f123f2fbSVivien Didelot struct net_device *bridge); 40543c44a9fSVivien Didelot void (*port_stp_state_set)(struct dsa_switch *ds, int port, 406b73adef6SFlorian Fainelli u8 state); 407732f794cSVivien Didelot void (*port_fast_age)(struct dsa_switch *ds, int port); 4082a778e1bSVivien Didelot 4092a778e1bSVivien Didelot /* 41011149536SVivien Didelot * VLAN support 41111149536SVivien Didelot */ 412fb2dabadSVivien Didelot int (*port_vlan_filtering)(struct dsa_switch *ds, int port, 413fb2dabadSVivien Didelot bool vlan_filtering); 41476e398a6SVivien Didelot int (*port_vlan_prepare)(struct dsa_switch *ds, int port, 41576e398a6SVivien Didelot const struct switchdev_obj_port_vlan *vlan, 41676e398a6SVivien Didelot struct switchdev_trans *trans); 4174d5770b3SVivien Didelot void (*port_vlan_add)(struct dsa_switch *ds, int port, 41876e398a6SVivien Didelot const struct switchdev_obj_port_vlan *vlan, 41976e398a6SVivien Didelot struct switchdev_trans *trans); 42076e398a6SVivien Didelot int (*port_vlan_del)(struct dsa_switch *ds, int port, 42176e398a6SVivien Didelot const struct switchdev_obj_port_vlan *vlan); 42211149536SVivien Didelot /* 4232a778e1bSVivien Didelot * Forwarding database 4242a778e1bSVivien Didelot */ 4251b6dd556SArkadi Sharshevsky int (*port_fdb_add)(struct dsa_switch *ds, int port, 4266c2c1dcbSArkadi Sharshevsky const unsigned char *addr, u16 vid); 4272a778e1bSVivien Didelot int (*port_fdb_del)(struct dsa_switch *ds, int port, 4286c2c1dcbSArkadi Sharshevsky const unsigned char *addr, u16 vid); 429ea70ba98SVivien Didelot int (*port_fdb_dump)(struct dsa_switch *ds, int port, 4302bedde1aSArkadi Sharshevsky dsa_fdb_dump_cb_t *cb, void *data); 4318df30255SVivien Didelot 4328df30255SVivien Didelot /* 4338df30255SVivien Didelot * Multicast database 4348df30255SVivien Didelot */ 4358df30255SVivien Didelot int (*port_mdb_prepare)(struct dsa_switch *ds, int port, 4368df30255SVivien Didelot const struct switchdev_obj_port_mdb *mdb, 4378df30255SVivien Didelot struct switchdev_trans *trans); 4388df30255SVivien Didelot void (*port_mdb_add)(struct dsa_switch *ds, int port, 4398df30255SVivien Didelot const struct switchdev_obj_port_mdb *mdb, 4408df30255SVivien Didelot struct switchdev_trans *trans); 4418df30255SVivien Didelot int (*port_mdb_del)(struct dsa_switch *ds, int port, 4428df30255SVivien Didelot const struct switchdev_obj_port_mdb *mdb); 443bf9f2648SFlorian Fainelli /* 444bf9f2648SFlorian Fainelli * RXNFC 445bf9f2648SFlorian Fainelli */ 446bf9f2648SFlorian Fainelli int (*get_rxnfc)(struct dsa_switch *ds, int port, 447bf9f2648SFlorian Fainelli struct ethtool_rxnfc *nfc, u32 *rule_locs); 448bf9f2648SFlorian Fainelli int (*set_rxnfc)(struct dsa_switch *ds, int port, 449bf9f2648SFlorian Fainelli struct ethtool_rxnfc *nfc); 450f50f2127SFlorian Fainelli 451f50f2127SFlorian Fainelli /* 452f50f2127SFlorian Fainelli * TC integration 453f50f2127SFlorian Fainelli */ 454f50f2127SFlorian Fainelli int (*port_mirror_add)(struct dsa_switch *ds, int port, 455f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror, 456f50f2127SFlorian Fainelli bool ingress); 457f50f2127SFlorian Fainelli void (*port_mirror_del)(struct dsa_switch *ds, int port, 458f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror); 45940ef2c93SVivien Didelot 46040ef2c93SVivien Didelot /* 46140ef2c93SVivien Didelot * Cross-chip operations 46240ef2c93SVivien Didelot */ 46340ef2c93SVivien Didelot int (*crosschip_bridge_join)(struct dsa_switch *ds, int sw_index, 46440ef2c93SVivien Didelot int port, struct net_device *br); 46540ef2c93SVivien Didelot void (*crosschip_bridge_leave)(struct dsa_switch *ds, int sw_index, 46640ef2c93SVivien Didelot int port, struct net_device *br); 467c8f0b869SBen Hutchings }; 468c8f0b869SBen Hutchings 469ab3d408dSFlorian Fainelli struct dsa_switch_driver { 470ab3d408dSFlorian Fainelli struct list_head list; 471a82f67afSFlorian Fainelli const struct dsa_switch_ops *ops; 472ab3d408dSFlorian Fainelli }; 473ab3d408dSFlorian Fainelli 474a6a71f19SVivien Didelot /* Legacy driver registration */ 475ab3d408dSFlorian Fainelli void register_switch_driver(struct dsa_switch_driver *type); 476ab3d408dSFlorian Fainelli void unregister_switch_driver(struct dsa_switch_driver *type); 477b4d2394dSAlexander Duyck struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev); 478a6a71f19SVivien Didelot 47914b89f36SFlorian Fainelli struct net_device *dsa_dev_to_net_device(struct device *dev); 480c8f0b869SBen Hutchings 48173a7ece8SVivien Didelot /* Keep inline for faster access in hot path */ 482c6e970a0SAndrew Lunn static inline bool netdev_uses_dsa(struct net_device *dev) 483c6e970a0SAndrew Lunn { 484c6e970a0SAndrew Lunn #if IS_ENABLED(CONFIG_NET_DSA) 485717ffbfbSVivien Didelot return dev->dsa_ptr && dev->dsa_ptr->rcv; 486c6e970a0SAndrew Lunn #endif 487c6e970a0SAndrew Lunn return false; 488c6e970a0SAndrew Lunn } 489c6e970a0SAndrew Lunn 490a0c02161SVivien Didelot struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n); 49183c0afaeSAndrew Lunn void dsa_unregister_switch(struct dsa_switch *ds); 49223c9ee49SVivien Didelot int dsa_register_switch(struct dsa_switch *ds); 493ea825e70SFlorian Fainelli #ifdef CONFIG_PM_SLEEP 494ea825e70SFlorian Fainelli int dsa_switch_suspend(struct dsa_switch *ds); 495ea825e70SFlorian Fainelli int dsa_switch_resume(struct dsa_switch *ds); 496ea825e70SFlorian Fainelli #else 497ea825e70SFlorian Fainelli static inline int dsa_switch_suspend(struct dsa_switch *ds) 498ea825e70SFlorian Fainelli { 499ea825e70SFlorian Fainelli return 0; 500ea825e70SFlorian Fainelli } 501ea825e70SFlorian Fainelli static inline int dsa_switch_resume(struct dsa_switch *ds) 502ea825e70SFlorian Fainelli { 503ea825e70SFlorian Fainelli return 0; 504ea825e70SFlorian Fainelli } 505ea825e70SFlorian Fainelli #endif /* CONFIG_PM_SLEEP */ 506ea825e70SFlorian Fainelli 50760724d4bSFlorian Fainelli enum dsa_notifier_type { 50860724d4bSFlorian Fainelli DSA_PORT_REGISTER, 50960724d4bSFlorian Fainelli DSA_PORT_UNREGISTER, 51060724d4bSFlorian Fainelli }; 51160724d4bSFlorian Fainelli 51260724d4bSFlorian Fainelli struct dsa_notifier_info { 51360724d4bSFlorian Fainelli struct net_device *dev; 51460724d4bSFlorian Fainelli }; 51560724d4bSFlorian Fainelli 51660724d4bSFlorian Fainelli struct dsa_notifier_register_info { 51760724d4bSFlorian Fainelli struct dsa_notifier_info info; /* must be first */ 51860724d4bSFlorian Fainelli struct net_device *master; 51960724d4bSFlorian Fainelli unsigned int port_number; 52060724d4bSFlorian Fainelli unsigned int switch_number; 52160724d4bSFlorian Fainelli }; 52260724d4bSFlorian Fainelli 52360724d4bSFlorian Fainelli static inline struct net_device * 52460724d4bSFlorian Fainelli dsa_notifier_info_to_dev(const struct dsa_notifier_info *info) 52560724d4bSFlorian Fainelli { 52660724d4bSFlorian Fainelli return info->dev; 52760724d4bSFlorian Fainelli } 52860724d4bSFlorian Fainelli 52960724d4bSFlorian Fainelli #if IS_ENABLED(CONFIG_NET_DSA) 53060724d4bSFlorian Fainelli int register_dsa_notifier(struct notifier_block *nb); 53160724d4bSFlorian Fainelli int unregister_dsa_notifier(struct notifier_block *nb); 53260724d4bSFlorian Fainelli int call_dsa_notifiers(unsigned long val, struct net_device *dev, 53360724d4bSFlorian Fainelli struct dsa_notifier_info *info); 53460724d4bSFlorian Fainelli #else 53560724d4bSFlorian Fainelli static inline int register_dsa_notifier(struct notifier_block *nb) 53660724d4bSFlorian Fainelli { 53760724d4bSFlorian Fainelli return 0; 53860724d4bSFlorian Fainelli } 53960724d4bSFlorian Fainelli 54060724d4bSFlorian Fainelli static inline int unregister_dsa_notifier(struct notifier_block *nb) 54160724d4bSFlorian Fainelli { 54260724d4bSFlorian Fainelli return 0; 54360724d4bSFlorian Fainelli } 54460724d4bSFlorian Fainelli 54560724d4bSFlorian Fainelli static inline int call_dsa_notifiers(unsigned long val, struct net_device *dev, 54660724d4bSFlorian Fainelli struct dsa_notifier_info *info) 54760724d4bSFlorian Fainelli { 54860724d4bSFlorian Fainelli return NOTIFY_DONE; 54960724d4bSFlorian Fainelli } 55060724d4bSFlorian Fainelli #endif 55160724d4bSFlorian Fainelli 5520a5f14ceSFlorian Fainelli /* Broadcom tag specific helpers to insert and extract queue/port number */ 5530a5f14ceSFlorian Fainelli #define BRCM_TAG_SET_PORT_QUEUE(p, q) ((p) << 8 | q) 5540a5f14ceSFlorian Fainelli #define BRCM_TAG_GET_PORT(v) ((v) >> 8) 5550a5f14ceSFlorian Fainelli #define BRCM_TAG_GET_QUEUE(v) ((v) & 0xff) 5560a5f14ceSFlorian Fainelli 55791da11f8SLennert Buytenhek #endif 558