linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 00/16] net: dsa: turn arrays of ports into a list
@ 2019-10-20  3:19 Vivien Didelot
  2019-10-20  3:19 ` [PATCH net-next 01/16] net: dsa: use dsa_to_port helper everywhere Vivien Didelot
                   ` (16 more replies)
  0 siblings, 17 replies; 44+ messages in thread
From: Vivien Didelot @ 2019-10-20  3:19 UTC (permalink / raw)
  To: David S. Miller
  Cc: linux-kernel, Vivien Didelot, Florian Fainelli, Andrew Lunn, netdev

The dsa_switch structure represents the physical switch device itself,
and is allocated by the driver. The dsa_switch_tree and dsa_port structures
represent the logical switch fabric (eventually composed of multiple switch
devices) and its ports, and are allocated by the DSA core.

This branch lists the logical ports directly in the fabric which simplifies
the iteration over all ports when assigning the default CPU port or configuring
the D in DSA in drivers like mv88e6xxx.

This also removes the unique dst->cpu_dp pointer and is a first step towards
supporting multiple CPU ports and dropping the DSA_MAX_PORTS limitation.

Because the dsa_port structures are not tight to the dsa_switch structure
anymore, we do not need to provide an helper for the drivers to allocate a
switch structure. Like in many other subsystems, drivers can now embed their
dsa_switch structure as they wish into their private structure. This will
be particularly interesting for the Broadcom drivers which were currently
limited by the dynamically allocated array of DSA ports.

The series implements the list of dsa_port structures, makes use of it,
then drops dst->cpu_dp and the dsa_switch_alloc helper.


Vivien Didelot (16):
  net: dsa: use dsa_to_port helper everywhere
  net: dsa: add ports list in the switch fabric
  net: dsa: use ports list in dsa_to_port
  net: dsa: use ports list to find slave
  net: dsa: use ports list to setup switches
  net: dsa: use ports list for routing table setup
  net: dsa: use ports list to find a port by node
  net: dsa: use ports list to setup multiple master devices
  net: dsa: use ports list to find first CPU port
  net: dsa: use ports list to setup default CPU port
  net: dsa: mv88e6xxx: silently skip PVT ops
  net: dsa: mv88e6xxx: use ports list to map port VLAN
  net: dsa: mv88e6xxx: use ports list to map bridge
  net: dsa: sja1105: register switch before assigning port private data
  net: dsa: allocate ports on touch
  net: dsa: remove dsa_switch_alloc helper

 drivers/net/dsa/b53/b53_common.c       |  11 +-
 drivers/net/dsa/bcm_sf2.c              |   8 +-
 drivers/net/dsa/bcm_sf2_cfp.c          |   6 +-
 drivers/net/dsa/dsa_loop.c             |   5 +-
 drivers/net/dsa/lan9303-core.c         |   4 +-
 drivers/net/dsa/lantiq_gswip.c         |   4 +-
 drivers/net/dsa/microchip/ksz_common.c |   5 +-
 drivers/net/dsa/mt7530.c               |  17 +-
 drivers/net/dsa/mv88e6060.c            |   4 +-
 drivers/net/dsa/mv88e6xxx/chip.c       |  87 ++++----
 drivers/net/dsa/qca8k.c                |   7 +-
 drivers/net/dsa/realtek-smi-core.c     |   5 +-
 drivers/net/dsa/sja1105/sja1105_main.c |  37 ++--
 drivers/net/dsa/vitesse-vsc73xx-core.c |   5 +-
 include/net/dsa.h                      |  26 ++-
 net/dsa/dsa.c                          |   8 +-
 net/dsa/dsa2.c                         | 282 +++++++++++++------------
 net/dsa/dsa_priv.h                     |  23 +-
 net/dsa/switch.c                       |   4 +-
 net/dsa/tag_8021q.c                    |   6 +-
 20 files changed, 297 insertions(+), 257 deletions(-)

-- 
2.23.0


^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH net-next 01/16] net: dsa: use dsa_to_port helper everywhere
  2019-10-20  3:19 [PATCH net-next 00/16] net: dsa: turn arrays of ports into a list Vivien Didelot
