Patch "net: dsa: introduce helpers for iterating through ports using dp" has been added to the 5.15-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    net: dsa: introduce helpers for iterating through ports using dp

to the 5.15-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     net-dsa-introduce-helpers-for-iterating-through-port.patch
and it can be found in the queue-5.15 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 6c8dc66118143fb7f454122b6ca7eced432567fd
Author: Vladimir Oltean <vladimir.oltean@xxxxxxx>
Date:   Wed Oct 20 20:49:49 2021 +0300

    net: dsa: introduce helpers for iterating through ports using dp
    
    [ Upstream commit 82b318983c515f29b8b3a0dad9f6a5fe8a68a7f4 ]
    
    Since the DSA conversion from the ds->ports array into the dst->ports
    list, the DSA API has encouraged driver writers, as well as the core
    itself, to write inefficient code.
    
    Currently, code that wants to filter by a specific type of port when
    iterating, like {!unused, user, cpu, dsa}, uses the dsa_is_*_port helper.
    Under the hood, this uses dsa_to_port which iterates again through
    dst->ports. But the driver iterates through the port list already, so
    the complexity is quadratic for the typical case of a single-switch
    tree.
    
    This patch introduces some iteration helpers where the iterator is
    already a struct dsa_port *dp, so that the other variant of the
    filtering functions, dsa_port_is_{unused,user,cpu_dsa}, can be used
    directly on the iterator. This eliminates the second lookup.
    
    These functions can be used both by the core and by drivers.
    
    Signed-off-by: Vladimir Oltean <vladimir.oltean@xxxxxxx>
    Reviewed-by: Florian Fainelli <f.fainelli@xxxxxxxxx>
    Signed-off-by: David S. Miller <davem@xxxxxxxxxxxxx>
    Stable-dep-of: 120a56b01bee ("net: dsa: mt7530: fix network connectivity with multiple CPU ports")
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/include/net/dsa.h b/include/net/dsa.h
index d784e76113b8d..bec439c4a0859 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -472,6 +472,34 @@ static inline bool dsa_is_user_port(struct dsa_switch *ds, int p)
 	return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_USER;
 }
 
+#define dsa_tree_for_each_user_port(_dp, _dst) \
+	list_for_each_entry((_dp), &(_dst)->ports, list) \
+		if (dsa_port_is_user((_dp)))
+
+#define dsa_switch_for_each_port(_dp, _ds) \
+	list_for_each_entry((_dp), &(_ds)->dst->ports, list) \
+		if ((_dp)->ds == (_ds))
+
+#define dsa_switch_for_each_port_safe(_dp, _next, _ds) \
+	list_for_each_entry_safe((_dp), (_next), &(_ds)->dst->ports, list) \
+		if ((_dp)->ds == (_ds))
+
+#define dsa_switch_for_each_port_continue_reverse(_dp, _ds) \
+	list_for_each_entry_continue_reverse((_dp), &(_ds)->dst->ports, list) \
+		if ((_dp)->ds == (_ds))
+
+#define dsa_switch_for_each_available_port(_dp, _ds) \
+	dsa_switch_for_each_port((_dp), (_ds)) \
+		if (!dsa_port_is_unused((_dp)))
+
+#define dsa_switch_for_each_user_port(_dp, _ds) \
+	dsa_switch_for_each_port((_dp), (_ds)) \
+		if (dsa_port_is_user((_dp)))
+
+#define dsa_switch_for_each_cpu_port(_dp, _ds) \
+	dsa_switch_for_each_port((_dp), (_ds)) \
+		if (dsa_port_is_cpu((_dp)))
+
 static inline u32 dsa_user_ports(struct dsa_switch *ds)
 {
 	u32 mask = 0;



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux