@@ -1378,42 +1378,50 @@ static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
return 0;
}
+static struct dsa_port *mv88e6xxx_find_port(struct dsa_switch_tree *dst,
+ int sw_index, int port)
+{
+ struct dsa_port *dp;
+
+ list_for_each_entry(dp, &dst->ports, list)
+ if (dp->ds->index == sw_index && dp->index == port)
+ return dp;
+
+ return NULL;
+}
+
+static struct dsa_port *
+mv88e6xxx_find_port_by_bridge_num(struct dsa_switch_tree *dst,
+ unsigned int bridge_num)
+{
+ struct dsa_port *dp;
+
+ list_for_each_entry(dp, &dst->ports, list)
+ if (dsa_port_bridge_num_get(dp) == bridge_num)
+ return dp;
+
+ return NULL;
+}
+
/* Mask of the local ports allowed to receive frames from a given fabric port */
static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
{
struct dsa_switch *ds = chip->ds;
struct dsa_switch_tree *dst = ds->dst;
struct dsa_port *dp, *other_dp;
- bool found = false;
u16 pvlan;
- /* dev is a physical switch */
if (dev <= dst->last_switch) {
- list_for_each_entry(dp, &dst->ports, list) {
- if (dp->ds->index == dev && dp->index == port) {
- /* dp might be a DSA link or a user port, so it
- * might or might not have a bridge.
- * Use the "found" variable for both cases.
- */
- found = true;
- break;
- }
- }
- /* dev is a virtual bridge */
+ /* dev is a physical switch */
+ dp = mv88e6xxx_find_port(dst, dev, port);
} else {
- list_for_each_entry(dp, &dst->ports, list) {
- unsigned int bridge_num = dsa_port_bridge_num_get(dp);
-
- if (bridge_num + dst->last_switch != dev)
- continue;
-
- found = true;
- break;
- }
+ /* dev is a virtual bridge */
+ dp = mv88e6xxx_find_port_by_bridge_num(dst,
+ dev - dst->last_switch);
}
/* Prevent frames from unknown switch or virtual bridge */
- if (!found)
+ if (!dp)
return 0;
/* Frames from DSA links and CPU ports can egress any local port */