@ 2019-10-20  3:19 ` Vivien Didelot
  2019-10-21  2:34   ` Florian Fainelli
  2019-10-21 12:31   ` Andrew Lunn
  2019-10-20  3:19 ` [PATCH net-next 02/16] net: dsa: add ports list in the switch fabric Vivien Didelot
                   ` (15 subsequent siblings)
  16 siblings, 2 replies; 44+ messages in thread
From: Vivien Didelot @ 2019-10-20  3:19 UTC (permalink / raw)
  To: David S. Miller
  Cc: linux-kernel, Vivien Didelot, Florian Fainelli, Andrew Lunn, netdev

Do not let the drivers access the ds->ports static array directly
while there is a dsa_to_port helper for this purpose.

At the same time, un-const this helper since the SJA1105 driver
assigns the priv member of the returned dsa_port structure.

Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
---
 drivers/net/dsa/b53/b53_common.c       |  6 +++---
 drivers/net/dsa/bcm_sf2.c              |  8 ++++----
 drivers/net/dsa/bcm_sf2_cfp.c          |  6 +++---
 drivers/net/dsa/mt7530.c               | 12 ++++++------
 drivers/net/dsa/mv88e6xxx/chip.c       | 10 +++++-----
 drivers/net/dsa/qca8k.c                |  2 +-
 drivers/net/dsa/sja1105/sja1105_main.c | 18 +++++++++---------
 include/net/dsa.h                      |  2 +-
 net/dsa/dsa.c                          |  8 +++++---
 net/dsa/dsa2.c                         |  4 ++--
 net/dsa/switch.c                       |  4 ++--
 net/dsa/tag_8021q.c                    |  6 +++---
 12 files changed, 44 insertions(+), 42 deletions(-)

diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index 526ba2ab66f1..9ba91f1370ac 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -524,7 +524,7 @@ int b53_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy)
 	if (!dsa_is_user_port(ds, port))
 		return 0;
 
-	cpu_port = ds->ports[port].cpu_dp->index;
+	cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
 
 	if (dev->ops->irq_enable)
 		ret = dev->ops->irq_enable(dev, port);
@@ -1629,7 +1629,7 @@ EXPORT_SYMBOL(b53_fdb_dump);
 int b53_br_join(struct dsa_switch *ds, int port, struct net_device *br)
 {
 	struct b53_device *dev = ds->priv;
-	s8 cpu_port = ds->ports[port].cpu_dp->index;
+	s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
 	u16 pvlan, reg;
 	unsigned int i;
 
@@ -1675,7 +1675,7 @@ void b53_br_leave(struct dsa_switch *ds, int port, struct net_device *br)
 {
 	struct b53_device *dev = ds->priv;
 	struct b53_vlan *vl = &dev->vlans[0];
-	s8 cpu_port = ds->ports[port].cpu_dp->index;
+	s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
 	unsigned int i;
 	u16 pvlan, reg, pvid;
 
diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index 26509fa37a50..c068a3b7207b 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -662,7 +662,7 @@ static void bcm_sf2_sw_fixed_state(struct dsa_switch *ds, int port,
 		 * state machine and make it go in PHY_FORCING state instead.
 		 */
 		if (!status->link)
-			netif_carrier_off(ds->ports[port].slave);
+			netif_carrier_off(dsa_to_port(ds, port)->slave);
 		status->duplex = DUPLEX_FULL;
 	} else {
 		status->link = true;
@@ -728,7 +728,7 @@ static int bcm_sf2_sw_resume(struct dsa_switch *ds)
 static void bcm_sf2_sw_get_wol(struct dsa_switch *ds, int port,
 			       struct ethtool_wolinfo *wol)
 {
-	struct net_device *p = ds->ports[port].cpu_dp->master;
+	struct net_device *p = dsa_to_port(ds, port)->cpu_dp->master;
 	struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
 	struct ethtool_wolinfo pwol = { };
 
@@ -752,9 +752,9 @@ static void bcm_sf2_sw_get_wol(struct dsa_switch *ds, int port,
 static int bcm_sf2_sw_set_wol(struct dsa_switch *ds, int port,
 			      struct ethtool_wolinfo *wol)
 {
-	struct net_device *p = ds->ports[port].cpu_dp->master;
+	struct net_device *p = dsa_to_port(ds, port)->cpu_dp->master;
 	struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
-	s8 cpu_port = ds->ports[port].cpu_dp->index;
+	s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
 	struct ethtool_wolinfo pwol =  { };
 
 	if (p->ethtool_ops->get_wol)
diff --git a/drivers/net/dsa/bcm_sf2_cfp.c b/drivers/net/dsa/bcm_sf2_cfp.c
index d264776a95a3..f3f0c3f07391 100644
--- a/drivers/net/dsa/bcm_sf2_cfp.c
+++ b/drivers/net/dsa/bcm_sf2_cfp.c
@@ -821,7 +821,7 @@ static int bcm_sf2_cfp_rule_insert(struct dsa_switch *ds, int port,
 				   struct ethtool_rx_flow_spec *fs)
 {
 	struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
-	s8 cpu_port = ds->ports[port].cpu_dp->index;
+	s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
 	__u64 ring_cookie = fs->ring_cookie;
 	unsigned int queue_num, port_num;
 	int ret;
@@ -1049,7 +1049,7 @@ static int bcm_sf2_cfp_rule_get_all(struct bcm_sf2_priv *priv,
 int bcm_sf2_get_rxnfc(struct dsa_switch *ds, int port,
 		      struct ethtool_rxnfc *nfc, u32 *rule_locs)
 {
-	struct net_device *p = ds->ports[port].cpu_dp->master;
+	struct net_device *p = dsa_to_port(ds, port)->cpu_dp->master;
 	struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
 	int ret = 0;
 
@@ -1092,7 +1092,7 @@ int bcm_sf2_get_rxnfc(struct dsa_switch *ds, int port,
 int bcm_sf2_set_rxnfc(struct dsa_switch *ds, int port,
 		      struct ethtool_rxnfc *nfc)
 {
-	struct net_device *p = ds->ports[port].cpu_dp->master;
+	struct net_device *p = dsa_to_port(ds, port)->cpu_dp->master;
 	struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
 	int ret = 0;
 
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index 1d8d36de4d20..a91293e47a57 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -862,7 +862,7 @@ mt7530_port_set_vlan_unaware(struct dsa_switch *ds, int port)
 
 	for (i = 0; i < MT7530_NUM_PORTS; i++) {
 		if (dsa_is_user_port(ds, i) &&
-		    dsa_port_is_vlan_filtering(&ds->ports[i])) {
+		    dsa_port_is_vlan_filtering(dsa_to_port(ds, i))) {
 			all_user_ports_removed = false;
 			break;
 		}
@@ -922,7 +922,7 @@ mt7530_port_bridge_leave(struct dsa_switch *ds, int port,
 		 * other port is still a VLAN-aware port.
 		 */
 		if (dsa_is_user_port(ds, i) && i != port &&
-		   !dsa_port_is_vlan_filtering(&ds->ports[i])) {
+		   !dsa_port_is_vlan_filtering(dsa_to_port(ds, i))) {
 			if (dsa_to_port(ds, i)->bridge_dev != bridge)
 				continue;
 			if (priv->ports[i].enable)
@@ -1165,7 +1165,7 @@ mt7530_port_vlan_add(struct dsa_switch *ds, int port,
 	/* The port is kept as VLAN-unaware if bridge with vlan_filtering not
 	 * being set.
 	 */
-	if (!dsa_port_is_vlan_filtering(&ds->ports[port]))
+	if (!dsa_port_is_vlan_filtering(dsa_to_port(ds, port)))
 		return;
 
 	mutex_lock(&priv->reg_mutex);
@@ -1196,7 +1196,7 @@ mt7530_port_vlan_del(struct dsa_switch *ds, int port,
 	/* The port is kept as VLAN-unaware if bridge with vlan_filtering not
 	 * being set.
 	 */
-	if (!dsa_port_is_vlan_filtering(&ds->ports[port]))
+	if (!dsa_port_is_vlan_filtering(dsa_to_port(ds, port)))
 		return 0;
 
 	mutex_lock(&priv->reg_mutex);
@@ -1252,7 +1252,7 @@ mt7530_setup(struct dsa_switch *ds)
 	 * controller also is the container for two GMACs nodes representing
 	 * as two netdev instances.
 	 */
-	dn = ds->ports[MT7530_CPU_PORT].master->dev.of_node->parent;
+	dn = dsa_to_port(ds, MT7530_CPU_PORT)->master->dev.of_node->parent;
 
 	if (priv->id == ID_MT7530) {
 		priv->ethernet = syscon_node_to_regmap(dn);
@@ -1340,7 +1340,7 @@ mt7530_setup(struct dsa_switch *ds)
 
 	if (!dsa_is_unused_port(ds, 5)) {
 		priv->p5_intf_sel = P5_INTF_SEL_GMAC5;
-		interface = of_get_phy_mode(ds->ports[5].dn);
+		interface = of_get_phy_mode(dsa_to_port(ds, 5)->dn);
 	} else {
 		/* Scan the ethernet nodes. look for GMAC1, lookup used phy */
 		for_each_child_of_node(dn, mac_np) {
diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index 6787d560e9e3..d67deec77452 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -1075,7 +1075,7 @@ static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
 	if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
 		return mv88e6xxx_port_mask(chip);
 
-	br = ds->ports[port].bridge_dev;
+	br = dsa_to_port(ds, port)->bridge_dev;
 	pvlan = 0;
 
 	/* Frames from user ports can egress any local DSA links and CPU ports,
@@ -1402,7 +1402,7 @@ static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
 			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
 				continue;
 
-			if (!ds->ports[i].slave)
+			if (!dsa_to_port(ds, i)->slave)
 				continue;
 
 			if (vlan.member[i] ==
@@ -1410,7 +1410,7 @@ static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
 				continue;
 
 			if (dsa_to_port(ds, i)->bridge_dev ==
-			    ds->ports[port].bridge_dev)
+			    dsa_to_port(ds, port)->bridge_dev)
 				break; /* same bridge, check next VLAN */
 
 			if (!dsa_to_port(ds, i)->bridge_dev)
@@ -2042,7 +2042,7 @@ static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
 
 	/* Remap the Port VLAN of each local bridge group member */
 	for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
-		if (chip->ds->ports[port].bridge_dev == br) {
+		if (dsa_to_port(chip->ds, port)->bridge_dev == br) {
 			err = mv88e6xxx_port_vlan_map(chip, port);
 			if (err)
 				return err;
@@ -2059,7 +2059,7 @@ static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
 			break;
 
 		for (port = 0; port < ds->num_ports; ++port) {
-			if (ds->ports[port].bridge_dev == br) {
+			if (dsa_to_port(ds, port)->bridge_dev == br) {
 				err = mv88e6xxx_pvt_map(chip, dev, port);
 				if (err)
 					return err;
diff --git a/drivers/net/dsa/qca8k.c b/drivers/net/dsa/qca8k.c
index b00274caae4f..71e44c8763b8 100644
--- a/drivers/net/dsa/qca8k.c
+++ b/drivers/net/dsa/qca8k.c
@@ -661,7 +661,7 @@ qca8k_setup(struct dsa_switch *ds)
 		return ret;
 
 	/* Initialize CPU port pad mode (xMII type, delays...) */
-	phy_mode = of_get_phy_mode(ds->ports[QCA8K_CPU_PORT].dn);
+	phy_mode = of_get_phy_mode(dsa_to_port(ds, QCA8K_CPU_PORT)->dn);
 	if (phy_mode < 0) {
 		pr_err("Can't find phy-mode for master device\n");
 		return phy_mode;
diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c
index 2ffe642cf54b..4b0cb779f187 100644
--- a/drivers/net/dsa/sja1105/sja1105_main.c
+++ b/drivers/net/dsa/sja1105/sja1105_main.c
@@ -1058,7 +1058,7 @@ int sja1105pqrs_fdb_add(struct dsa_switch *ds, int port,
 	l2_lookup.vlanid = vid;
 	l2_lookup.iotag = SJA1105_S_TAG;
 	l2_lookup.mask_macaddr = GENMASK_ULL(ETH_ALEN * 8 - 1, 0);
-	if (dsa_port_is_vlan_filtering(&ds->ports[port])) {
+	if (dsa_port_is_vlan_filtering(dsa_to_port(ds, port))) {
 		l2_lookup.mask_vlanid = VLAN_VID_MASK;
 		l2_lookup.mask_iotag = BIT(0);
 	} else {
@@ -1121,7 +1121,7 @@ int sja1105pqrs_fdb_del(struct dsa_switch *ds, int port,
 	l2_lookup.vlanid = vid;
 	l2_lookup.iotag = SJA1105_S_TAG;
 	l2_lookup.mask_macaddr = GENMASK_ULL(ETH_ALEN * 8 - 1, 0);
-	if (dsa_port_is_vlan_filtering(&ds->ports[port])) {
+	if (dsa_port_is_vlan_filtering(dsa_to_port(ds, port))) {
 		l2_lookup.mask_vlanid = VLAN_VID_MASK;
 		l2_lookup.mask_iotag = BIT(0);
 	} else {
@@ -1167,7 +1167,7 @@ static int sja1105_fdb_add(struct dsa_switch *ds, int port,
 	 * for what gets printed in 'bridge fdb show'.  In the case of zero,
 	 * no VID gets printed at all.
 	 */
-	if (!dsa_port_is_vlan_filtering(&ds->ports[port]))
+	if (!dsa_port_is_vlan_filtering(dsa_to_port(ds, port)))
 		vid = 0;
 
 	return priv->info->fdb_add_cmd(ds, port, addr, vid);
@@ -1178,7 +1178,7 @@ static int sja1105_fdb_del(struct dsa_switch *ds, int port,
 {
 	struct sja1105_private *priv = ds->priv;
 
-	if (!dsa_port_is_vlan_filtering(&ds->ports[port]))
+	if (!dsa_port_is_vlan_filtering(dsa_to_port(ds, port)))
 		vid = 0;
 
 	return priv->info->fdb_del_cmd(ds, port, addr, vid);
@@ -1217,7 +1217,7 @@ static int sja1105_fdb_dump(struct dsa_switch *ds, int port,
 		u64_to_ether_addr(l2_lookup.macaddr, macaddr);
 
 		/* We need to hide the dsa_8021q VLANs from the user. */
-		if (!dsa_port_is_vlan_filtering(&ds->ports[port]))
+		if (!dsa_port_is_vlan_filtering(dsa_to_port(ds, port)))
 			l2_lookup.vlanid = 0;
 		cb(macaddr, l2_lookup.vlanid, l2_lookup.lockeds, data);
 	}
@@ -1704,7 +1704,7 @@ static int sja1105_port_enable(struct dsa_switch *ds, int port,
 	if (!dsa_is_user_port(ds, port))
 		return 0;
 
-	slave = ds->ports[port].slave;
+	slave = dsa_to_port(ds, port)->slave;
 
 	slave->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
 
@@ -1736,7 +1736,7 @@ static int sja1105_mgmt_xmit(struct dsa_switch *ds, int port, int slot,
 	}
 
 	/* Transfer skb to the host port. */
-	dsa_enqueue_skb(skb, ds->ports[port].slave);
+	dsa_enqueue_skb(skb, dsa_to_port(ds, port)->slave);
 
 	/* Wait until the switch has processed the frame */
 	do {
@@ -2061,8 +2061,8 @@ static int sja1105_probe(struct spi_device *spi)
 	for (i = 0; i < SJA1105_NUM_PORTS; i++) {
 		struct sja1105_port *sp = &priv->ports[i];
 
-		ds->ports[i].priv = sp;
-		sp->dp = &ds->ports[i];
+		dsa_to_port(ds, i)->priv = sp;
+		sp->dp = dsa_to_port(ds, i);
 		sp->data = tagger_data;
 	}
 	mutex_init(&priv->ptp_data.lock);
diff --git a/include/net/dsa.h b/include/net/dsa.h
index 8c3ea0530f65..2e4fe2f8962b 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -278,7 +278,7 @@ struct dsa_switch {
 	struct dsa_port ports[];
 };
 
-static inline const struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p)
+static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p)
 {
 	return &ds->ports[p];
 }
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 43120a3fb06f..a5545762f5e7 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -246,7 +246,9 @@ static int dsa_switch_rcv(struct sk_buff *skb, struct net_device *dev,
 #ifdef CONFIG_PM_SLEEP
 static bool dsa_is_port_initialized(struct dsa_switch *ds, int p)
 {
-	return dsa_is_user_port(ds, p) && ds->ports[p].slave;
+	const struct dsa_port *dp = dsa_to_port(ds, p);
+
+	return dp->type == DSA_PORT_TYPE_USER && dp->slave;
 }
 
 int dsa_switch_suspend(struct dsa_switch *ds)
@@ -258,7 +260,7 @@ int dsa_switch_suspend(struct dsa_switch *ds)
 		if (!dsa_is_port_initialized(ds, i))
 			continue;
 
-		ret = dsa_slave_suspend(ds->ports[i].slave);
+		ret = dsa_slave_suspend(dsa_to_port(ds, i)->slave);
 		if (ret)
 			return ret;
 	}
@@ -285,7 +287,7 @@ int dsa_switch_resume(struct dsa_switch *ds)
 		if (!dsa_is_port_initialized(ds, i))
 			continue;
 
-		ret = dsa_slave_resume(ds->ports[i].slave);
+		ret = dsa_slave_resume(dsa_to_port(ds, i)->slave);
 		if (ret)
 			return ret;
 	}
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 716d265ba8ca..1716535167ee 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -708,7 +708,7 @@ static int dsa_switch_parse_ports_of(struct dsa_switch *ds,
 			goto out_put_node;
 		}
 
-		dp = &ds->ports[reg];
+		dp = dsa_to_port(ds, reg);
 
 		err = dsa_port_parse_of(dp, port);
 		if (err)
@@ -787,7 +787,7 @@ static int dsa_switch_parse_ports(struct dsa_switch *ds,
 	for (i = 0; i < DSA_MAX_PORTS; i++) {
 		name = cd->port_names[i];
 		dev = cd->netdev[i];
-		dp = &ds->ports[i];
+		dp = dsa_to_port(ds, i);
 
 		if (!name)
 			continue;
diff --git a/net/dsa/switch.c b/net/dsa/switch.c
index 6a9607518823..df4abe897ed6 100644
--- a/net/dsa/switch.c
+++ b/net/dsa/switch.c
@@ -20,7 +20,7 @@ static unsigned int dsa_switch_fastest_ageing_time(struct dsa_switch *ds,
 	int i;
 
 	for (i = 0; i < ds->num_ports; ++i) {
-		struct dsa_port *dp = &ds->ports[i];
+		struct dsa_port *dp = dsa_to_port(ds, i);
 
 		if (dp->ageing_time && dp->ageing_time < ageing_time)
 			ageing_time = dp->ageing_time;
@@ -98,7 +98,7 @@ static int dsa_switch_bridge_leave(struct dsa_switch *ds,
 	if (unset_vlan_filtering) {
 		struct switchdev_trans trans = {0};
 
-		err = dsa_port_vlan_filtering(&ds->ports[info->port],
+		err = dsa_port_vlan_filtering(dsa_to_port(ds, info->port),
 					      false, &trans);
 		if (err && err != EOPNOTSUPP)
 			return err;
diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c
index 9c1cc2482b68..bf91fc55fc44 100644
--- a/net/dsa/tag_8021q.c
+++ b/net/dsa/tag_8021q.c
@@ -103,7 +103,7 @@ static int dsa_8021q_restore_pvid(struct dsa_switch *ds, int port)
 	if (!dsa_is_user_port(ds, port))
 		return 0;
 
-	slave = ds->ports[port].slave;
+	slave = dsa_to_port(ds, port)->slave;
 
 	err = br_vlan_get_pvid(slave, &pvid);
 	if (err < 0)
@@ -118,7 +118,7 @@ static int dsa_8021q_restore_pvid(struct dsa_switch *ds, int port)
 		return err;
 	}
 
-	return dsa_port_vid_add(&ds->ports[port], pvid, vinfo.flags);
+	return dsa_port_vid_add(dsa_to_port(ds, port), pvid, vinfo.flags);
 }
 
 /* If @enabled is true, installs @vid with @flags into the switch port's HW
@@ -130,7 +130,7 @@ static int dsa_8021q_restore_pvid(struct dsa_switch *ds, int port)
 static int dsa_8021q_vid_apply(struct dsa_switch *ds, int port, u16 vid,
 			       u16 flags, bool enabled)
 {
-	struct dsa_port *dp = &ds->ports[port];
+	struct dsa_port *dp = dsa_to_port(ds, port);
 	struct bridge_vlan_info vinfo;
 	int err;
 
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH net-next 02/16] net: dsa: add ports list in the switch fabric
  2019-10-20  3:19 [PATCH net-next 00/16] net: dsa: turn arrays of ports into a list Vivien Didelot
  2019-10-20  3:19 ` [PATCH net-next 01/16] net: dsa: use dsa_to_port helper everywhere Vivien Didelot
