Skip to content

Commit

Permalink
net: dsa: introduce dsa_is_upstream_port and dsa_switch_is_upstream_of
Browse files Browse the repository at this point in the history
In preparation for the new cross-chip notifiers for host addresses,
let's introduce some more topology helpers which we are going to use to
discern switches that are in our path towards the dedicated CPU port
from switches that aren't.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Vladimir Oltean authored and David S. Miller committed Jun 29, 2021
1 parent b117e1e commit 63609c8
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions include/net/dsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,32 @@ static inline unsigned int dsa_upstream_port(struct dsa_switch *ds, int port)
return dsa_towards_port(ds, cpu_dp->ds->index, cpu_dp->index);
}

/* Return true if this is the local port used to reach the CPU port */
static inline bool dsa_is_upstream_port(struct dsa_switch *ds, int port)
{
if (dsa_is_unused_port(ds, port))
return false;

return port == dsa_upstream_port(ds, port);
}

/* Return true if @upstream_ds is an upstream switch of @downstream_ds, meaning
* that the routing port from @downstream_ds to @upstream_ds is also the port
* which @downstream_ds uses to reach its dedicated CPU.
*/
static inline bool dsa_switch_is_upstream_of(struct dsa_switch *upstream_ds,
struct dsa_switch *downstream_ds)
{
int routing_port;

if (upstream_ds == downstream_ds)
return true;

routing_port = dsa_routing_port(downstream_ds, upstream_ds->index);

return dsa_is_upstream_port(downstream_ds, routing_port);
}

static inline bool dsa_port_is_vlan_filtering(const struct dsa_port *dp)
{
const struct dsa_switch *ds = dp->ds;
Expand Down

0 comments on commit 63609c8

Please sign in to comment.