From: Vivien Didelot <vivien.didelot@gmail.com>
To: "David S. Miller" <davem@davemloft.net>
Cc: linux-kernel@vger.kernel.org,
Vivien Didelot <vivien.didelot@gmail.com>,
Florian Fainelli <f.fainelli@gmail.com>,
Andrew Lunn <andrew@lunn.ch>,
netdev@vger.kernel.org
Subject: [PATCH net-next 02/16] net: dsa: add ports list in the switch fabric
Date: Sat, 19 Oct 2019 23:19:27 -0400 [thread overview]
Message-ID: <20191020031941.3805884-3-vivien.didelot@gmail.com> (raw)
In-Reply-To: <20191020031941.3805884-1-vivien.didelot@gmail.com>
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
next prev parent reply other threads:[~2019-10-20 3:20 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Vivien Didelot [this message]
2019-10-21 2:36 ` [PATCH net-next 02/16] net: dsa: add ports list in the switch fabric 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191020031941.3805884-3-vivien.didelot@gmail.com \
--to=vivien.didelot@gmail.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).