@ 2019-10-20  3:19 ` Vivien Didelot
  2019-10-21  2:36   ` Florian Fainelli
                     ` (2 more replies)
  2019-10-20  3:19 ` [PATCH net-next 03/16] net: dsa: use ports list in dsa_to_port Vivien Didelot
                   ` (14 subsequent siblings)
  16 siblings, 3 replies; 44+ messages in thread
From: Vivien Didelot @ 2019-10-20  3:19 UTC (permalink / raw)
  To: David S. Miller
  Cc: linux-kernel, Vivien Didelot, Florian Fainelli, Andrew Lunn, netdev

Add a list of switch ports within the switch fabric. This will help the
lookup of a port inside the whole fabric, and it is the first step
towards supporting multiple CPU ports, before deprecating the usage of
the unique dst->cpu_dp pointer.

In preparation for a future allocation of the dsa_port structures,
return -ENOMEM in case no structure is returned, even though this
error cannot be reached yet.

Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
---
 include/net/dsa.h |  5 +++++
 net/dsa/dsa2.c    | 48 +++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 2e4fe2f8962b..6ff6dfcdc61d 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -125,6 +125,9 @@ struct dsa_switch_tree {
 	 */
 	struct dsa_port		*cpu_dp;
 
+	/* List of switch ports */
+	struct list_head ports;
+
 	/*
 	 * Data for the individual switch chips.
 	 */
@@ -195,6 +198,8 @@ struct dsa_port {
 	struct work_struct	xmit_work;
 	struct sk_buff_head	xmit_queue;
 
+	struct list_head list;
+
 	/*
 	 * Give the switch driver somewhere to hang its per-port private data
 	 * structures (accessible from the tagger).
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 1716535167ee..b6536641ac99 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -45,6 +45,8 @@ static struct dsa_switch_tree *dsa_tree_alloc(int index)
 
 	dst->index = index;
 
+	INIT_LIST_HEAD(&dst->ports);
+
 	INIT_LIST_HEAD(&dst->list);
 	list_add_tail(&dst->list, &dsa_tree_list);
 
@@ -616,6 +618,22 @@ static int dsa_tree_add_switch(struct dsa_switch_tree *dst,
 	return err;
 }
 
+static struct dsa_port *dsa_port_touch(struct dsa_switch *ds, int index)
+{
+	struct dsa_switch_tree *dst = ds->dst;
+	struct dsa_port *dp;
+
+	dp = &ds->ports[index];
+
+	dp->ds = ds;
+	dp->index = index;
+
+	INIT_LIST_HEAD(&dp->list);
+	list_add(&dp->list, &dst->ports);
+
+	return dp;
+}
+
 static int dsa_port_parse_user(struct dsa_port *dp, const char *name)
 {
 	if (!name)
@@ -742,6 +760,20 @@ static int dsa_switch_parse_member_of(struct dsa_switch *ds,
 	return 0;
 }
 
+static int dsa_switch_touch_ports(struct dsa_switch *ds)
+{
+	struct dsa_port *dp;
+	int port;
+
+	for (port = 0; port < ds->num_ports; port++) {
+		dp = dsa_port_touch(ds, port);
+		if (!dp)
+			return -ENOMEM;
+	}
+
+	return 0;
+}
+
 static int dsa_switch_parse_of(struct dsa_switch *ds, struct device_node *dn)
 {
 	int err;
@@ -750,6 +782,10 @@ static int dsa_switch_parse_of(struct dsa_switch *ds, struct device_node *dn)
 	if (err)
 		return err;
 
+	err = dsa_switch_touch_ports(ds);
+	if (err)
+		return err;
+
 	return dsa_switch_parse_ports_of(ds, dn);
 }
 
@@ -807,6 +843,8 @@ static int dsa_switch_parse_ports(struct dsa_switch *ds,
 
 static int dsa_switch_parse(struct dsa_switch *ds, struct dsa_chip_data *cd)
 {
+	int err;
+
 	ds->cd = cd;
 
 	/* We don't support interconnected switches nor multiple trees via
@@ -817,6 +855,10 @@ static int dsa_switch_parse(struct dsa_switch *ds, struct dsa_chip_data *cd)
 	if (!ds->dst)
 		return -ENOMEM;
 
+	err = dsa_switch_touch_ports(ds);
+	if (err)
+		return err;
+
 	return dsa_switch_parse_ports(ds, cd);
 }
 
@@ -849,7 +891,6 @@ static int dsa_switch_probe(struct dsa_switch *ds)
 struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n)
 {
 	struct dsa_switch *ds;
-	int i;
 
 	ds = devm_kzalloc(dev, struct_size(ds, ports, n), GFP_KERNEL);
 	if (!ds)
@@ -858,11 +899,6 @@ struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n)
 	ds->dev = dev;
 	ds->num_ports = n;
 
-	for (i = 0; i < ds->num_ports; ++i) {
-		ds->ports[i].index = i;
-		ds->ports[i].ds = ds;
-	}
-
 	return ds;
 }
 EXPORT_SYMBOL_GPL(dsa_switch_alloc);
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH net-next 03/16] net: dsa: use ports list in dsa_to_port
  2019-10-20  3:19 [PATCH net-next 00/16] net: dsa: turn arrays of ports into a list Vivien Didelot
  2019-10-20  3:19 ` [PATCH net-next 01/16] net: dsa: use dsa_to_port helper everywhere Vivien Didelot
  2019-10-20  3:19 ` [PATCH net-next 02/16] net: dsa: add ports list in the switch fabric Vivien Didelot
@ 2019-10-20  3:19 ` Vivien Didelot
  2019-10-21  2:38   ` Florian Fainelli
  2019-10-21 12:39   ` Andrew Lunn
  2019-10-20  3:19 ` [PATCH net-next 04/16] net: dsa: use ports list to find slave Vivien Didelot
                   ` (13 subsequent siblings)
  16 siblings, 2 replies; 44+ messages in thread
From: Vivien Didelot @ 2019-10-20  3:19 UTC (permalink / raw)
  To: David S. Miller
  Cc: linux-kernel, Vivien Didelot, Florian Fainelli, Andrew Lunn, netdev

Use the new ports list instead of accessing the dsa_switch array
of ports in the dsa_to_port helper.

Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
---
 include/net/dsa.h | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 6ff6dfcdc61d..938de9518c61 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -285,7 +285,14 @@ struct dsa_switch {
 
 static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p)
 {
-	return &ds->ports[p];
+	struct dsa_switch_tree *dst = ds->dst;
+	struct dsa_port *dp;
+
+	list_for_each_entry(dp, &dst->ports, list)
+		if (dp->ds == ds && dp->index == p)
+			return dp;
+
+	return NULL;
 }
 
 static inline bool dsa_is_unused_port(struct dsa_switch *ds, int p)
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH net-next 04/16] net: dsa: use ports list to find slave
  2019-10-20  3:19 [PATCH net-next 00/16] net: dsa: turn arrays of ports into a list Vivien Didelot
                   ` (2 preceding siblings ...)
  2019-10-20  3:19 ` [PATCH net-next 03/16] net: dsa: use ports list in dsa_to_port Vivien Didelot
@ 2019-10-20  3:19 ` Vivien Didelot
  2019-10-21  2:39   ` Florian Fainelli
  2019-10-21 12:42   ` Andrew Lunn
  2019-10-20  3:19 ` [PATCH net-next 05/16] net: dsa: use ports list to setup switches Vivien Didelot
                   ` (12 subsequent siblings)
  16 siblings, 2 replies; 44+ messages in thread
From: Vivien Didelot @ 2019-10-20  3:19 UTC (permalink / raw)
  To: David S. Miller
  Cc: linux-kernel, Vivien Didelot, Florian Fainelli, Andrew Lunn, netdev

Use the new ports list instead of iterating over switches and their
ports when looking for a slave device from a given master interface.

Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
---
 net/dsa/dsa_priv.h | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index 12f8c7ee4dd8..53e7577896b6 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -104,25 +104,14 @@ static inline struct net_device *dsa_master_find_slave(struct net_device *dev,
 {
 	struct dsa_port *cpu_dp = dev->dsa_ptr;
 	struct dsa_switch_tree *dst = cpu_dp->dst;
-	struct dsa_switch *ds;
-	struct dsa_port *slave_port;
+	struct dsa_port *dp;
 
-	if (device < 0 || device >= DSA_MAX_SWITCHES)
-		return NULL;
+	list_for_each_entry(dp, &dst->ports, list)
+		if (dp->ds->index == device && dp->index == port &&
+		    dp->type == DSA_PORT_TYPE_USER)
+			return dp->slave;
 
-	ds = dst->ds[device];
-	if (!ds)
-		return NULL;
-
-	if (port < 0 || port >= ds->num_ports)
-		return NULL;
-
-	slave_port = &ds->ports[port];
-
-	if (unlikely(slave_port->type != DSA_PORT_TYPE_USER))
-		return NULL;
-
-	return slave_port->slave;
+	return NULL;
 }
 
 /* port.c */
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH net-next 05/16] net: dsa: use ports list to setup switches
  2019-10-20  3:19 [PATCH net-next 00/16] net: dsa: turn arrays of ports into a list Vivien Didelot
                   ` (3 preceding siblings ...)
  2019-10-20  3:19 ` [PATCH net-next 04/16] net: dsa: use ports list to find slave Vivien Didelot
@ 2019-10-20  3:19 ` Vivien Didelot
  2019-10-21  2:42   ` Florian Fainelli
  2019-10-20  3:19 ` [PATCH net-next 06/16] net: dsa: use ports list for routing table setup Vivien Didelot
                   ` (11 subsequent siblings)
  16 siblings, 1 reply; 44+ messages in thread
From: Vivien Didelot @ 2019-10-20  3:19 UTC (permalink / raw)
  To: David S. Miller
  Cc: linux-kernel, Vivien Didelot, Florian Fainelli, Andrew Lunn, netdev

Use the new ports list instead of iterating over switches and their
ports when setting up the switches and their ports.

At the same time, provide setup states and messages for ports and
switches as it is done for the trees.

Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
---
 include/net/dsa.h |   4 ++
 net/dsa/dsa2.c    | 101 ++++++++++++++++++++++------------------------
 2 files changed, 53 insertions(+), 52 deletions(-)

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 938de9518c61..b199a8ca6393 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -215,9 +215,13 @@ struct dsa_port {
 	 * Original copy of the master netdev net_device_ops
 	 */
 	const struct net_device_ops *orig_ndo_ops;
+
+	bool setup;
 };
 
 struct dsa_switch {
+	bool setup;
+
 	struct device *dev;
 
 	/*
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index b6536641ac99..fd2b7f157f97 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -267,6 +267,9 @@ static int dsa_port_setup(struct dsa_port *dp)
 	bool dsa_port_enabled = false;
 	int err = 0;
 
+	if (dp->setup)
+		return 0;
+
 	switch (dp->type) {
 	case DSA_PORT_TYPE_UNUSED:
 		dsa_port_disable(dp);
@@ -335,14 +338,23 @@ static int dsa_port_setup(struct dsa_port *dp)
 		dsa_port_link_unregister_of(dp);
 	if (err && devlink_port_registered)
 		devlink_port_unregister(dlp);
+	if (err)
+		return err;
 
-	return err;
+	dp->setup = true;
+
+	pr_info("DSA: switch %d port %d setup\n", dp->ds->index, dp->index);
+
+	return 0;
 }
 
 static void dsa_port_teardown(struct dsa_port *dp)
 {
 	struct devlink_port *dlp = &dp->devlink_port;
 
+	if (!dp->setup)
+		return;
+
 	switch (dp->type) {
 	case DSA_PORT_TYPE_UNUSED:
 		break;
@@ -365,11 +377,18 @@ static void dsa_port_teardown(struct dsa_port *dp)
 		}
 		break;
 	}
+
+	dp->setup = false;
+
+	pr_info("DSA: switch %d port %d torn down\n", dp->ds->index, dp->index);
 }
 
 static int dsa_switch_setup(struct dsa_switch *ds)
 {
-	int err = 0;
+	int err;
+
+	if (ds->setup)
+		return 0;
 
 	/* Initialize ds->phys_mii_mask before registering the slave MDIO bus
 	 * driver and before ops->setup() has run, since the switch drivers and
@@ -411,6 +430,10 @@ static int dsa_switch_setup(struct dsa_switch *ds)
 			goto unregister_notifier;
 	}
 
+	ds->setup = true;
+
+	pr_info("DSA: switch %d setup\n", ds->index);
+
 	return 0;
 
 unregister_notifier:
@@ -426,6 +449,9 @@ static int dsa_switch_setup(struct dsa_switch *ds)
 
 static void dsa_switch_teardown(struct dsa_switch *ds)
 {
+	if (!ds->setup)
+		return;
+
 	if (ds->slave_mii_bus && ds->ops->phy_read)
 		mdiobus_unregister(ds->slave_mii_bus);
 
@@ -440,78 +466,49 @@ static void dsa_switch_teardown(struct dsa_switch *ds)
 		ds->devlink = NULL;
 	}
 
+	ds->setup = false;
+
+	pr_info("DSA: switch %d torn down\n", ds->index);
 }
 
 static int dsa_tree_setup_switches(struct dsa_switch_tree *dst)
 {
-	struct dsa_switch *ds;
 	struct dsa_port *dp;
-	int device, port, i;
-	int err = 0;
-
-	for (device = 0; device < DSA_MAX_SWITCHES; device++) {
-		ds = dst->ds[device];
-		if (!ds)
-			continue;
+	int err;
 
-		err = dsa_switch_setup(ds);
+	list_for_each_entry(dp, &dst->ports, list) {
+		err = dsa_switch_setup(dp->ds);
 		if (err)
-			goto switch_teardown;
-
-		for (port = 0; port < ds->num_ports; port++) {
-			dp = &ds->ports[port];
+			goto teardown;
+	}
 
-			err = dsa_port_setup(dp);
-			if (err)
-				goto ports_teardown;
-		}
+	list_for_each_entry(dp, &dst->ports, list) {
+		err = dsa_port_setup(dp);
+		if (err)
+			goto teardown;
 	}
 
 	return 0;
 
-ports_teardown:
-	for (i = 0; i < port; i++)
-		dsa_port_teardown(&ds->ports[i]);
-
-	dsa_switch_teardown(ds);
-
-switch_teardown:
-	for (i = 0; i < device; i++) {
-		ds = dst->ds[i];
-		if (!ds)
-			continue;
-
-		for (port = 0; port < ds->num_ports; port++) {
-			dp = &ds->ports[port];
-
-			dsa_port_teardown(dp);
-		}
+teardown:
+	list_for_each_entry(dp, &dst->ports, list)
+		dsa_port_teardown(dp);
 
-		dsa_switch_teardown(ds);
-	}
+	list_for_each_entry(dp, &dst->ports, list)
+		dsa_switch_teardown(dp->ds);
 
 	return err;
 }
 
 static void dsa_tree_teardown_switches(struct dsa_switch_tree *dst)
 {
-	struct dsa_switch *ds;
 	struct dsa_port *dp;
-	int device, port;
-
-	for (device = 0; device < DSA_MAX_SWITCHES; device++) {
-		ds = dst->ds[device];
-		if (!ds)
-			continue;
 
-		for (port = 0; port < ds->num_ports; port++) {
-			dp = &ds->ports[port];
+	list_for_each_entry(dp, &dst->ports, list)
+		dsa_port_teardown(dp);
 
-			dsa_port_teardown(dp);
-		}
-
-		dsa_switch_teardown(ds);
-	}
+	list_for_each_entry(dp, &dst->ports, list)
+		dsa_switch_teardown(dp->ds);
 }
 
 static int dsa_tree_setup_master(struct dsa_switch_tree *dst)
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH net-next 06/16] net: dsa: use ports list for routing table setup
  2019-10-20  3:19 [PATCH net-next 00/16] net: dsa: turn arrays of ports into a list Vivien Didelot
                   ` (4 preceding siblings ...)
  2019-10-20  3:19 ` [PATCH net-next 05/16] net: dsa: use ports list to setup switches Vivien Didelot
@ 2019-10-20  3:19 ` Vivien Didelot
  2019-10-21  2:42   ` Florian Fainelli
  2019-10-21 12:50   ` Andrew Lunn
  2019-10-20  3:19 ` [PATCH net-next 07/16] net: dsa: use ports list to find a port by node Vivien Didelot
                   ` (10 subsequent siblings)
  16 siblings, 2 replies; 44+ messages in thread
