]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - include/net/dsa.h
net: dsa: Pass a port to get_tag_protocol()
[mirror_ubuntu-bionic-kernel.git] / include / net / dsa.h
index 2746741f74cf4c6eadda15acb7f0bfedb8594960..68e232fd4b0f0476e3cd4f658e05bdaf94932454 100644 (file)
@@ -116,13 +116,13 @@ struct dsa_switch_tree {
        struct raw_notifier_head        nh;
 
        /* Tree identifier */
-       u32 tree;
+       unsigned int index;
 
        /* Number of switches attached to this tree */
        struct kref refcount;
 
        /* Has this tree been applied to the hardware? */
-       bool applied;
+       bool setup;
 
        /*
         * Configuration data for the platform device that owns
@@ -164,6 +164,14 @@ struct dsa_mall_tc_entry {
 
 
 struct dsa_port {
+       /* A CPU port is physically connected to a master device.
+        * A user port exposed to userspace has a slave device.
+        */
+       union {
+               struct net_device *master;
+               struct net_device *slave;
+       };
+
        /* CPU port tagging operations used by master or slave devices */
        const struct dsa_device_ops *tag_ops;
 
@@ -172,11 +180,17 @@ struct dsa_port {
        struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev,
                               struct packet_type *pt);
 
+       enum {
+               DSA_PORT_TYPE_UNUSED = 0,
+               DSA_PORT_TYPE_CPU,
+               DSA_PORT_TYPE_DSA,
+               DSA_PORT_TYPE_USER,
+       } type;
+
        struct dsa_switch       *ds;
        unsigned int            index;
        const char              *name;
-       struct dsa_port         *cpu_dp;
-       struct net_device       *netdev;
+       const struct dsa_port   *cpu_dp;
        struct device_node      *dn;
        unsigned int            ageing_time;
        u8                      stp_state;
@@ -195,7 +209,7 @@ struct dsa_switch {
         * Parent switch tree, and switch index.
         */
        struct dsa_switch_tree  *dst;
-       int                     index;
+       unsigned int            index;
 
        /* Listener for switch fabric events */
        struct notifier_block   nb;
@@ -226,9 +240,6 @@ struct dsa_switch {
        /*
         * Slave mii_bus and devices for the individual ports.
         */
-       u32                     dsa_port_mask;
-       u32                     cpu_port_mask;
-       u32                     enabled_port_mask;
        u32                     phys_mii_mask;
        struct mii_bus          *slave_mii_bus;
 
@@ -247,19 +258,41 @@ struct dsa_switch {
        struct dsa_port ports[];
 };
 
+static inline const struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p)
+{
+       return &ds->ports[p];
+}
+
+static inline bool dsa_is_unused_port(struct dsa_switch *ds, int p)
+{
+       return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_UNUSED;
+}
+
 static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
 {
-       return !!(ds->cpu_port_mask & (1 << p));
+       return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_CPU;
 }
 
 static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p)
 {
-       return !!((ds->dsa_port_mask) & (1 << p));
+       return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_DSA;
 }
 
-static inline bool dsa_is_normal_port(struct dsa_switch *ds, int p)
+static inline bool dsa_is_user_port(struct dsa_switch *ds, int p)
 {
-       return !dsa_is_cpu_port(ds, p) && !dsa_is_dsa_port(ds, p);
+       return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_USER;
+}
+
+static inline u32 dsa_user_ports(struct dsa_switch *ds)
+{
+       u32 mask = 0;
+       int p;
+
+       for (p = 0; p < ds->num_ports; p++)
+               if (dsa_is_user_port(ds, p))
+                       mask |= BIT(p);
+
+       return mask;
 }
 
 static inline u8 dsa_upstream_port(struct dsa_switch *ds)
@@ -288,7 +321,8 @@ struct dsa_switch_ops {
                                  struct device *host_dev, int sw_addr,
                                  void **priv);
 
-       enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds);
+       enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds,
+                                                 int port);
 
        int     (*setup)(struct dsa_switch *ds);
        u32     (*get_phy_flags)(struct dsa_switch *ds, int port);