Skip to content

Commit 63609c8

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: introduce dsa_is_upstream_port and dsa_switch_is_upstream_of
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b117e1e commit 63609c8

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

include/net/dsa.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,32 @@ static inline unsigned int dsa_upstream_port(struct dsa_switch *ds, int port)
491491
return dsa_towards_port(ds, cpu_dp->ds->index, cpu_dp->index);
492492
}
493493

494+
/* Return true if this is the local port used to reach the CPU port */
495+
static inline bool dsa_is_upstream_port(struct dsa_switch *ds, int port)
496+
{
497+
if (dsa_is_unused_port(ds, port))
498+
return false;
499+
500+
return port == dsa_upstream_port(ds, port);
501+
}
502+
503+
/* Return true if @upstream_ds is an upstream switch of @downstream_ds, meaning
504+
* that the routing port from @downstream_ds to @upstream_ds is also the port
505+
* which @downstream_ds uses to reach its dedicated CPU.
506+
*/
507+
static inline bool dsa_switch_is_upstream_of(struct dsa_switch *upstream_ds,
508+
struct dsa_switch *downstream_ds)
509+
{
510+
int routing_port;
511+
512+
if (upstream_ds == downstream_ds)
513+
return true;
514+
515+
routing_port = dsa_routing_port(downstream_ds, upstream_ds->index);
516+
517+
return dsa_is_upstream_port(downstream_ds, routing_port);
518+
}
519+
494520
static inline bool dsa_port_is_vlan_filtering(const struct dsa_port *dp)
495521
{
496522
const struct dsa_switch *ds = dp->ds;

0 commit comments

Comments
 (0)