From: Vivien Didelot @ 2019-10-20  3:19 UTC (permalink / raw)
  To: David S. Miller
  Cc: linux-kernel, Vivien Didelot, Florian Fainelli, Andrew Lunn, netdev

Use the new ports list instead of accessing the dsa_switch array
of ports when iterating over DSA ports of a switch to set up the
routing table.

Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
---
 net/dsa/dsa2.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index fd2b7f157f97..84afeaeef141 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -157,6 +157,7 @@ static bool dsa_port_setup_routing_table(struct dsa_port *dp)
 
 static bool dsa_switch_setup_routing_table(struct dsa_switch *ds)
 {
+	struct dsa_switch_tree *dst = ds->dst;
 	bool complete = true;
 	struct dsa_port *dp;
 	int i;
@@ -164,10 +165,8 @@ static bool dsa_switch_setup_routing_table(struct dsa_switch *ds)
 	for (i = 0; i < DSA_MAX_SWITCHES; i++)
 		ds->rtable[i] = DSA_RTABLE_NONE;
 
-	for (i = 0; i < ds->num_ports; i++) {
-		dp = &ds->ports[i];
-
-		if (dsa_port_is_dsa(dp)) {
+	list_for_each_entry(dp, &dst->ports, list) {
+		if (dp->ds == ds && dsa_port_is_dsa(dp)) {
 			complete = dsa_port_setup_routing_table(dp);
 			if (!complete)
 				break;
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH net-next 07/16] net: dsa: use ports list to find a port by node
  2019-10-20  3:19 [PATCH net-next 00/16] net: dsa: turn arrays of ports into a list Vivien Didelot
                   ` (5 preceding siblings ...)
  2019-10-20  3:19 ` [PATCH net-next 06/16] net: dsa: use ports list for routing table setup Vivien Didelot
@ 2019-10-20  3:19 ` Vivien Didelot
  2019-10-21  2:43   ` Florian Fainelli
  2019-10-20  3:19 ` [PATCH net-next 08/16] net: dsa: use ports list to setup multiple master devices Vivien Didelot
                   ` (9 subsequent siblings)
  16 siblings, 1 reply; 44+ messages in thread
From: Vivien Didelot @ 2019-10-20  3:19 UTC (permalink / raw)
  To: David S. Miller
  Cc: linux-kernel, Vivien Didelot, Florian Fainelli, Andrew Lunn, netdev

Use the new ports list instead of iterating over switches and their
ports to find a port from a given node.

Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
---
 net/dsa/dsa2.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)

diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 84afeaeef141..8b038cc56769 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -113,22 +113,11 @@ static bool dsa_port_is_user(struct dsa_port *dp)
 static struct dsa_port *dsa_tree_find_port_by_node(struct dsa_switch_tree *dst,
 						   struct device_node *dn)
 {
-	struct dsa_switch *ds;
 	struct dsa_port *dp;
-	int device, port;
-
-	for (device = 0; device < DSA_MAX_SWITCHES; device++) {
-		ds = dst->ds[device];
-		if (!ds)
-			continue;
 
-		for (port = 0; port < ds->num_ports; port++) {
-			dp = &ds->ports[port];
-
-			if (dp->dn == dn)
-				return dp;
-		}
-	}
+	list_for_each_entry(dp, &dst->ports, list)
+		if (dp->dn == dn)
+			return dp;
 
 	return NULL;
 }
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH net-next 08/16] net: dsa: use ports list to setup multiple master devices
  2019-10-20  3:19 [PATCH net-next 00/16] net: dsa: turn arrays of ports into a list Vivien Didelot
                   ` (6 preceding siblings ...)
  2019-10-20  3:19 ` [PATCH net-next 07/16] net: dsa: use ports list to find a port by node Vivien Didelot
@ 2019-10-20  3:19 ` Vivien Didelot
  2019-10-21  3:03   ` Florian Fainelli
  2019-10-20  3:19 ` [PATCH net-next 09/16] net: dsa: use ports list to find first CPU port Vivien Didelot
                   ` (8 subsequent siblings)
  16 siblings, 1 reply; 44+ messages in thread
From: Vivien Didelot @ 2019-10-20  3:19 UTC (permalink / raw)
  To: David S. Miller
  Cc: linux-kernel, Vivien Didelot, Florian Fainelli, Andrew Lunn, netdev

Now that we have a potential list of CPU ports, make use of it instead
of only configuring the master device of an unique CPU port.

Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
---
 net/dsa/dsa2.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 8b038cc56769..3b8de155bc0b 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -501,19 +501,27 @@ static void dsa_tree_teardown_switches(struct dsa_switch_tree *dst)
 
 static int dsa_tree_setup_master(struct dsa_switch_tree *dst)
 {
-	struct dsa_port *cpu_dp = dst->cpu_dp;
-	struct net_device *master = cpu_dp->master;
+	struct dsa_port *dp;
+	int err;
 
-	/* DSA currently supports a single pair of CPU port and master device */
-	return dsa_master_setup(master, cpu_dp);
+	list_for_each_entry(dp, &dst->ports, list) {
+		if (dsa_port_is_cpu(dp)) {
+			err = dsa_master_setup(dp->master, dp);
+			if (err)
+				return err;
+		}
+	}
+
+	return 0;
 }
 
 static void dsa_tree_teardown_master(struct dsa_switch_tree *dst)
 {
-	struct dsa_port *cpu_dp = dst->cpu_dp;
-	struct net_device *master = cpu_dp->master;
+	struct dsa_port *dp;
 
-	return dsa_master_teardown(master);
+	list_for_each_entry(dp, &dst->ports, list)
+		if (dsa_port_is_cpu(dp))
+			dsa_master_teardown(dp->master);
 }
 
 static int dsa_tree_setup(struct dsa_switch_tree *dst)
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH net-next 09/16] net: dsa: use ports list to find first CPU port
  2019-10-20  3:19 [PATCH net-next 00/16] net: dsa: turn arrays of ports into a list Vivien Didelot
                   ` (7 preceding siblings ...)
  2019-10-20  3:19 ` [PATCH net-next 08/16] net: dsa: use ports list to setup multiple master devices Vivien Didelot
@ 2019-10-20  3:19 ` Vivien Didelot
  2019-10-21  2:46   ` Florian Fainelli
  2019-10-20  3:19 ` [PATCH net-next 10/16] net: dsa: use ports list to setup default " Vivien Didelot
                   ` (7 subsequent siblings)
  16 siblings, 1 reply; 44+ messages in thread
From: Vivien Didelot @ 2019-10-20  3:19 UTC (permalink / raw)
  To: David S. Miller
  Cc: linux-kernel, Vivien Didelot, Florian Fainelli, Andrew Lunn, netdev

Use the new ports list instead of iterating over switches and their
ports when looking up the first CPU port in the tree.

Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
---
 net/dsa/dsa2.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)

diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 3b8de155bc0b..99f5dab06787 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -186,22 +186,11 @@ static bool dsa_tree_setup_routing_table(struct dsa_switch_tree *dst)
 
 static struct dsa_port *dsa_tree_find_first_cpu(struct dsa_switch_tree *dst)
 {
-	struct dsa_switch *ds;
 	struct dsa_port *dp;
-	int device, port;
-
-	for (device = 0; device < DSA_MAX_SWITCHES; device++) {
-		ds = dst->ds[device];
-		if (!ds)
-			continue;
 
-		for (port = 0; port < ds->num_ports; port++) {
-			dp = &ds->ports[port];
-
-			if (dsa_port_is_cpu(dp))
-				return dp;
-		}
-	}
+	list_for_each_entry(dp, &dst->ports, list)
+		if (dsa_port_is_cpu(dp))
+			return dp;
 
 	return NULL;
 }
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH net-next 10/16] net: dsa: use ports list to setup default CPU port
  2019-10-20  3:19 [PATCH net-next 00/16] net: dsa: turn arrays of ports into a list Vivien Didelot
                   ` (8 preceding siblings ...)
  2019-10-20  3:19 ` [PATCH net-next 09/16] net: dsa: use ports list to find first CPU port Vivien Didelot
@ 2019-10-20  3:19 ` Vivien Didelot
  2019-10-21  2:47   ` Florian Fainelli
  2019-10-20  3:19 ` [PATCH net-next 11/16] net: dsa: mv88e6xxx: silently skip PVT ops Vivien Didelot
                   ` (6 subsequent siblings)
  16 siblings, 1 reply; 44+ messages in thread
From: Vivien Didelot @ 2019-10-20  3:19 UTC (permalink / raw)
  To: David S. Miller
  Cc: linux-kernel, Vivien Didelot, Florian Fainelli, Andrew Lunn, netdev

Use the new ports list instead of iterating over switches and their
ports when setting up the default CPU port. Unassign it on teardown.

Now that we can iterate over multiple CPU ports, remove dst->cpu_dp.

At the same time, provide a better error message for CPU-less tree.

Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
---
 include/net/dsa.h |  5 -----
 net/dsa/dsa2.c    | 33 ++++++++++++---------------------
 2 files changed, 12 insertions(+), 26 deletions(-)

diff --git a/include/net/dsa.h b/include/net/dsa.h
index b199a8ca6393..020f5db8666b 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -120,11 +120,6 @@ struct dsa_switch_tree {
 	 */
 	struct dsa_platform_data	*pd;
 
-	/*
-	 * The switch port to which the CPU is attached.
-	 */
-	struct dsa_port		*cpu_dp;
-
 	/* List of switch ports */
 	struct list_head ports;
 
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 99f5dab06787..772deacc33d3 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -197,38 +197,29 @@ static struct dsa_port *dsa_tree_find_first_cpu(struct dsa_switch_tree *dst)
 
 static int dsa_tree_setup_default_cpu(struct dsa_switch_tree *dst)
 {
-	struct dsa_switch *ds;
-	struct dsa_port *dp;
-	int device, port;
+	struct dsa_port *cpu_dp, *dp;
 
-	/* DSA currently only supports a single CPU port */
-	dst->cpu_dp = dsa_tree_find_first_cpu(dst);
-	if (!dst->cpu_dp) {
-		pr_warn("Tree has no master device\n");
+	cpu_dp = dsa_tree_find_first_cpu(dst);
+	if (!cpu_dp) {
+		pr_err("DSA: tree %d has no CPU port\n", dst->index);
 		return -EINVAL;
 	}
 
 	/* Assign the default CPU port to all ports of the fabric */
-	for (device = 0; device < DSA_MAX_SWITCHES; device++) {
-		ds = dst->ds[device];
-		if (!ds)
-			continue;
-
-		for (port = 0; port < ds->num_ports; port++) {
-			dp = &ds->ports[port];
-
-			if (dsa_port_is_user(dp) || dsa_port_is_dsa(dp))
-				dp->cpu_dp = dst->cpu_dp;
-		}
-	}
+	list_for_each_entry(dp, &dst->ports, list)
+		if (dsa_port_is_user(dp) || dsa_port_is_dsa(dp))
+			dp->cpu_dp = cpu_dp;
 
 	return 0;
 }
 
 static void dsa_tree_teardown_default_cpu(struct dsa_switch_tree *dst)
 {
-	/* DSA currently only supports a single CPU port */
-	dst->cpu_dp = NULL;
+	struct dsa_port *dp;
+
+	list_for_each_entry(dp, &dst->ports, list)
+		if (dsa_port_is_user(dp) || dsa_port_is_dsa(dp))
+			dp->cpu_dp = NULL;
 }
 
 static int dsa_port_setup(struct dsa_port *dp)
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH net-next 11/16] net: dsa: mv88e6xxx: silently skip PVT ops
  2019-10-20  3:19 [PATCH net-next 00/16] net: dsa: turn arrays of ports into a list Vivien Didelot
                   ` (9 preceding siblings ...)
  2019-10-20  3:19 ` [PATCH net-next 10/16] net: dsa: use ports list to setup default " Vivien Didelot
@ 2019-10-20  3:19 ` Vivien Didelot
  2019-10-21  2:48   ` Florian Fainelli
  2019-10-20  3:19 ` [PATCH net-next 12/16] net: dsa: mv88e6xxx: use ports list to map port VLAN Vivien Didelot
                   ` (5 subsequent siblings)
  16 siblings, 1 reply; 44+ messages in thread
From: Vivien Didelot @ 2019-10-20  3:19 UTC (permalink / raw)
  To: David S. Miller
  Cc: linux-kernel, Vivien Didelot, Florian Fainelli, Andrew Lunn, netdev

Since mv88e6xxx_pvt_map is a static helper, no need to return
-EOPNOTSUPP if the chip has no PVT, simply silently skip the operation.

Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
---
 drivers/net/dsa/mv88e6xxx/chip.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index d67deec77452..510ccdc2d03c 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -1253,7 +1253,7 @@ static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
 	u16 pvlan = 0;
 
 	if (!mv88e6xxx_has_pvt(chip))
-		return -EOPNOTSUPP;
+		return 0;
 
 	/* Skip the local source device, which uses in-chip port VLAN */
 	if (dev != chip->ds->index)
@@ -2049,9 +2049,6 @@ static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
 		}
 	}
 
