mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vivien Didelot <vivien.didelot@gmail.com>
To: "David S. Miller" <davem@davemloft.net>
Cc: linux-kernel@vger.kernel.org,
	Vivien Didelot <vivien.didelot@gmail.com>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Andrew Lunn <andrew@lunn.ch>,
	netdev@vger.kernel.org
Subject: [PATCH net-next v2 12/16] net: dsa: mv88e6xxx: use ports list to map port VLAN
Date: Mon, 21 Oct 2019 16:51:26 -0400	[thread overview]
Message-ID: <20191021205130.304149-13-vivien.didelot@gmail.com> (raw)
In-Reply-To: <20191021205130.304149-1-vivien.didelot@gmail.com>

Instead of digging into the other dsa_switch structures of the fabric
and relying too much on the dsa_to_port helper, use the new list of
switch fabric ports to define the mask of the local ports allowed to
receive frames from another port of the fabric.

Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
---
 drivers/net/dsa/mv88e6xxx/chip.c | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index 510ccdc2d03c..af8943142053 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -1057,35 +1057,43 @@ static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
 	return 0;
 }
 
+/* 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 = NULL;
+	struct dsa_switch *ds = chip->ds;
+	struct dsa_switch_tree *dst = ds->dst;
 	struct net_device *br;
+	struct dsa_port *dp;
+	bool found = false;
 	u16 pvlan;
-	int i;
 
-	if (dev < DSA_MAX_SWITCHES)
-		ds = chip->ds->dst->ds[dev];
+	list_for_each_entry(dp, &dst->ports, list) {
+		if (dp->ds->index == dev && dp->index == port) {
+			found = true;
+			break;
+		}
+	}
 
 	/* Prevent frames from unknown switch or port */
-	if (!ds || port >= ds->num_ports)
+	if (!found)
 		return 0;
 
 	/* Frames from DSA links and CPU ports can egress any local port */
-	if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
+	if (dp->type == DSA_PORT_TYPE_CPU || dp->type == DSA_PORT_TYPE_DSA)
 		return mv88e6xxx_port_mask(chip);
 
-	br = dsa_to_port(ds, port)->bridge_dev;
+	br = dp->bridge_dev;
 	pvlan = 0;
 
 	/* Frames from user ports can egress any local DSA links and CPU ports,
 	 * as well as any local member of their bridge group.
 	 */
-	for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
-		if (dsa_is_cpu_port(chip->ds, i) ||
-		    dsa_is_dsa_port(chip->ds, i) ||
-		    (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
-			pvlan |= BIT(i);
+	list_for_each_entry(dp, &dst->ports, list)
+		if (dp->ds == ds &&
+		    (dp->type == DSA_PORT_TYPE_CPU ||
+		     dp->type == DSA_PORT_TYPE_DSA ||
+		     (br && dp->bridge_dev == br)))
+			pvlan |= BIT(dp->index);
 
 	return pvlan;
 }
-- 
2.23.0


  parent reply	other threads:[~2019-10-21 20:52 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-21 20:51 [PATCH net-next v2 00/16] net: dsa: turn arrays of ports into a list Vivien Didelot
2019-10-21 20:51 ` [PATCH net-next v2 01/16] net: dsa: use dsa_to_port helper everywhere Vivien Didelot
2019-10-21 20:51 ` [PATCH net-next v2 02/16] net: dsa: add ports list in the switch fabric Vivien Didelot
2019-10-21 20:51 ` [PATCH net-next v2 03/16] net: dsa: use ports list in dsa_to_port Vivien Didelot
2019-10-21 20:51 ` [PATCH net-next v2 04/16] net: dsa: use ports list to find slave Vivien Didelot
2019-10-21 20:51 ` [PATCH net-next v2 05/16] net: dsa: use ports list to setup switches Vivien Didelot
2019-10-21 20:51 ` [PATCH net-next v2 06/16] net: dsa: use ports list for routing table setup Vivien Didelot
2019-10-21 20:51 ` [PATCH net-next v2 07/16] net: dsa: use ports list to find a port by node Vivien Didelot
2019-10-21 20:51 ` [PATCH net-next v2 08/16] net: dsa: use ports list to setup multiple master devices Vivien Didelot
2019-10-21 20:51 ` [PATCH net-next v2 09/16] net: dsa: use ports list to find first CPU port Vivien Didelot
2019-10-21 20:51 ` [PATCH net-next v2 10/16] net: dsa: use ports list to setup default " Vivien Didelot
2019-10-21 20:51 ` [PATCH net-next v2 11/16] net: dsa: mv88e6xxx: silently skip PVT ops Vivien Didelot
2019-10-21 20:51 ` Vivien Didelot [this message]
2019-10-21 20:51 ` [PATCH net-next v2 13/16] net: dsa: mv88e6xxx: use ports list to map bridge Vivien Didelot
2019-10-21 20:51 ` [PATCH net-next v2 14/16] net: dsa: sja1105: register switch before assigning port private data Vivien Didelot
2019-10-21 20:51 ` [PATCH net-next v2 15/16] net: dsa: allocate ports on touch Vivien Didelot
2019-10-21 20:51 ` [PATCH net-next v2 16/16] net: dsa: remove dsa_switch_alloc helper Vivien Didelot
2019-10-21 22:34 ` [PATCH net-next v2 00/16] net: dsa: turn arrays of ports into a list Florian Fainelli
2019-10-22 11:43 ` Michal Vokáč
2019-10-22 19:41 ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191021205130.304149-13-vivien.didelot@gmail.com \
    --to=vivien.didelot@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®