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> 22cf50dcc2SBen Hutchings 23f50f2127SFlorian Fainelli struct tc_action; 244d56a29fSRussell King struct phy_device; 254d56a29fSRussell King struct fixed_phy_status; 26f50f2127SFlorian Fainelli 27ac7a04c3SFlorian Fainelli enum dsa_tag_protocol { 28ac7a04c3SFlorian Fainelli DSA_TAG_PROTO_NONE = 0, 29ac7a04c3SFlorian Fainelli DSA_TAG_PROTO_DSA, 30ac7a04c3SFlorian Fainelli DSA_TAG_PROTO_TRAILER, 31ac7a04c3SFlorian Fainelli DSA_TAG_PROTO_EDSA, 32ac7a04c3SFlorian Fainelli DSA_TAG_PROTO_BRCM, 33cafdc45cSJohn Crispin DSA_TAG_PROTO_QCA, 3439a7f2a4SAndrew Lunn DSA_TAG_LAST, /* MUST BE LAST */ 35ac7a04c3SFlorian Fainelli }; 365037d532SFlorian Fainelli 37e84665c9SLennert Buytenhek #define DSA_MAX_SWITCHES 4 3891da11f8SLennert Buytenhek #define DSA_MAX_PORTS 12 3991da11f8SLennert Buytenhek 40d390238cSVivien Didelot #define DSA_RTABLE_NONE -1 41d390238cSVivien Didelot 42e84665c9SLennert Buytenhek struct dsa_chip_data { 43e84665c9SLennert Buytenhek /* 44e84665c9SLennert Buytenhek * How to access the switch configuration registers. 45e84665c9SLennert Buytenhek */ 46b4d2394dSAlexander Duyck struct device *host_dev; 47e84665c9SLennert Buytenhek int sw_addr; 48e84665c9SLennert Buytenhek 4971e0bbdeSFlorian Fainelli /* 5071e0bbdeSFlorian Fainelli * Reference to network devices 5171e0bbdeSFlorian Fainelli */ 5271e0bbdeSFlorian Fainelli struct device *netdev[DSA_MAX_PORTS]; 5371e0bbdeSFlorian Fainelli 546793abb4SGuenter Roeck /* set to size of eeprom if supported by the switch */ 556793abb4SGuenter Roeck int eeprom_len; 566793abb4SGuenter Roeck 57fa981d9aSFlorian Fainelli /* Device tree node pointer for this specific switch chip 58fa981d9aSFlorian Fainelli * used during switch setup in case additional properties 59fa981d9aSFlorian Fainelli * and resources needs to be used 60fa981d9aSFlorian Fainelli */ 61fa981d9aSFlorian Fainelli struct device_node *of_node; 62fa981d9aSFlorian Fainelli 63e84665c9SLennert Buytenhek /* 64e84665c9SLennert Buytenhek * The names of the switch's ports. Use "cpu" to 65e84665c9SLennert Buytenhek * designate the switch port that the cpu is connected to, 66e84665c9SLennert Buytenhek * "dsa" to indicate that this port is a DSA link to 67e84665c9SLennert Buytenhek * another switch, NULL to indicate the port is unused, 68e84665c9SLennert Buytenhek * or any other string to indicate this is a physical port. 69e84665c9SLennert Buytenhek */ 70e84665c9SLennert Buytenhek char *port_names[DSA_MAX_PORTS]; 71bd47497aSFlorian Fainelli struct device_node *port_dn[DSA_MAX_PORTS]; 72e84665c9SLennert Buytenhek 73e84665c9SLennert Buytenhek /* 744a7704ffSAndrew Lunn * An array of which element [a] indicates which port on this 754a7704ffSAndrew Lunn * switch should be used to send packets to that are destined 764a7704ffSAndrew Lunn * for switch a. Can be NULL if there is only one switch chip. 77e84665c9SLennert Buytenhek */ 784a7704ffSAndrew Lunn s8 rtable[DSA_MAX_SWITCHES]; 79e84665c9SLennert Buytenhek }; 80e84665c9SLennert Buytenhek 8191da11f8SLennert Buytenhek struct dsa_platform_data { 8291da11f8SLennert Buytenhek /* 8391da11f8SLennert Buytenhek * Reference to a Linux network interface that connects 84e84665c9SLennert Buytenhek * to the root switch chip of the tree. 8591da11f8SLennert Buytenhek */ 8691da11f8SLennert Buytenhek struct device *netdev; 87769a0202SFlorian Fainelli struct net_device *of_netdev; 8891da11f8SLennert Buytenhek 8991da11f8SLennert Buytenhek /* 90e84665c9SLennert Buytenhek * Info structs describing each of the switch chips 91e84665c9SLennert Buytenhek * connected via this network interface. 9291da11f8SLennert Buytenhek */ 93e84665c9SLennert Buytenhek int nr_chips; 94e84665c9SLennert Buytenhek struct dsa_chip_data *chip; 9591da11f8SLennert Buytenhek }; 9691da11f8SLennert Buytenhek 975075314eSAlexander Duyck struct packet_type; 983e8a72d1SFlorian Fainelli 99cf50dcc2SBen Hutchings struct dsa_switch_tree { 10083c0afaeSAndrew Lunn struct list_head list; 10183c0afaeSAndrew Lunn 102f515f192SVivien Didelot /* Notifier chain for switch-wide events */ 103f515f192SVivien Didelot struct raw_notifier_head nh; 104f515f192SVivien Didelot 10583c0afaeSAndrew Lunn /* Tree identifier */ 10683c0afaeSAndrew Lunn u32 tree; 10783c0afaeSAndrew Lunn 10883c0afaeSAndrew Lunn /* Number of switches attached to this tree */ 10983c0afaeSAndrew Lunn struct kref refcount; 11083c0afaeSAndrew Lunn 11183c0afaeSAndrew Lunn /* Has this tree been applied to the hardware? */ 11283c0afaeSAndrew Lunn bool applied; 11383c0afaeSAndrew Lunn 114cf50dcc2SBen Hutchings /* 115cf50dcc2SBen Hutchings * Configuration data for the platform device that owns 116cf50dcc2SBen Hutchings * this dsa switch tree instance. 117cf50dcc2SBen Hutchings */ 118cf50dcc2SBen Hutchings struct dsa_platform_data *pd; 119cf85d08fSLennert Buytenhek 120cf50dcc2SBen Hutchings /* 121cf50dcc2SBen Hutchings * Reference to network device to use, and which tagging 122cf50dcc2SBen Hutchings * protocol to use. 123cf50dcc2SBen Hutchings */ 124cf50dcc2SBen Hutchings struct net_device *master_netdev; 1255075314eSAlexander Duyck int (*rcv)(struct sk_buff *skb, 1265075314eSAlexander Duyck struct net_device *dev, 1275075314eSAlexander Duyck struct packet_type *pt, 1285075314eSAlexander Duyck struct net_device *orig_dev); 129cf50dcc2SBen Hutchings 130cf50dcc2SBen Hutchings /* 131badf3adaSFlorian Fainelli * Original copy of the master netdev ethtool_ops 132badf3adaSFlorian Fainelli */ 133badf3adaSFlorian Fainelli struct ethtool_ops master_ethtool_ops; 1340c73c523SFlorian Fainelli const struct ethtool_ops *master_orig_ethtool_ops; 135badf3adaSFlorian Fainelli 136badf3adaSFlorian Fainelli /* 137cf50dcc2SBen Hutchings * The switch and port to which the CPU is attached. 138cf50dcc2SBen Hutchings */ 139b22de490SVivien Didelot struct dsa_switch *cpu_switch; 140cf50dcc2SBen Hutchings s8 cpu_port; 141cf50dcc2SBen Hutchings 142cf50dcc2SBen Hutchings /* 143cf50dcc2SBen Hutchings * Data for the individual switch chips. 144cf50dcc2SBen Hutchings */ 145cf50dcc2SBen Hutchings struct dsa_switch *ds[DSA_MAX_SWITCHES]; 14639a7f2a4SAndrew Lunn 14739a7f2a4SAndrew Lunn /* 14839a7f2a4SAndrew Lunn * Tagging protocol operations for adding and removing an 14939a7f2a4SAndrew Lunn * encapsulation tag. 15039a7f2a4SAndrew Lunn */ 15139a7f2a4SAndrew Lunn const struct dsa_device_ops *tag_ops; 152cf50dcc2SBen Hutchings }; 153cf50dcc2SBen Hutchings 154f50f2127SFlorian Fainelli /* TC matchall action types, only mirroring for now */ 155f50f2127SFlorian Fainelli enum dsa_port_mall_action_type { 156f50f2127SFlorian Fainelli DSA_PORT_MALL_MIRROR, 157f50f2127SFlorian Fainelli }; 158f50f2127SFlorian Fainelli 159f50f2127SFlorian Fainelli /* TC mirroring entry */ 160f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry { 161f50f2127SFlorian Fainelli u8 to_local_port; 162f50f2127SFlorian Fainelli bool ingress; 163f50f2127SFlorian Fainelli }; 164f50f2127SFlorian Fainelli 165f50f2127SFlorian Fainelli /* TC matchall entry */ 166f50f2127SFlorian Fainelli struct dsa_mall_tc_entry { 167f50f2127SFlorian Fainelli struct list_head list; 168f50f2127SFlorian Fainelli unsigned long cookie; 169f50f2127SFlorian Fainelli enum dsa_port_mall_action_type type; 170f50f2127SFlorian Fainelli union { 171f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry mirror; 172f50f2127SFlorian Fainelli }; 173f50f2127SFlorian Fainelli }; 174f50f2127SFlorian Fainelli 175f50f2127SFlorian Fainelli 176c8b09808SAndrew Lunn struct dsa_port { 177818be848SVivien Didelot struct dsa_switch *ds; 178818be848SVivien Didelot unsigned int index; 17971e0bbdeSFlorian Fainelli const char *name; 180c8b09808SAndrew Lunn struct net_device *netdev; 181189b0d93SAndrew Lunn struct device_node *dn; 18234a79f63SVivien Didelot unsigned int ageing_time; 183732f794cSVivien Didelot u8 stp_state; 184a5e9a02eSVivien Didelot struct net_device *bridge_dev; 185c8b09808SAndrew Lunn }; 186c8b09808SAndrew Lunn 187c8f0b869SBen Hutchings struct dsa_switch { 188c33063d6SAndrew Lunn struct device *dev; 189c33063d6SAndrew Lunn 190c8f0b869SBen Hutchings /* 191c8f0b869SBen Hutchings * Parent switch tree, and switch index. 192c8f0b869SBen Hutchings */ 193c8f0b869SBen Hutchings struct dsa_switch_tree *dst; 194c8f0b869SBen Hutchings int index; 195c8f0b869SBen Hutchings 196f515f192SVivien Didelot /* Listener for switch fabric events */ 197f515f192SVivien Didelot struct notifier_block nb; 198f515f192SVivien Didelot 199c8f0b869SBen Hutchings /* 2007543a6d5SAndrew Lunn * Give the switch driver somewhere to hang its private data 2017543a6d5SAndrew Lunn * structure. 2027543a6d5SAndrew Lunn */ 2037543a6d5SAndrew Lunn void *priv; 2047543a6d5SAndrew Lunn 2057543a6d5SAndrew Lunn /* 206c8f0b869SBen Hutchings * Configuration data for this switch. 207c8f0b869SBen Hutchings */ 208ff04955cSAndrew Lunn struct dsa_chip_data *cd; 209c8f0b869SBen Hutchings 210c8f0b869SBen Hutchings /* 2119d490b4eSVivien Didelot * The switch operations. 212c8f0b869SBen Hutchings */ 213a82f67afSFlorian Fainelli const struct dsa_switch_ops *ops; 214c8f0b869SBen Hutchings 21566472fc0SAndrew Lunn /* 21666472fc0SAndrew Lunn * An array of which element [a] indicates which port on this 21766472fc0SAndrew Lunn * switch should be used to send packets to that are destined 21866472fc0SAndrew Lunn * for switch a. Can be NULL if there is only one switch chip. 21966472fc0SAndrew Lunn */ 22066472fc0SAndrew Lunn s8 rtable[DSA_MAX_SWITCHES]; 22166472fc0SAndrew Lunn 222c8f0b869SBen Hutchings /* 22383c0afaeSAndrew Lunn * The lower device this switch uses to talk to the host 22483c0afaeSAndrew Lunn */ 22583c0afaeSAndrew Lunn struct net_device *master_netdev; 22683c0afaeSAndrew Lunn 22783c0afaeSAndrew Lunn /* 228c8f0b869SBen Hutchings * Slave mii_bus and devices for the individual ports. 229c8f0b869SBen Hutchings */ 230c8f0b869SBen Hutchings u32 dsa_port_mask; 23183c0afaeSAndrew Lunn u32 cpu_port_mask; 23274c3e2a5SAndrew Lunn u32 enabled_port_mask; 2330d8bcdd3SFlorian Fainelli u32 phys_mii_mask; 234c8f0b869SBen Hutchings struct mii_bus *slave_mii_bus; 235a0c02161SVivien Didelot 2360f3da6afSVivien Didelot /* Ageing Time limits in msecs */ 2370f3da6afSVivien Didelot unsigned int ageing_time_min; 2380f3da6afSVivien Didelot unsigned int ageing_time_max; 2390f3da6afSVivien Didelot 240a0c02161SVivien Didelot /* Dynamically allocated ports, keep last */ 241a0c02161SVivien Didelot size_t num_ports; 242a0c02161SVivien Didelot struct dsa_port ports[]; 243c8f0b869SBen Hutchings }; 244c8f0b869SBen Hutchings 245c8f0b869SBen Hutchings static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p) 246c8f0b869SBen Hutchings { 247b22de490SVivien Didelot return !!(ds == ds->dst->cpu_switch && p == ds->dst->cpu_port); 248c8f0b869SBen Hutchings } 249c8f0b869SBen Hutchings 25060045cbfSAndrew Lunn static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p) 25160045cbfSAndrew Lunn { 25260045cbfSAndrew Lunn return !!((ds->dsa_port_mask) & (1 << p)); 25360045cbfSAndrew Lunn } 25460045cbfSAndrew Lunn 2556cd456f3SVivien Didelot static inline bool dsa_is_normal_port(struct dsa_switch *ds, int p) 2566cd456f3SVivien Didelot { 2576cd456f3SVivien Didelot return !dsa_is_cpu_port(ds, p) && !dsa_is_dsa_port(ds, p); 2586cd456f3SVivien Didelot } 2596cd456f3SVivien Didelot 260d79d2107SGuenter Roeck static inline bool dsa_is_port_initialized(struct dsa_switch *ds, int p) 261d79d2107SGuenter Roeck { 262c8b09808SAndrew Lunn return ds->enabled_port_mask & (1 << p) && ds->ports[p].netdev; 263d79d2107SGuenter Roeck } 264d79d2107SGuenter Roeck 265c8f0b869SBen Hutchings static inline u8 dsa_upstream_port(struct dsa_switch *ds) 266c8f0b869SBen Hutchings { 267c8f0b869SBen Hutchings struct dsa_switch_tree *dst = ds->dst; 268c8f0b869SBen Hutchings 269c8f0b869SBen Hutchings /* 270c8f0b869SBen Hutchings * If this is the root switch (i.e. the switch that connects 271c8f0b869SBen Hutchings * to the CPU), return the cpu port number on this switch. 272c8f0b869SBen Hutchings * Else return the (DSA) port number that connects to the 273c8f0b869SBen Hutchings * switch that is one hop closer to the cpu. 274c8f0b869SBen Hutchings */ 275b22de490SVivien Didelot if (dst->cpu_switch == ds) 276c8f0b869SBen Hutchings return dst->cpu_port; 277c8f0b869SBen Hutchings else 278b22de490SVivien Didelot return ds->rtable[dst->cpu_switch->index]; 279c8f0b869SBen Hutchings } 280c8f0b869SBen Hutchings 281146a3206SVivien Didelot struct switchdev_trans; 282ea70ba98SVivien Didelot struct switchdev_obj; 283146a3206SVivien Didelot struct switchdev_obj_port_fdb; 2848df30255SVivien Didelot struct switchdev_obj_port_mdb; 28576e398a6SVivien Didelot struct switchdev_obj_port_vlan; 286146a3206SVivien Didelot 28704d3a4c6SVivien Didelot #define DSA_NOTIFIER_BRIDGE_JOIN 1 28804d3a4c6SVivien Didelot #define DSA_NOTIFIER_BRIDGE_LEAVE 2 28904d3a4c6SVivien Didelot 29004d3a4c6SVivien Didelot /* DSA_NOTIFIER_BRIDGE_* */ 29104d3a4c6SVivien Didelot struct dsa_notifier_bridge_info { 29204d3a4c6SVivien Didelot struct net_device *br; 29304d3a4c6SVivien Didelot int sw_index; 29404d3a4c6SVivien Didelot int port; 29504d3a4c6SVivien Didelot }; 29604d3a4c6SVivien Didelot 2979d490b4eSVivien Didelot struct dsa_switch_ops { 298c8f0b869SBen Hutchings /* 299c8f0b869SBen Hutchings * Probing and setup. 300c8f0b869SBen Hutchings */ 3010209d144SVivien Didelot const char *(*probe)(struct device *dsa_dev, 3020209d144SVivien Didelot struct device *host_dev, int sw_addr, 3030209d144SVivien Didelot void **priv); 3047b314362SAndrew Lunn 3057b314362SAndrew Lunn enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds); 3067b314362SAndrew Lunn 307c8f0b869SBen Hutchings int (*setup)(struct dsa_switch *ds); 308c8f0b869SBen Hutchings int (*set_addr)(struct dsa_switch *ds, u8 *addr); 3096819563eSFlorian Fainelli u32 (*get_phy_flags)(struct dsa_switch *ds, int port); 310c8f0b869SBen Hutchings 311c8f0b869SBen Hutchings /* 312c8f0b869SBen Hutchings * Access to the switch's PHY registers. 313c8f0b869SBen Hutchings */ 314c8f0b869SBen Hutchings int (*phy_read)(struct dsa_switch *ds, int port, int regnum); 315c8f0b869SBen Hutchings int (*phy_write)(struct dsa_switch *ds, int port, 316c8f0b869SBen Hutchings int regnum, u16 val); 317c8f0b869SBen Hutchings 318c8f0b869SBen Hutchings /* 319ec9436baSFlorian Fainelli * Link state adjustment (called from libphy) 320ec9436baSFlorian Fainelli */ 321ec9436baSFlorian Fainelli void (*adjust_link)(struct dsa_switch *ds, int port, 322ec9436baSFlorian Fainelli struct phy_device *phydev); 323ce31b31cSFlorian Fainelli void (*fixed_link_update)(struct dsa_switch *ds, int port, 324ce31b31cSFlorian Fainelli struct fixed_phy_status *st); 325ec9436baSFlorian Fainelli 326ec9436baSFlorian Fainelli /* 327c8f0b869SBen Hutchings * ethtool hardware statistics. 328c8f0b869SBen Hutchings */ 329c8f0b869SBen Hutchings void (*get_strings)(struct dsa_switch *ds, int port, uint8_t *data); 330c8f0b869SBen Hutchings void (*get_ethtool_stats)(struct dsa_switch *ds, 331c8f0b869SBen Hutchings int port, uint64_t *data); 332c8f0b869SBen Hutchings int (*get_sset_count)(struct dsa_switch *ds); 33324462549SFlorian Fainelli 33424462549SFlorian Fainelli /* 33519e57c4eSFlorian Fainelli * ethtool Wake-on-LAN 33619e57c4eSFlorian Fainelli */ 33719e57c4eSFlorian Fainelli void (*get_wol)(struct dsa_switch *ds, int port, 33819e57c4eSFlorian Fainelli struct ethtool_wolinfo *w); 33919e57c4eSFlorian Fainelli int (*set_wol)(struct dsa_switch *ds, int port, 34019e57c4eSFlorian Fainelli struct ethtool_wolinfo *w); 34119e57c4eSFlorian Fainelli 34219e57c4eSFlorian Fainelli /* 34324462549SFlorian Fainelli * Suspend and resume 34424462549SFlorian Fainelli */ 34524462549SFlorian Fainelli int (*suspend)(struct dsa_switch *ds); 34624462549SFlorian Fainelli int (*resume)(struct dsa_switch *ds); 347b2f2af21SFlorian Fainelli 348b2f2af21SFlorian Fainelli /* 349b2f2af21SFlorian Fainelli * Port enable/disable 350b2f2af21SFlorian Fainelli */ 351b2f2af21SFlorian Fainelli int (*port_enable)(struct dsa_switch *ds, int port, 352b2f2af21SFlorian Fainelli struct phy_device *phy); 353b2f2af21SFlorian Fainelli void (*port_disable)(struct dsa_switch *ds, int port, 354b2f2af21SFlorian Fainelli struct phy_device *phy); 3557905288fSFlorian Fainelli 3567905288fSFlorian Fainelli /* 3577905288fSFlorian Fainelli * EEE setttings 3587905288fSFlorian Fainelli */ 3597905288fSFlorian Fainelli int (*set_eee)(struct dsa_switch *ds, int port, 3607905288fSFlorian Fainelli struct phy_device *phydev, 3617905288fSFlorian Fainelli struct ethtool_eee *e); 3627905288fSFlorian Fainelli int (*get_eee)(struct dsa_switch *ds, int port, 3637905288fSFlorian Fainelli struct ethtool_eee *e); 36451579c3fSGuenter Roeck 3656793abb4SGuenter Roeck /* EEPROM access */ 3666793abb4SGuenter Roeck int (*get_eeprom_len)(struct dsa_switch *ds); 3676793abb4SGuenter Roeck int (*get_eeprom)(struct dsa_switch *ds, 3686793abb4SGuenter Roeck struct ethtool_eeprom *eeprom, u8 *data); 3696793abb4SGuenter Roeck int (*set_eeprom)(struct dsa_switch *ds, 3706793abb4SGuenter Roeck struct ethtool_eeprom *eeprom, u8 *data); 3713d762a0fSGuenter Roeck 3723d762a0fSGuenter Roeck /* 3733d762a0fSGuenter Roeck * Register access. 3743d762a0fSGuenter Roeck */ 3753d762a0fSGuenter Roeck int (*get_regs_len)(struct dsa_switch *ds, int port); 3763d762a0fSGuenter Roeck void (*get_regs)(struct dsa_switch *ds, int port, 3773d762a0fSGuenter Roeck struct ethtool_regs *regs, void *p); 378b73adef6SFlorian Fainelli 379b73adef6SFlorian Fainelli /* 380b73adef6SFlorian Fainelli * Bridge integration 381b73adef6SFlorian Fainelli */ 38234a79f63SVivien Didelot int (*set_ageing_time)(struct dsa_switch *ds, unsigned int msecs); 38371327a4eSVivien Didelot int (*port_bridge_join)(struct dsa_switch *ds, int port, 384a6692754SVivien Didelot struct net_device *bridge); 385f123f2fbSVivien Didelot void (*port_bridge_leave)(struct dsa_switch *ds, int port, 386f123f2fbSVivien Didelot struct net_device *bridge); 38743c44a9fSVivien Didelot void (*port_stp_state_set)(struct dsa_switch *ds, int port, 388b73adef6SFlorian Fainelli u8 state); 389732f794cSVivien Didelot void (*port_fast_age)(struct dsa_switch *ds, int port); 3902a778e1bSVivien Didelot 3912a778e1bSVivien Didelot /* 39211149536SVivien Didelot * VLAN support 39311149536SVivien Didelot */ 394fb2dabadSVivien Didelot int (*port_vlan_filtering)(struct dsa_switch *ds, int port, 395fb2dabadSVivien Didelot bool vlan_filtering); 39676e398a6SVivien Didelot int (*port_vlan_prepare)(struct dsa_switch *ds, int port, 39776e398a6SVivien Didelot const struct switchdev_obj_port_vlan *vlan, 39876e398a6SVivien Didelot struct switchdev_trans *trans); 3994d5770b3SVivien Didelot void (*port_vlan_add)(struct dsa_switch *ds, int port, 40076e398a6SVivien Didelot const struct switchdev_obj_port_vlan *vlan, 40176e398a6SVivien Didelot struct switchdev_trans *trans); 40276e398a6SVivien Didelot int (*port_vlan_del)(struct dsa_switch *ds, int port, 40376e398a6SVivien Didelot const struct switchdev_obj_port_vlan *vlan); 40465aebfc0SVivien Didelot int (*port_vlan_dump)(struct dsa_switch *ds, int port, 40565aebfc0SVivien Didelot struct switchdev_obj_port_vlan *vlan, 40665aebfc0SVivien Didelot int (*cb)(struct switchdev_obj *obj)); 40711149536SVivien Didelot 40811149536SVivien Didelot /* 4092a778e1bSVivien Didelot * Forwarding database 4102a778e1bSVivien Didelot */ 411146a3206SVivien Didelot int (*port_fdb_prepare)(struct dsa_switch *ds, int port, 412146a3206SVivien Didelot const struct switchdev_obj_port_fdb *fdb, 413146a3206SVivien Didelot struct switchdev_trans *trans); 4148497aa61SVivien Didelot void (*port_fdb_add)(struct dsa_switch *ds, int port, 4151f36faf2SVivien Didelot const struct switchdev_obj_port_fdb *fdb, 4161f36faf2SVivien Didelot struct switchdev_trans *trans); 4172a778e1bSVivien Didelot int (*port_fdb_del)(struct dsa_switch *ds, int port, 4188057b3e7SVivien Didelot const struct switchdev_obj_port_fdb *fdb); 419ea70ba98SVivien Didelot int (*port_fdb_dump)(struct dsa_switch *ds, int port, 420ea70ba98SVivien Didelot struct switchdev_obj_port_fdb *fdb, 421ea70ba98SVivien Didelot int (*cb)(struct switchdev_obj *obj)); 4228df30255SVivien Didelot 4238df30255SVivien Didelot /* 4248df30255SVivien Didelot * Multicast database 4258df30255SVivien Didelot */ 4268df30255SVivien Didelot int (*port_mdb_prepare)(struct dsa_switch *ds, int port, 4278df30255SVivien Didelot const struct switchdev_obj_port_mdb *mdb, 4288df30255SVivien Didelot struct switchdev_trans *trans); 4298df30255SVivien Didelot void (*port_mdb_add)(struct dsa_switch *ds, int port, 4308df30255SVivien Didelot const struct switchdev_obj_port_mdb *mdb, 4318df30255SVivien Didelot struct switchdev_trans *trans); 4328df30255SVivien Didelot int (*port_mdb_del)(struct dsa_switch *ds, int port, 4338df30255SVivien Didelot const struct switchdev_obj_port_mdb *mdb); 4348df30255SVivien Didelot int (*port_mdb_dump)(struct dsa_switch *ds, int port, 4358df30255SVivien Didelot struct switchdev_obj_port_mdb *mdb, 4368df30255SVivien Didelot int (*cb)(struct switchdev_obj *obj)); 437bf9f2648SFlorian Fainelli 438bf9f2648SFlorian Fainelli /* 439bf9f2648SFlorian Fainelli * RXNFC 440bf9f2648SFlorian Fainelli */ 441bf9f2648SFlorian Fainelli int (*get_rxnfc)(struct dsa_switch *ds, int port, 442bf9f2648SFlorian Fainelli struct ethtool_rxnfc *nfc, u32 *rule_locs); 443bf9f2648SFlorian Fainelli int (*set_rxnfc)(struct dsa_switch *ds, int port, 444bf9f2648SFlorian Fainelli struct ethtool_rxnfc *nfc); 445f50f2127SFlorian Fainelli 446f50f2127SFlorian Fainelli /* 447f50f2127SFlorian Fainelli * TC integration 448f50f2127SFlorian Fainelli */ 449f50f2127SFlorian Fainelli int (*port_mirror_add)(struct dsa_switch *ds, int port, 450f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror, 451f50f2127SFlorian Fainelli bool ingress); 452f50f2127SFlorian Fainelli void (*port_mirror_del)(struct dsa_switch *ds, int port, 453f50f2127SFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror); 454c8f0b869SBen Hutchings }; 455c8f0b869SBen Hutchings 456ab3d408dSFlorian Fainelli struct dsa_switch_driver { 457ab3d408dSFlorian Fainelli struct list_head list; 458a82f67afSFlorian Fainelli const struct dsa_switch_ops *ops; 459ab3d408dSFlorian Fainelli }; 460ab3d408dSFlorian Fainelli 461ab3d408dSFlorian Fainelli void register_switch_driver(struct dsa_switch_driver *type); 462ab3d408dSFlorian Fainelli void unregister_switch_driver(struct dsa_switch_driver *type); 463b4d2394dSAlexander Duyck struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev); 46414b89f36SFlorian Fainelli struct net_device *dsa_dev_to_net_device(struct device *dev); 465c8f0b869SBen Hutchings 4665aed85ceSFlorian Fainelli static inline bool dsa_uses_tagged_protocol(struct dsa_switch_tree *dst) 4675aed85ceSFlorian Fainelli { 4685075314eSAlexander Duyck return dst->rcv != NULL; 4695aed85ceSFlorian Fainelli } 47083c0afaeSAndrew Lunn 471a0c02161SVivien Didelot struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n); 47283c0afaeSAndrew Lunn void dsa_unregister_switch(struct dsa_switch *ds); 47355ed0ce0SFlorian Fainelli int dsa_register_switch(struct dsa_switch *ds, struct device *dev); 474ea825e70SFlorian Fainelli #ifdef CONFIG_PM_SLEEP 475ea825e70SFlorian Fainelli int dsa_switch_suspend(struct dsa_switch *ds); 476ea825e70SFlorian Fainelli int dsa_switch_resume(struct dsa_switch *ds); 477ea825e70SFlorian Fainelli #else 478ea825e70SFlorian Fainelli static inline int dsa_switch_suspend(struct dsa_switch *ds) 479ea825e70SFlorian Fainelli { 480ea825e70SFlorian Fainelli return 0; 481ea825e70SFlorian Fainelli } 482ea825e70SFlorian Fainelli static inline int dsa_switch_resume(struct dsa_switch *ds) 483ea825e70SFlorian Fainelli { 484ea825e70SFlorian Fainelli return 0; 485ea825e70SFlorian Fainelli } 486ea825e70SFlorian Fainelli #endif /* CONFIG_PM_SLEEP */ 487ea825e70SFlorian Fainelli 48891da11f8SLennert Buytenhek #endif 489