-	if (!mv88e6xxx_has_pvt(chip))
-		return 0;
-
 	/* Remap the Port VLAN of each cross-chip bridge group member */
 	for (dev = 0; dev < DSA_MAX_SWITCHES; ++dev) {
 		ds = chip->ds->dst->ds[dev];
@@ -2101,9 +2098,6 @@ static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev,
 	struct mv88e6xxx_chip *chip = ds->priv;
 	int err;
 
-	if (!mv88e6xxx_has_pvt(chip))
-		return 0;
-
 	mv88e6xxx_reg_lock(chip);
 	err = mv88e6xxx_pvt_map(chip, dev, port);
 	mv88e6xxx_reg_unlock(chip);
@@ -2116,9 +2110,6 @@ static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, int dev,
 {
 	struct mv88e6xxx_chip *chip = ds->priv;
 
-	if (!mv88e6xxx_has_pvt(chip))
-		return;
-
 	mv88e6xxx_reg_lock(chip);
 	if (mv88e6xxx_pvt_map(chip, dev, port))
 		dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH net-next 12/16] net: dsa: mv88e6xxx: use ports list to map port VLAN
  2019-10-20  3:19 [PATCH net-next 00/16] net: dsa: turn arrays of ports into a list Vivien Didelot
                   ` (10 preceding siblings ...)
  2019-10-20  3:19 ` [PATCH net-next 11/16] net: dsa: mv88e6xxx: silently skip PVT ops Vivien Didelot
@ 2019-10-20  3:19 ` Vivien Didelot
  2019-10-21  2:50   ` Florian Fainelli
  2019-10-20  3:19 ` [PATCH net-next 13/16] net: dsa: mv88e6xxx: use ports list to map bridge Vivien Didelot
                   ` (4 subsequent siblings)
  16 siblings, 1 reply; 44+ messages in thread
From: Vivien Didelot @ 2019-10-20  3:19 UTC (permalink / raw)
  To: David S. Miller
  Cc: linux-kernel, Vivien Didelot, Florian Fainelli, Andrew Lunn, netdev

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>
---
 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


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH net-next 13/16] net: dsa: mv88e6xxx: use ports list to map bridge
  2019-10-20  3:19 [PATCH net-next 00/16] net: dsa: turn arrays of ports into a list Vivien Didelot
                   ` (11 preceding siblings ...)
  2019-10-20  3:19 ` [PATCH net-next 12/16] net: dsa: mv88e6xxx: use ports list to map port VLAN Vivien Didelot
@ 2019-10-20  3:19 ` Vivien Didelot
  2019-10-21  2:52   ` Florian Fainelli
  2019-10-20  3:19 ` [PATCH net-next 14/16] net: dsa: sja1105: register switch before assigning port private data Vivien Didelot
                   ` (3 subsequent siblings)
  16 siblings, 1 reply; 44+ messages in thread
From: Vivien Didelot @ 2019-10-20  3:19 UTC (permalink / raw)
  To: David S. Miller
  Cc: linux-kernel, Vivien Didelot, Florian Fainelli, Andrew Lunn, netdev

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 remap the Port VLAN Map of local bridge
group members or remap the Port VLAN Table entry of external bridge
group members.

Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
---
 drivers/net/dsa/mv88e6xxx/chip.c | 36 +++++++++++++-------------------
 1 file changed, 15 insertions(+), 21 deletions(-)

diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index af8943142053..8771f2525932 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -2043,29 +2043,23 @@ static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
 static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
 				struct net_device *br)
 {
-	struct dsa_switch *ds;
-	int port;
-	int dev;
+	struct dsa_switch *ds = chip->ds;
+	struct dsa_switch_tree *dst = ds->dst;
+	struct dsa_port *dp;
 	int err;
 
-	/* Remap the Port VLAN of each local bridge group member */
-	for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
-		if (dsa_to_port(chip->ds, port)->bridge_dev == br) {
-			err = mv88e6xxx_port_vlan_map(chip, port);
-			if (err)
-				return err;
-		}
-	}
-
-	/* Remap the Port VLAN of each cross-chip bridge group member */
-	for (dev = 0; dev < DSA_MAX_SWITCHES; ++dev) {
-		ds = chip->ds->dst->ds[dev];
-		if (!ds)
-			break;
-
-		for (port = 0; port < ds->num_ports; ++port) {
-			if (dsa_to_port(ds, port)->bridge_dev == br) {
-				err = mv88e6xxx_pvt_map(chip, dev, port);
+	list_for_each_entry(dp, &dst->ports, list) {
+		/* Remap the Port VLAN Map of local bridge group members and
+		 * remap the PVT entry of external bridge group members.
+		 */
+		if (dp->bridge_dev == br) {
+			if (dp->ds == ds) {
+				err = mv88e6xxx_port_vlan_map(chip, dp->index);
+				if (err)
+					return err;
+			} else {
+				err = mv88e6xxx_pvt_map(chip, dp->ds->index,
+							dp->index);
 				if (err)
 					return err;
 			}
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH net-next 14/16] net: dsa: sja1105: register switch before assigning port private data
  2019-10-20  3:19 [PATCH net-next 00/16] net: dsa: turn arrays of ports into a list Vivien Didelot
                   ` (12 preceding siblings ...)
  2019-10-20  3:19 ` [PATCH net-next 13/16] net: dsa: mv88e6xxx: use ports list to map bridge Vivien Didelot
@ 2019-10-20  3:19 ` Vivien Didelot
  2019-10-20  3:19 ` [PATCH net-next 15/16] net: dsa: allocate ports on touch Vivien Didelot
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 44+ messages in thread
From: Vivien Didelot @ 2019-10-20  3:19 UTC (permalink / raw)
  To: David S. Miller
  Cc: linux-kernel, Vivien Didelot, Florian Fainelli, Andrew Lunn, netdev

Like the dsa_switch_tree structures, the dsa_port structures will be
allocated on switch registration.

The SJA1105 driver is the only one accessing the dsa_port structure
after the switch allocation and before the switch registration.
For that reason, move switch registration prior to assigning the priv
member of the dsa_port structures.

Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
---
 drivers/net/dsa/sja1105/sja1105_main.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c
index 4b0cb779f187..0ebbda5ca665 100644
--- a/drivers/net/dsa/sja1105/sja1105_main.c
+++ b/drivers/net/dsa/sja1105/sja1105_main.c
@@ -2057,6 +2057,15 @@ static int sja1105_probe(struct spi_device *spi)
 
 	tagger_data = &priv->tagger_data;
 
+	mutex_init(&priv->ptp_data.lock);
+	mutex_init(&priv->mgmt_lock);
+
+	sja1105_tas_setup(ds);
+
+	rc = dsa_register_switch(priv->ds);
+	if (rc)
+		return rc;
+
 	/* Connections between dsa_port and sja1105_port */
 	for (i = 0; i < SJA1105_NUM_PORTS; i++) {
 		struct sja1105_port *sp = &priv->ports[i];
@@ -2065,12 +2074,8 @@ static int sja1105_probe(struct spi_device *spi)
 		sp->dp = dsa_to_port(ds, i);
 		sp->data = tagger_data;
 	}
-	mutex_init(&priv->ptp_data.lock);
-	mutex_init(&priv->mgmt_lock);
 
-	sja1105_tas_setup(ds);
-
-	return dsa_register_switch(priv->ds);
+	return 0;
 }
 
 static int sja1105_remove(struct spi_device *spi)
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH net-next 15/16] net: dsa: allocate ports on touch
  2019-10-20  3:19 [PATCH net-next 00/16] net: dsa: turn arrays of ports into a list Vivien Didelot
                   ` (13 preceding siblings ...)
  2019-10-20  3:19 ` [PATCH net-next 14/16] net: dsa: sja1105: register switch before assigning port private data Vivien Didelot
@ 2019-10-20  3:19 ` Vivien Didelot
  2019-10-21  2:56   ` Florian Fainelli
  2019-10-20  3:19 ` [PATCH net-next 16/16] net: dsa: remove dsa_switch_alloc helper Vivien Didelot
  2019-10-21 18:32 ` [PATCH net-next 00/16] net: dsa: turn arrays of ports into a list David Miller
  16 siblings, 1 reply; 44+ messages in thread
From: Vivien Didelot @ 2019-10-20  3:19 UTC (permalink / raw)
  To: David S. Miller
  Cc: linux-kernel, Vivien Didelot, Florian Fainelli, Andrew Lunn, netdev

Allocate the struct dsa_port the first time it is accessed with
dsa_port_touch, and remove the static dsa_port array from the
dsa_switch structure.

Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
---
 include/net/dsa.h |  2 --
 net/dsa/dsa2.c    | 16 ++++++++++++++--
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 020f5db8666b..d28ac54cb8c4 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -277,9 +277,7 @@ struct dsa_switch {
 	 */
 	bool			vlan_filtering;
 
-	/* Dynamically allocated ports, keep last */
 	size_t num_ports;
-	struct dsa_port ports[];
 };
 
 static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p)
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 772deacc33d3..7669a6278c40 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -596,7 +596,13 @@ static struct dsa_port *dsa_port_touch(struct dsa_switch *ds, int index)
 	struct dsa_switch_tree *dst = ds->dst;
 	struct dsa_port *dp;
 
-	dp = &ds->ports[index];
+	list_for_each_entry(dp, &dst->ports, list)
+		if (dp->ds == ds && dp->index == index)
+			return dp;
+
+	dp = kzalloc(sizeof(*dp), GFP_KERNEL);
+	if (!dp)
+		return NULL;
 
 	dp->ds = ds;
 	dp->index = index;
@@ -865,7 +871,7 @@ struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n)
 {
 	struct dsa_switch *ds;
 
-	ds = devm_kzalloc(dev, struct_size(ds, ports, n), GFP_KERNEL);
+	ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
 	if (!ds)
 		return NULL;
 
@@ -893,6 +899,12 @@ static void dsa_switch_remove(struct dsa_switch *ds)
 {
 	struct dsa_switch_tree *dst = ds->dst;
 	unsigned int index = ds->index;
+	struct dsa_port *dp, *next;
+
+	list_for_each_entry_safe(dp, next, &dst->ports, list) {
+		list_del(&dp->list);
+		kfree(dp);
+	}
 
 	dsa_tree_remove_switch(dst, index);
 }
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH net-next 16/16] net: dsa: remove dsa_switch_alloc helper
  2019-10-20  3:19 [PATCH net-next 00/16] net: dsa: turn arrays of ports into a list Vivien Didelot
                   ` (14 preceding siblings ...)
  2019-10-20  3:19 ` [PATCH net-next 15/16] net: dsa: allocate ports on touch Vivien Didelot
@ 2019-10-20  3:19 ` Vivien Didelot
  2019-10-21  2:55   ` Florian Fainelli
  2019-10-21 18:32 ` [PATCH net-next 00/16] net: dsa: turn arrays of ports into a list David Miller
  16 siblings, 1 reply; 44+ messages in thread
From: Vivien Didelot @ 2019-10-20  3:19 UTC (permalink / raw)
  To: David S. Miller
  Cc: linux-kernel, Vivien Didelot, Florian Fainelli, Andrew Lunn, netdev

Now that ports are dynamically listed in the fabric, there is no need
to provide a special helper to allocate the dsa_switch structure. This
will give more flexibility to drivers to embed this structure as they
wish in their private structure.

Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
---
 drivers/net/dsa/b53/b53_common.c       |  5 ++++-
 drivers/net/dsa/dsa_loop.c             |  5 ++++-
 drivers/net/dsa/lan9303-core.c         |  4 +++-
 drivers/net/dsa/lantiq_gswip.c         |  4 +++-
 drivers/net/dsa/microchip/ksz_common.c |  5 ++++-
 drivers/net/dsa/mt7530.c               |  5 ++++-
 drivers/net/dsa/mv88e6060.c            |  4 +++-
 drivers/net/dsa/mv88e6xxx/chip.c       |  4 +++-
 drivers/net/dsa/qca8k.c                |  5 ++++-
 drivers/net/dsa/realtek-smi-core.c     |  5 ++++-
 drivers/net/dsa/sja1105/sja1105_main.c |  4 +++-
 drivers/net/dsa/vitesse-vsc73xx-core.c |  5 ++++-
 include/net/dsa.h                      |  1 -
 net/dsa/dsa2.c                         | 21 ++++++---------------
 14 files changed, 49 insertions(+), 28 deletions(-)

diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index 9ba91f1370ac..0a5ab2ce74e3 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -2342,10 +2342,13 @@ struct b53_device *b53_switch_alloc(struct device *base,
 	struct dsa_switch *ds;
 	struct b53_device *dev;
 
-	ds = dsa_switch_alloc(base, DSA_MAX_PORTS);
+	ds = devm_kzalloc(base, sizeof(*ds), GFP_KERNEL);
 	if (!ds)
 		return NULL;
 
+	ds->dev = base;
+	ds->num_ports = DSA_MAX_PORTS;
+
 	dev = devm_kzalloc(base, sizeof(*dev), GFP_KERNEL);
 	if (!dev)
 		return NULL;
diff --git a/drivers/net/dsa/dsa_loop.c b/drivers/net/dsa/dsa_loop.c
index 925ed135a4d9..c8d7ef27fd72 100644
--- a/drivers/net/dsa/dsa_loop.c
+++ b/drivers/net/dsa/dsa_loop.c
@@ -286,10 +286,13 @@ static int dsa_loop_drv_probe(struct mdio_device *mdiodev)
 	dev_info(&mdiodev->dev, "%s: 0x%0x\n",
 		 pdata->name, pdata->enabled_ports);
 
-	ds = dsa_switch_alloc(&mdiodev->dev, DSA_MAX_PORTS);
+	ds = devm_kzalloc(&mdiodev->dev, sizeof(*ds), GFP_KERNEL);
 	if (!ds)
 		return -ENOMEM;
 
+	ds->dev = &mdiodev->dev;
+	ds->num_ports = DSA_MAX_PORTS;
+
 	ps = devm_kzalloc(&mdiodev->dev, sizeof(*ps), GFP_KERNEL);
 	if (!ps)
 		return -ENOMEM;
diff --git a/drivers/net/dsa/lan9303-core.c b/drivers/net/dsa/lan9303-core.c
index bbec86b9418e..e3c333a8f45d 100644
--- a/drivers/net/dsa/lan9303-core.c
+++ b/drivers/net/dsa/lan9303-core.c
@@ -1283,10 +1283,12 @@ static int lan9303_register_switch(struct lan9303 *chip)
 {
 	int base;
 
-	chip->ds = dsa_switch_alloc(chip->dev, LAN9303_NUM_PORTS);
+	chip->ds = devm_kzalloc(chip->dev, sizeof(*chip->ds), GFP_KERNEL);
 	if (!chip->ds)
 		return -ENOMEM;
 
+	chip->ds->dev = chip->dev;
+	chip->ds->num_ports = LAN9303_NUM_PORTS;
 	chip->ds->priv = chip;
 	chip->ds->ops = &lan9303_switch_ops;
 	base = chip->phy_addr_base;
diff --git a/drivers/net/dsa/lantiq_gswip.c b/drivers/net/dsa/lantiq_gswip.c
index a69c9b9878b7..955324968b74 100644
--- a/drivers/net/dsa/lantiq_gswip.c
+++ b/drivers/net/dsa/lantiq_gswip.c
@@ -1854,10 +1854,12 @@ static int gswip_probe(struct platform_device *pdev)
 	if (!priv->hw_info)
 		return -EINVAL;
 
-	priv->ds = dsa_switch_alloc(dev, priv->hw_info->max_ports);
+	priv->ds = devm_kzalloc(dev, sizeof(*priv->ds), GFP_KERNEL);
 	if (!priv->ds)
 		return -ENOMEM;
 
+	priv->ds->dev = dev;
+	priv->ds->num_ports = priv->hw_info->max_ports;
 	priv->ds->priv = priv;
 	priv->ds->ops = &gswip_switch_ops;
 	priv->dev = dev;
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index b0b870f0c252..c755d9e1c4f6 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -398,10 +398,13 @@ struct ksz_device *ksz_switch_alloc(struct device *base, void *priv)
 	struct dsa_switch *ds;
 	struct ksz_device *swdev;
 
-	ds = dsa_switch_alloc(base, DSA_MAX_PORTS);
+	ds = devm_kzalloc(base, sizeof(*ds), GFP_KERNEL);
 	if (!ds)
 		return NULL;
 
+	ds->dev = base;
+	ds->num_ports = DSA_MAX_PORTS;
+
 	swdev = devm_kzalloc(base, sizeof(*swdev), GFP_KERNEL);
 	if (!swdev)
 		return NULL;
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index a91293e47a57..add9e4279176 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -1632,10 +1632,13 @@ mt7530_probe(struct mdio_device *mdiodev)
 	if (!priv)
 		return -ENOMEM;
 
-	priv->ds = dsa_switch_alloc(&mdiodev->dev, DSA_MAX_PORTS);
+	priv->ds = devm_kzalloc(&mdiodev->dev, sizeof(*priv->ds), GFP_KERNEL);
 	if (!priv->ds)
 		return -ENOMEM;
 
+	priv->ds->dev = &mdiodev->dev;
+	priv->ds->num_ports = DSA_MAX_PORTS;
+
 	/* Use medatek,mcm property to distinguish hardware type that would
 	 * casues a little bit differences on power-on sequence.
 	 */
diff --git a/drivers/net/dsa/mv88e6060.c b/drivers/net/dsa/mv88e6060.c
index 2a2489b5196d..a5a37f47b320 100644
--- a/drivers/net/dsa/mv88e6060.c
+++ b/drivers/net/dsa/mv88e6060.c
@@ -270,10 +270,12 @@ static int mv88e6060_probe(struct mdio_device *mdiodev)
 
 	dev_info(dev, "switch %s detected\n", name);
 
-	ds = dsa_switch_alloc(dev, MV88E6060_PORTS);
+	ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
 	if (!ds)
 		return -ENOMEM;
 
+	ds->dev = dev;
+	ds->num_ports = MV88E6060_PORTS;
 	ds->priv = priv;
 	ds->dev = dev;
 	ds->ops = &mv88e6060_switch_ops;
diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index 8771f2525932..e414f9f8f86e 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -4975,10 +4975,12 @@ static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
 	struct device *dev = chip->dev;
 	struct dsa_switch *ds;
 
-	ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
+	ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
 	if (!ds)
 		return -ENOMEM;
 
+	ds->dev = dev;
+	ds->num_ports = mv88e6xxx_num_ports(chip);
 	ds->priv = chip;
 	ds->dev = dev;
 	ds->ops = &mv88e6xxx_switch_ops;
diff --git a/drivers/net/dsa/qca8k.c b/drivers/net/dsa/qca8k.c
index 71e44c8763b8..7e742cd491e8 100644
--- a/drivers/net/dsa/qca8k.c
+++ b/drivers/net/dsa/qca8k.c
@@ -1077,10 +1077,13 @@ qca8k_sw_probe(struct mdio_device *mdiodev)
 	if (id != QCA8K_ID_QCA8337)
 		return -ENODEV;
 
-	priv->ds = dsa_switch_alloc(&mdiodev->dev, QCA8K_NUM_PORTS);
+	priv->ds = devm_kzalloc(&mdiodev->dev, sizeof(*priv->ds),
+				QCA8K_NUM_PORTS);
 	if (!priv->ds)
 		return -ENOMEM;
 
+	priv->ds->dev = &mdiodev->dev;
+	priv->ds->num_ports = DSA_MAX_PORTS;
 	priv->ds->priv = priv;
 	priv->ops = qca8k_switch_ops;
 	priv->ds->ops = &priv->ops;
diff --git a/drivers/net/dsa/realtek-smi-core.c b/drivers/net/dsa/realtek-smi-core.c
index dc0509c02d29..fae188c60191 100644
--- a/drivers/net/dsa/realtek-smi-core.c
+++ b/drivers/net/dsa/realtek-smi-core.c
@@ -444,9 +444,12 @@ static int realtek_smi_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	smi->ds = dsa_switch_alloc(dev, smi->num_ports);
+	smi->ds = devm_kzalloc(dev, sizeof(*smi->ds), GFP_KERNEL);
 	if (!smi->ds)
 		return -ENOMEM;
+
+	smi->ds->dev = dev;
+	smi->ds->num_ports = smi->num_ports;
 	smi->ds->priv = smi;
 
 	smi->ds->ops = var->ds_ops;
diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c
index 0ebbda5ca665..2ae84a9dea59 100644
--- a/drivers/net/dsa/sja1105/sja1105_main.c
+++ b/drivers/net/dsa/sja1105/sja1105_main.c
@@ -2047,10 +2047,12 @@ static int sja1105_probe(struct spi_device *spi)
 
 	dev_info(dev, "Probed switch chip: %s\n", priv->info->name);
 
-	ds = dsa_switch_alloc(dev, SJA1105_NUM_PORTS);
+	ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
 	if (!ds)
 		return -ENOMEM;
 
+	ds->dev = dev;
+	ds->num_ports = SJA1105_NUM_PORTS;
 	ds->ops = &sja1105_switch_ops;
 	ds->priv = priv;
 	priv->ds = ds;
diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c
index 614377ef7956..42c1574d45f2 100644
--- a/drivers/net/dsa/vitesse-vsc73xx-core.c
+++ b/drivers/net/dsa/vitesse-vsc73xx-core.c
@@ -1178,9 +1178,12 @@ int vsc73xx_probe(struct vsc73xx *vsc)
 	 * We allocate 8 ports and avoid access to the nonexistant
 	 * ports.
 	 */
-	vsc->ds = dsa_switch_alloc(dev, 8);
+	vsc->ds = devm_kzalloc(dev, sizeof(*vsc->ds), GFP_KERNEL);
 	if (!vsc->ds)
 		return -ENOMEM;
+
+	vsc->ds->dev = dev;
+	vsc->ds->num_ports = 8;
 	vsc->ds->priv = vsc;
 
 	vsc->ds->ops = &vsc73xx_ds_ops;
diff --git a/include/net/dsa.h b/include/net/dsa.h
index d28ac54cb8c4..0b46b63fef67 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -577,7 +577,6 @@ static inline bool dsa_can_decode(const struct sk_buff *skb,
 	return false;
 }
 
-struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n);
 void dsa_unregister_switch(struct dsa_switch *ds);
 int dsa_register_switch(struct dsa_switch *ds);
 #ifdef CONFIG_PM_SLEEP
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 7669a6278c40..da84d0d14511 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -854,6 +854,12 @@ static int dsa_switch_probe(struct dsa_switch *ds)
 	struct device_node *np = ds->dev->of_node;
 	int err;
 
+	if (!ds->dev)
+		return -ENODEV;
+
+	if (!ds->num_ports)
+		return -EINVAL;
+
 	if (np)
 		err = dsa_switch_parse_of(ds, np);
 	else if (pdata)
@@ -867,21 +873,6 @@ static int dsa_switch_probe(struct dsa_switch *ds)
 	return dsa_switch_add(ds);
 }
 
-struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n)
-{
-	struct dsa_switch *ds;
-
-	ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
-	if (!ds)
-		return NULL;
-
-	ds->dev = dev;
-	ds->num_ports = n;
-
-	return ds;
-}
-EXPORT_SYMBOL_GPL(dsa_switch_alloc);
-
 int dsa_register_switch(struct dsa_switch *ds)
 {
 	int err;
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 01/16] net: dsa: use dsa_to_port helper everywhere
  2019-10-20  3:19 ` [PATCH net-next 01/16] net: dsa: use dsa_to_port helper everywhere Vivien Didelot
@ 2019-10-21  2:34   ` Florian Fainelli
  2019-10-21 12:31   ` Andrew Lunn
  1 sibling, 0 replies; 44+ messages in thread
From: Florian Fainelli @ 2019-10-21  2:34 UTC (permalink / raw)
  To: Vivien Didelot, David S. Miller; +Cc: linux-kernel, Andrew Lunn, netdev



On 10/19/2019 8:19 PM, Vivien Didelot wrote:
> Do not let the drivers access the ds->ports static array directly
> while there is a dsa_to_port helper for this purpose.
> 
> At the same time, un-const this helper since the SJA1105 driver
> assigns the priv member of the returned dsa_port structure.
> 
> Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 02/16] net: dsa: add ports list in the switch fabric
  2019-10-20  3:19 ` [PATCH net-next 02/16] net: dsa: add ports list in the switch fabric Vivien Didelot
@ 2019-10-21  2:36   ` Florian Fainelli
  2019-10-21  2:58   ` Florian Fainelli
  2019-10-21 12:37   ` Andrew Lunn
  2 siblings, 0 replies; 44+ messages in thread
From: Florian Fainelli @ 2019-10-21  2:36 UTC (permalink / raw)
  To: Vivien Didelot, David S. Miller; +Cc: linux-kernel, Andrew Lunn, netdev



On 10/19/2019 8:19 PM, Vivien Didelot wrote:
> Add a list of switch ports within the switch fabric. This will help the
> lookup of a port inside the whole fabric, and it is the first step
> towards supporting multiple CPU ports, before deprecating the usage of
> the unique dst->cpu_dp pointer.
> 
> In preparation for a future allocation of the dsa_port structures,
> return -ENOMEM in case no structure is returned, even though this
> error cannot be reached yet.
> 
> Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 03/16] net: dsa: use ports list in dsa_to_port
  2019-10-20  3:19 ` [PATCH net-next 03/16] net: dsa: use ports list in dsa_to_port Vivien Didelot
@ 2019-10-21  2:38   ` Florian Fainelli
  2019-10-21 12:39   ` Andrew Lunn
  1 sibling, 0 replies; 44+ messages in thread
From: Florian Fainelli @ 2019-10-21  2:38 UTC (permalink / raw)
  To: Vivien Didelot, David S. Miller; +Cc: linux-kernel, Andrew Lunn, netdev



On 10/19/2019 8:19 PM, Vivien Didelot wrote:
> Use the new ports list instead of accessing the dsa_switch array
> of ports in the dsa_to_port helper.
> 
> Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
> ---
>  include/net/dsa.h | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/include/net/dsa.h b/include/net/dsa.h
> index 6ff6dfcdc61d..938de9518c61 100644
> --- a/include/net/dsa.h
> +++ b/include/net/dsa.h
> @@ -285,7 +285,14 @@ struct dsa_switch {
>  
>  static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p)
>  {
> -	return &ds->ports[p];
> +	struct dsa_switch_tree *dst = ds->dst;
> +	struct dsa_port *dp;

I would initialize this to NULL and always return dp

> +
> +	list_for_each_entry(dp, &dst->ports, list)
> +		if (dp->ds == ds && dp->index == p)
> +			return dp;

and do a break here, but this is strictly identical to your code, so it
boils down to a matter of preference.

Do you possibly need to use list_for_ech_entry_safe() here, especially
for the code paths that deal with the unregistering of a switch/switch
fabric? That also raises the question of locking as well, which can be
punted on the caller if that is appropriate.

Other than that:

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 04/16] net: dsa: use ports list to find slave
  2019-10-20  3:19 ` [PATCH net-next 04/16] net: dsa: use ports list to find slave Vivien Didelot
@ 2019-10-21  2:39   ` Florian Fainelli
  2019-10-21 12:42   ` Andrew Lunn
  1 sibling, 0 replies; 44+ messages in thread
From: Florian Fainelli @ 2019-10-21  2:39 UTC (permalink / raw)
  To: Vivien Didelot, David S. Miller; +Cc: linux-kernel, Andrew Lunn, netdev



On 10/19/2019 8:19 PM, Vivien Didelot wrote:
> Use the new ports list instead of iterating over switches and their
> ports when looking for a slave device from a given master interface.
> 
> Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 05/16] net: dsa: use ports list to setup switches
  2019-10-20  3:19 ` [PATCH net-next 05/16] net: dsa: use ports list to setup switches Vivien Didelot
@ 2019-10-21  2:42   ` Florian Fainelli
  2019-10-21 12:49     ` Andrew Lunn
  0 siblings, 1 reply; 44+ messages in thread
From: Florian Fainelli @ 2019-10-21  2:42 UTC (permalink / raw)
  To: Vivien Didelot, David S. Miller; +Cc: linux-kernel, Andrew Lunn, netdev



On 10/19/2019 8:19 PM, Vivien Didelot wrote:
> Use the new ports list instead of iterating over switches and their
> ports when setting up the switches and their ports.
> 
> At the same time, provide setup states and messages for ports and
> switches as it is done for the trees.

Humm, that becomes quite noisy, would it make sense to have those
messages only for non-user ports that are not already visible because
they do not have a net_device?

If you have multiple switches in a fabric, it might be convenient to use
dev_info(dp->ds->dev, ...) to print your message so you can clearly
identify which port belongs to which switch, which becomes even more
important as it is all flattened thanks to lists now. What do you think?
-- 
Florian

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 06/16] net: dsa: use ports list for routing table setup
  2019-10-20  3:19 ` [PATCH net-next 06/16] net: dsa: use ports list for routing table setup Vivien Didelot
@ 2019-10-21  2:42   ` Florian Fainelli
  2019-10-21 12:50   ` Andrew Lunn
  1 sibling, 0 replies; 44+ messages in thread
From: Florian Fainelli @ 2019-10-21  2:42 UTC (permalink / raw)
  To: Vivien Didelot, David S. Miller; +Cc: linux-kernel, Andrew Lunn, netdev



On 10/19/2019 8:19 PM, Vivien Didelot wrote:
> Use the new ports list instead of accessing the dsa_switch array
> of ports when iterating over DSA ports of a switch to set up the
> routing table.
> 
> Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 07/16] net: dsa: use ports list to find a port by node
  2019-10-20  3:19 ` [PATCH net-next 07/16] net: dsa: use ports list to find a port by node Vivien Didelot
@ 2019-10-21  2:43   ` Florian Fainelli
  0 siblings, 0 replies; 44+ messages in thread
From: Florian Fainelli @ 2019-10-21  2:43 UTC (permalink / raw)
  To: Vivien Didelot, David S. Miller; +Cc: linux-kernel, Andrew Lunn, netdev



On 10/19/2019 8:19 PM, Vivien Didelot wrote:
> Use the new ports list instead of iterating over switches and their
> ports to find a port from a given node.
> 
> Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 09/16] net: dsa: use ports list to find first CPU port
  2019-10-20  3:19 ` [PATCH net-next 09/16] net: dsa: use ports list to find first CPU port Vivien Didelot
@ 2019-10-21  2:46   ` Florian Fainelli
  0 siblings, 0 replies; 44+ messages in thread
From: Florian Fainelli @ 2019-10-21  2:46 UTC (permalink / raw)
  To: Vivien Didelot, David S. Miller; +Cc: linux-kernel, Andrew Lunn, netdev



On 10/19/2019 8:19 PM, Vivien Didelot wrote:
> Use the new ports list instead of iterating over switches and their
> ports when looking up the first CPU port in the tree.
> 
> Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 10/16] net: dsa: use ports list to setup default CPU port
  2019-10-20  3:19 ` [PATCH net-next 10/16] net: dsa: use ports list to setup default " Vivien Didelot
@ 2019-10-21  2:47   ` Florian Fainelli
  0 siblings, 0 replies; 44+ messages in thread
From: Florian Fainelli @ 2019-10-21  2:47 UTC (permalink / raw)
  To: Vivien Didelot, David S. Miller; +Cc: linux-kernel, Andrew Lunn, netdev



On 10/19/2019 8:19 PM, Vivien Didelot wrote:
> Use the new ports list instead of iterating over switches and their
> ports when setting up the default CPU port. Unassign it on teardown.
> 
> Now that we can iterate over multiple CPU ports, remove dst->cpu_dp.
> 
> At the same time, provide a better error message for CPU-less tree.
> 
> Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 11/16] net: dsa: mv88e6xxx: silently skip PVT ops
  2019-10-20  3:19 ` [PATCH net-next 11/16] net: dsa: mv88e6xxx: silently skip PVT ops Vivien Didelot
@ 2019-10-21  2:48   ` Florian Fainelli
  0 siblings, 0 replies; 44+ messages in thread
From: Florian Fainelli @ 2019-10-21  2:48 UTC (permalink / raw)
  To: Vivien Didelot, David S. Miller; +Cc: linux-kernel, Andrew Lunn, netdev



On 10/19/2019 8:19 PM, Vivien Didelot wrote:
> Since mv88e6xxx_pvt_map is a static helper, no need to return
> -EOPNOTSUPP if the chip has no PVT, simply silently skip the operation.
> 
> Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 12/16] net: dsa: mv88e6xxx: use ports list to map port VLAN
  2019-10-20  3:19 ` [PATCH net-next 12/16] net: dsa: mv88e6xxx: use ports list to map port VLAN Vivien Didelot
@ 2019-10-21  2:50   ` Florian Fainelli
  0 siblings, 0 replies; 44+ messages in thread
From: Florian Fainelli @ 2019-10-21  2:50 UTC (permalink / raw)
  To: Vivien Didelot, David S. Miller; +Cc: linux-kernel, Andrew Lunn, netdev



On 10/19/2019 8:19 PM, Vivien Didelot wrote:
> 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>
-- 
Florian

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 13/16] net: dsa: mv88e6xxx: use ports list to map bridge
  2019-10-20  3:19 ` [PATCH net-next 13/16] net: dsa: mv88e6xxx: use ports list to map bridge Vivien Didelot
@ 2019-10-21  2:52   ` Florian Fainelli
  0 siblings, 0 replies; 44+ messages in thread
From: Florian Fainelli @ 2019-10-21  2:52 UTC (permalink / raw)
  To: Vivien Didelot, David S. Miller; +Cc: linux-kernel, Andrew Lunn, netdev



On 10/19/2019 8:19 PM, Vivien Didelot wrote:
> 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 remap the Port VLAN Map of local bridge
> group members or remap the Port VLAN Table entry of external bridge
> group members.
> 
> Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
> ---

[snip]

> -		for (port = 0; port < ds->num_ports; ++port) {
> -			if (dsa_to_port(ds, port)->bridge_dev == br) {
> -				err = mv88e6xxx_pvt_map(chip, dev, port);
> +	list_for_each_entry(dp, &dst->ports, list) {
> +		/* Remap the Port VLAN Map of local bridge group members and
> +		 * remap the PVT entry of external bridge group members.
> +		 */

If you do a v2, I would tend to put these comments under the appropriate
branches taken below for clarify although the code is actually clearer
this want than it was before IMHO, so up to you :)

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 16/16] net: dsa: remove dsa_switch_alloc helper
  2019-10-20  3:19 ` [PATCH net-next 16/16] net: dsa: remove dsa_switch_alloc helper Vivien Didelot
@ 2019-10-21  2:55   ` Florian Fainelli
  0 siblings, 0 replies; 44+ messages in thread
From: Florian Fainelli @ 2019-10-21  2:55 UTC (permalink / raw)
  To: Vivien Didelot, David S. Miller; +Cc: linux-kernel, Andrew Lunn, netdev



On 10/19/2019 8:19 PM, Vivien Didelot wrote:
> Now that ports are dynamically listed in the fabric, there is no need
> to provide a special helper to allocate the dsa_switch structure. This
> will give more flexibility to drivers to embed this structure as they
> wish in their private structure.
> 
> Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 15/16] net: dsa: allocate ports on touch
  2019-10-20  3:19 ` [PATCH net-next 15/16] net: dsa: allocate ports on touch Vivien Didelot
@ 2019-10-21  2:56   ` Florian Fainelli
  0 siblings, 0 replies; 44+ messages in thread
From: Florian Fainelli @ 2019-10-21  2:56 UTC (permalink / raw)
  To: Vivien Didelot, David S. Miller; +Cc: linux-kernel, Andrew Lunn, netdev



On 10/19/2019 8:19 PM, Vivien Didelot wrote:
> Allocate the struct dsa_port the first time it is accessed with
> dsa_port_touch, and remove the static dsa_port array from the
> dsa_switch structure.
> 
> Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 02/16] net: dsa: add ports list in the switch fabric
  2019-10-20  3:19 ` [PATCH net-next 02/16] net: dsa: add ports list in the switch fabric Vivien Didelot
  2019-10-21  2:36   ` Florian Fainelli
@ 2019-10-21  2:58   ` Florian Fainelli
  2019-10-21 12:37   ` Andrew Lunn
  2 siblings, 0 replies; 44+ messages in thread
From: Florian Fainelli @ 2019-10-21  2:58 UTC (permalink / raw)
  To: Vivien Didelot, David S. Miller; +Cc: linux-kernel, Andrew Lunn, netdev



On 10/19/2019 8:19 PM, Vivien Didelot wrote:
> Add a list of switch ports within the switch fabric. This will help the
> lookup of a port inside the whole fabric, and it is the first step
> towards supporting multiple CPU ports, before deprecating the usage of
> the unique dst->cpu_dp pointer.
> 
> In preparation for a future allocation of the dsa_port structures,
> return -ENOMEM in case no structure is returned, even though this
> error cannot be reached yet.

BTW, this patch had a small hunk while applying which forced git am to
ask for manual resolution, my net-next tree was based off
v5.4-rc1-582-gebcd670d05d5.
-- 
Florian

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 08/16] net: dsa: use ports list to setup multiple master devices
  2019-10-20  3:19 ` [PATCH net-next 08/16] net: dsa: use ports list to setup multiple master devices Vivien Didelot
@ 2019-10-21  3:03   ` Florian Fainelli
  2019-10-21 14:17     ` Andrew Lunn
  0 siblings, 1 reply; 44+ messages in thread
From: Florian Fainelli @ 2019-10-21  3:03 UTC (permalink / raw)
  To: Vivien Didelot, David S. Miller; +Cc: linux-kernel, Andrew Lunn, netdev



On 10/19/2019 8:19 PM, Vivien Didelot wrote:
> Now that we have a potential list of CPU ports, make use of it instead
> of only configuring the master device of an unique CPU port.

Out of your series, this is the only one that has possible side effects
to existing set-up in that if you had multiple CPU ports defined, today,
we would stop at the first one, whereas now, we will set them all up. I
believe this is right way to do it, but have not had time to fire up a
test on a BCM7278 w/ bcm_sf2 and this patch series to confirm that, will
do that first thing tomorrow morning.

Great stuff, thanks!
-- 
Florian

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 01/16] net: dsa: use dsa_to_port helper everywhere
  2019-10-20  3:19 ` [PATCH net-next 01/16] net: dsa: use dsa_to_port helper everywhere Vivien Didelot
  2019-10-21  2:34   ` Florian Fainelli
@ 2019-10-21 12:31   ` Andrew Lunn
  2019-10-21 15:44     ` Vivien Didelot
  1 sibling, 1 reply; 44+ messages in thread
From: Andrew Lunn @ 2019-10-21 12:31 UTC (permalink / raw)
  To: Vivien Didelot; +Cc: David S. Miller, linux-kernel, Florian Fainelli, netdev

On Sat, Oct 19, 2019 at 11:19:26PM -0400, Vivien Didelot wrote:
> Do not let the drivers access the ds->ports static array directly
> while there is a dsa_to_port helper for this purpose.
> 
> At the same time, un-const this helper since the SJA1105 driver
> assigns the priv member of the returned dsa_port structure.

Hi Vivien

Is priv the only member we expect drivers to change? Is the rest
private to the core/RO? Rather then remove the const, i wonder if it
would be better to add a helper to set priv?

Otherwise:

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 02/16] net: dsa: add ports list in the switch fabric
  2019-10-20  3:19 ` [PATCH net-next 02/16] net: dsa: add ports list in the switch fabric Vivien Didelot
  2019-10-21  2:36   ` Florian Fainelli
  2019-10-21  2:58   ` Florian Fainelli
@ 2019-10-21 12:37   ` Andrew Lunn
  2019-10-21 20:00     ` Vivien Didelot
  2 siblings, 1 reply; 44+ messages in thread
From: Andrew Lunn @ 2019-10-21 12:37 UTC (permalink / raw)
  To: Vivien Didelot; +Cc: David S. Miller, linux-kernel, Florian Fainelli, netdev

> +static struct dsa_port *dsa_port_touch(struct dsa_switch *ds, int index)
> +{
> +	struct dsa_switch_tree *dst = ds->dst;
> +	struct dsa_port *dp;
> +
> +	dp = &ds->ports[index];
> +
> +	dp->ds = ds;
> +	dp->index = index;
> +
> +	INIT_LIST_HEAD(&dp->list);
> +	list_add(&dp->list, &dst->ports);
> +
> +	return dp;
> +}

Bike shedding, but i don't particularly like the name touch.  How
about list. The opposite would then be delist, if we ever need it?

Otherwise:

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 03/16] net: dsa: use ports list in dsa_to_port
  2019-10-20  3:19 ` [PATCH net-next 03/16] net: dsa: use ports list in dsa_to_port Vivien Didelot
  2019-10-21  2:38   ` Florian Fainelli
@ 2019-10-21 12:39   ` Andrew Lunn
  1 sibling, 0 replies; 44+ messages in thread
From: Andrew Lunn @ 2019-10-21 12:39 UTC (permalink / raw)
  To: Vivien Didelot; +Cc: David S. Miller, linux-kernel, Florian Fainelli, netdev

On Sat, Oct 19, 2019 at 11:19:28PM -0400, Vivien Didelot wrote:
> Use the new ports list instead of accessing the dsa_switch array
> of ports in the dsa_to_port helper.
> 
> Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 04/16] net: dsa: use ports list to find slave
  2019-10-20  3:19 ` [PATCH net-next 04/16] net: dsa: use ports list to find slave Vivien Didelot
  2019-10-21  2:39   ` Florian Fainelli
@ 2019-10-21 12:42   ` Andrew Lunn
  1 sibling, 0 replies; 44+ messages in thread
From: Andrew Lunn @ 2019-10-21 12:42 UTC (permalink / raw)
  To: Vivien Didelot; +Cc: David S. Miller, linux-kernel, Florian Fainelli, netdev

On Sat, Oct 19, 2019 at 11:19:29PM -0400, Vivien Didelot wrote:
> Use the new ports list instead of iterating over switches and their
> ports when looking for a slave device from a given master interface.
> 
> Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 05/16] net: dsa: use ports list to setup switches
  2019-10-21  2:42   ` Florian Fainelli
@ 2019-10-21 12:49     ` Andrew Lunn
  2019-10-21 19:37       ` Vivien Didelot
  0 siblings, 1 reply; 44+ messages in thread
From: Andrew Lunn @ 2019-10-21 12:49 UTC (permalink / raw)
  To: Florian Fainelli; +Cc: Vivien Didelot, David S. Miller, linux-kernel, netdev

On Sun, Oct 20, 2019 at 07:42:15PM -0700, Florian Fainelli wrote:
> 
> 
> On 10/19/2019 8:19 PM, Vivien Didelot wrote:
> > Use the new ports list instead of iterating over switches and their
> > ports when setting up the switches and their ports.
> > 
> > At the same time, provide setup states and messages for ports and
> > switches as it is done for the trees.
> 
> Humm, that becomes quite noisy, would it make sense to have those
> messages only for non-user ports that are not already visible because
> they do not have a net_device?

I agree, it looks noise. Maybe change them to _dbg()?
 
> If you have multiple switches in a fabric, it might be convenient to use
> dev_info(dp->ds->dev, ...) to print your message so you can clearly
> identify which port belongs to which switch, which becomes even more
> important as it is all flattened thanks to lists now. What do you think?

I do think it needs to identify both the dst and the ds.

  Andrew

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 06/16] net: dsa: use ports list for routing table setup
  2019-10-20  3:19 ` [PATCH net-next 06/16] net: dsa: use ports list for routing table setup Vivien Didelot
  2019-10-21  2:42   ` Florian Fainelli
@ 2019-10-21 12:50   ` Andrew Lunn
  1 sibling, 0 replies; 44+ messages in thread
From: Andrew Lunn @ 2019-10-21 12:50 UTC (permalink / raw)
  To: Vivien Didelot; +Cc: David S. Miller, linux-kernel, Florian Fainelli, netdev

On Sat, Oct 19, 2019 at 11:19:31PM -0400, Vivien Didelot wrote:
> Use the new ports list instead of accessing the dsa_switch array
> of ports when iterating over DSA ports of a switch to set up the
> routing table.
> 
> Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 08/16] net: dsa: use ports list to setup multiple master devices
  2019-10-21  3:03   ` Florian Fainelli
@ 2019-10-21 14:17     ` Andrew Lunn
  0 siblings, 0 replies; 44+ messages in thread
From: Andrew Lunn @ 2019-10-21 14:17 UTC (permalink / raw)
  To: Florian Fainelli; +Cc: Vivien Didelot, David S. Miller, linux-kernel, netdev

On Sun, Oct 20, 2019 at 08:03:34PM -0700, Florian Fainelli wrote:
> 
> 
> On 10/19/2019 8:19 PM, Vivien Didelot wrote:
> > Now that we have a potential list of CPU ports, make use of it instead
> > of only configuring the master device of an unique CPU port.
> 
> Out of your series, this is the only one that has possible side effects
> to existing set-up in that if you had multiple CPU ports defined, today,
> we would stop at the first one, whereas now, we will set them all up. I
> believe this is right way to do it, but have not had time to fire up a
> test on a BCM7278 w/ bcm_sf2 and this patch series to confirm that, will
> do that first thing tomorrow morning.

Hi Florian

The next patch might also change things, finding the first CPU port.
Is the order of the link list the same as searching the port array?

   Andrew

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 01/16] net: dsa: use dsa_to_port helper everywhere
  2019-10-21 12:31   ` Andrew Lunn
@ 2019-10-21 15:44     ` Vivien Didelot
  0 siblings, 0 replies; 44+ messages in thread
From: Vivien Didelot @ 2019-10-21 15:44 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: David S. Miller, linux-kernel, Florian Fainelli, netdev

Hi Andrew,

On Mon, 21 Oct 2019 14:31:49 +0200, Andrew Lunn <andrew@lunn.ch> wrote:
> On Sat, Oct 19, 2019 at 11:19:26PM -0400, Vivien Didelot wrote:
> > Do not let the drivers access the ds->ports static array directly
> > while there is a dsa_to_port helper for this purpose.
> > 
> > At the same time, un-const this helper since the SJA1105 driver
> > assigns the priv member of the returned dsa_port structure.
> 
> Hi Vivien
> 
> Is priv the only member we expect drivers to change? Is the rest
> private to the core/RO? Rather then remove the const, i wonder if it
> would be better to add a helper to set priv?
> 
> Otherwise:
> 
> Reviewed-by: Andrew Lunn <andrew@lunn.ch>

I had the same thought but actually since the SJA1105 driver is the only
user, I was thinking about maybe getting rid of it, I don't really see the
point of having some "dp->priv = priv, priv->dp = dp" kind of code...

In the meantime I kept the eventual helper or priv removal for a future series.


Thank you,
Vivien

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 00/16] net: dsa: turn arrays of ports into a list
  2019-10-20  3:19 [PATCH net-next 00/16] net: dsa: turn arrays of ports into a list Vivien Didelot
                   ` (15 preceding siblings ...)
  2019-10-20  3:19 ` [PATCH net-next 16/16] net: dsa: remove dsa_switch_alloc helper Vivien Didelot
@ 2019-10-21 18:32 ` David Miller
  16 siblings, 0 replies; 44+ messages in thread
From: David Miller @ 2019-10-21 18:32 UTC (permalink / raw)
  To: vivien.didelot; +Cc: linux-kernel, f.fainelli, andrew, netdev

From: Vivien Didelot <vivien.didelot@gmail.com>
Date: Sat, 19 Oct 2019 23:19:25 -0400

> The dsa_switch structure represents the physical switch device itself,
> and is allocated by the driver. The dsa_switch_tree and dsa_port structures
> represent the logical switch fabric (eventually composed of multiple switch
> devices) and its ports, and are allocated by the DSA core.
 ...

Expecting a v2.

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 05/16] net: dsa: use ports list to setup switches
  2019-10-21 12:49     ` Andrew Lunn
@ 2019-10-21 19:37       ` Vivien Didelot
  0 siblings, 0 replies; 44+ messages in thread
From: Vivien Didelot @ 2019-10-21 19:37 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: Florian Fainelli, David S. Miller, linux-kernel, netdev

On Mon, 21 Oct 2019 14:49:02 +0200, Andrew Lunn <andrew@lunn.ch> wrote:
> On Sun, Oct 20, 2019 at 07:42:15PM -0700, Florian Fainelli wrote:
> > 
> > 
> > On 10/19/2019 8:19 PM, Vivien Didelot wrote:
> > > Use the new ports list instead of iterating over switches and their
> > > ports when setting up the switches and their ports.
> > > 
> > > At the same time, provide setup states and messages for ports and
> > > switches as it is done for the trees.
> > 
> > Humm, that becomes quite noisy, would it make sense to have those
> > messages only for non-user ports that are not already visible because
> > they do not have a net_device?
> 
> I agree, it looks noise. Maybe change them to _dbg()?
>  
> > If you have multiple switches in a fabric, it might be convenient to use
> > dev_info(dp->ds->dev, ...) to print your message so you can clearly
> > identify which port belongs to which switch, which becomes even more
> > important as it is all flattened thanks to lists now. What do you think?
> 
> I do think it needs to identify both the dst and the ds.

It is noise indeed and doesn't add much value, I'll remove them.


Thanks,
Vivien

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH net-next 02/16] net: dsa: add ports list in the switch fabric
  2019-10-21 12:37   ` Andrew Lunn
@ 2019-10-21 20:00     ` Vivien Didelot
  0 siblings, 0 replies; 44+ messages in thread
From: Vivien Didelot @ 2019-10-21 20:00 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: David S. Miller, linux-kernel, Florian Fainelli, netdev

On Mon, 21 Oct 2019 14:37:40 +0200, Andrew Lunn <andrew@lunn.ch> wrote:
> > +static struct dsa_port *dsa_port_touch(struct dsa_switch *ds, int index)
> > +{
> > +	struct dsa_switch_tree *dst = ds->dst;
> > +	struct dsa_port *dp;
> > +
> > +	dp = &ds->ports[index];
> > +
> > +	dp->ds = ds;
> > +	dp->index = index;
> > +
> > +	INIT_LIST_HEAD(&dp->list);
> > +	list_add(&dp->list, &dst->ports);
> > +
> > +	return dp;
> > +}
> 
> Bike shedding, but i don't particularly like the name touch.  How
> about list. The opposite would then be delist, if we ever need it?

The fabric code uses "touch" for "get or create" already, so I used the same
semantics for ports as well. But I'm not strongly attached to this naming
anyway, so I will polish them all together in a future series.


Thanks,
Vivien

^ permalink raw reply	[flat|nested] 44+ messages in thread

end of thread, other threads:[~2019-10-21 20:00 UTC | newest]

Thread overview: 44+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-20  3:19 [PATCH net-next 00/16] net: dsa: turn arrays of ports into a list Vivien Didelot
2019-10-20  3:19 ` [PATCH net-next 01/16] net: dsa: use dsa_to_port helper everywhere Vivien Didelot
2019-10-21  2:34   ` Florian Fainelli
2019-10-21 12:31   ` Andrew Lunn
2019-10-21 15:44     ` Vivien Didelot
2019-10-20  3:19 ` [PATCH net-next 02/16] net: dsa: add ports list in the switch fabric Vivien Didelot
2019-10-21  2:36   ` Florian Fainelli
2019-10-21  2:58   ` Florian Fainelli
2019-10-21 12:37   ` Andrew Lunn
2019-10-21 20:00     ` Vivien Didelot
2019-10-20  3:19 ` [PATCH net-next 03/16] net: dsa: use ports list in dsa_to_port Vivien Didelot
2019-10-21  2:38   ` Florian Fainelli
2019-10-21 12:39   ` Andrew Lunn
2019-10-20  3:19 ` [PATCH net-next 04/16] net: dsa: use ports list to find slave Vivien Didelot
2019-10-21  2:39   ` Florian Fainelli
2019-10-21 12:42   ` Andrew Lunn
2019-10-20  3:19 ` [PATCH net-next 05/16] net: dsa: use ports list to setup switches Vivien Didelot
2019-10-21  2:42   ` Florian Fainelli
2019-10-21 12:49     ` Andrew Lunn
2019-10-21 19:37       ` Vivien Didelot
2019-10-20  3:19 ` [PATCH net-next 06/16] net: dsa: use ports list for routing table setup Vivien Didelot
2019-10-21  2:42   ` Florian Fainelli
2019-10-21 12:50   ` Andrew Lunn
2019-10-20  3:19 ` [PATCH net-next 07/16] net: dsa: use ports list to find a port by node Vivien Didelot
2019-10-21  2:43   ` Florian Fainelli
2019-10-20  3:19 ` [PATCH net-next 08/16] net: dsa: use ports list to setup multiple master devices Vivien Didelot
2019-10-21  3:03   ` Florian Fainelli
2019-10-21 14:17     ` Andrew Lunn
2019-10-20  3:19 ` [PATCH net-next 09/16] net: dsa: use ports list to find first CPU port Vivien Didelot
2019-10-21  2:46   ` Florian Fainelli
2019-10-20  3:19 ` [PATCH net-next 10/16] net: dsa: use ports list to setup default " Vivien Didelot
2019-10-21  2:47   ` Florian Fainelli
2019-10-20  3:19 ` [PATCH net-next 11/16] net: dsa: mv88e6xxx: silently skip PVT ops Vivien Didelot
2019-10-21  2:48   ` Florian Fainelli
2019-10-20  3:19 ` [PATCH net-next 12/16] net: dsa: mv88e6xxx: use ports list to map port VLAN Vivien Didelot
2019-10-21  2:50   ` Florian Fainelli
2019-10-20  3:19 ` [PATCH net-next 13/16] net: dsa: mv88e6xxx: use ports list to map bridge Vivien Didelot
2019-10-21  2:52   ` Florian Fainelli
2019-10-20  3:19 ` [PATCH net-next 14/16] net: dsa: sja1105: register switch before assigning port private data Vivien Didelot
2019-10-20  3:19 ` [PATCH net-next 15/16] net: dsa: allocate ports on touch Vivien Didelot
2019-10-21  2:56   ` Florian Fainelli
2019-10-20  3:19 ` [PATCH net-next 16/16] net: dsa: remove dsa_switch_alloc helper Vivien Didelot
2019-10-21  2:55   ` Florian Fainelli
2019-10-21 18:32 ` [PATCH net-next 00/16] net: dsa: turn arrays of ports into a list David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).