net: dsa: loop: Preparatory changes for
Subsystems (3)
cover net: dsa: loop: Preparatory changes for
Hi David,
These patches are all meant to help pave the way for a 802.1Q data path added to the mockup driver, making it more useful than just testing for configuration. Sending those out now since there is no real need to wait.
Thanks
Florian Fainelli (5):
net: dsa: loop: PVID should be per-port
net: dsa: loop: Support 4K VLANs
net: dsa: loop: Move data structures to header
net: dsa: loop: Wire-up MTU callbacks
net: dsa: loop: Set correct number of ports
drivers/net/dsa/dsa_loop.c | 61 ++++++++++++++------------------------ include/linux/dsa/loop.h | 41 +++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 38 deletions(-) create mode 100644 include/linux/dsa/loop.h
Signature · 1 line
2.25.1
PATCH 1/5 net: dsa: loop: PVID should be per-port
The PVID should be per-port, this is a preliminary change to support a 802.1Q data path in the driver.
--- drivers/net/dsa/dsa_loop.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/dsa/dsa_loop.c +4 -4
@@ -45,6 +45,7 @@ static struct dsa_loop_mib_entry dsa_loop_mibs[] = {struct dsa_loop_port {struct dsa_loop_mib_entry mib[__DSA_LOOP_CNT_MAX]; +u16 pvid; };#define DSA_LOOP_VLANS 5
@@ -55,7 +56,6 @@ struct dsa_loop_priv {struct dsa_loop_vlan vlans[DSA_LOOP_VLANS ];struct net_device *netdev;struct dsa_loop_port ports[DSA_MAX_PORTS ]; -u16 pvid; };static struct phy_device *phydevs[PHY_MAX_ADDR ];
@@ -224,7 +224,7 @@ static void dsa_loop_port_vlan_add(struct dsa_switch *ds, int port, }if (pvid) - ps->pvid = vid; + ps->ports[port].pvid = vid; } static int dsa_loop_port_vlan_del(struct dsa_switch *ds, int port,
@@ -234,7 +234,7 @@ static int dsa_loop_port_vlan_del(struct dsa_switch *ds, int port,struct dsa_loop_priv *ps = ds->priv;struct mii_bus *bus = ps->bus;struct dsa_loop_vlan *vl; -u16 vid, pvid = ps->pvid; +u16 vid, pvid = ps->ports[port].pvid;/* Just do a sleeping operation to make lockdep checks effective */ mdiobus_read (bus, ps->port_base + port,MII_BMSR );
@@ -252,7 +252,7 @@ static int dsa_loop_port_vlan_del(struct dsa_switch *ds, int port,dev_dbg (ds->dev,"%s: port: %d vlan: %d, %stagged, pvid: %d\n" , __func__, port, vid, untagged ?"un" :"" , pvid); } - ps->pvid = pvid; + ps->ports[port].pvid = pvid;return 0 ; }
Signature · 1 line
2.25.1
Re: [PATCH net-next 1/5] net: dsa: loop: PVID should be per-port
Quoted 4 lines · Florian Fainelli
The PVID should be per-port, this is a preliminary change to support a 802.1Q data path in the driver.
Signed-off-by Florian Fainelli <[email protected]>
Andrew
PATCH 2/5 net: dsa: loop: Support 4K VLANs
In reply to Florian FainelliAllocate a 4K array of VLANs instead of limiting ourselves to just 5 which is arbitrary.
--- drivers/net/dsa/dsa_loop.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/dsa/dsa_loop.c +2 -4
@@ -48,12 +48,10 @@ struct dsa_loop_port {u16 pvid; }; -#define DSA_LOOP_VLANS 5 -struct dsa_loop_priv {struct mii_bus *bus;unsigned int port_base; -struct dsa_loop_vlan vlans[DSA_LOOP_VLANS ]; +struct dsa_loop_vlan vlans[VLAN_N_VID ];struct net_device *netdev;struct dsa_loop_port ports[DSA_MAX_PORTS ]; };
@@ -191,7 +189,7 @@ dsa_loop_port_vlan_prepare(struct dsa_switch *ds, int port,/* Just do a sleeping operation to make lockdep checks effective */ mdiobus_read (bus, ps->port_base + port,MII_BMSR ); -if (vlan->vid_end >DSA_LOOP_VLANS ) +if (vlan->vid_end >ARRAY_SIZE (ps->vlans))return -ERANGE ;return 0 ;
Signature · 1 line
2.25.1
Re: [PATCH net-next 2/5] net: dsa: loop: Support 4K VLANs
Quoted 15 lines · Florian Fainelli
Allocate a 4K array of VLANs instead of limiting ourselves to just 5 which is arbitrary.
Signed-off-by Florian Fainelli <[email protected]>--- drivers/net/dsa/dsa_loop.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/net/dsa/dsa_loop.c +0
-0@@ -48,12 +48,10 @@ struct dsa_loop_port {u16 pvid; };
drivers/net/dsa/dsa_loop.c struct dsa_loop_port { · line 56
Quoted 10 lines
drivers/net/dsa/dsa_loop.c +1
-3-#define DSA_LOOP_VLANS 5 -struct dsa_loop_priv {struct mii_bus *bus;unsigned int port_base; -struct dsa_loop_vlan vlans[DSA_LOOP_VLANS ]; +struct dsa_loop_vlan vlans[VLAN_N_VID ];struct net_device *netdev;struct dsa_loop_port ports[DSA_MAX_PORTS ];
That is 4K x (2 x u16) = 16K RAM. I suppose for a test driver which is never expected to be used in production, that is O.K.
Andrew
Re: [PATCH net-next 2/5] net: dsa: loop: Support 4K VLANs
Quoted 17 lines · Andrew Lunn
Quoted 16 lines · Florian Fainelli
Allocate a 4K array of VLANs instead of limiting ourselves to just 5 which is arbitrary.
Signed-off-by Florian Fainelli <[email protected]>--- drivers/net/dsa/dsa_loop.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/net/dsa/dsa_loop.c +0
-0@@ -48,12 +48,10 @@ struct dsa_loop_port {u16 pvid; };
Quoted 12 lines
drivers/net/dsa/dsa_loop.c struct dsa_loop_port { · line 56
Quoted 9 lines
drivers/net/dsa/dsa_loop.c +1
-3-#define DSA_LOOP_VLANS 5 -struct dsa_loop_priv {struct mii_bus *bus;unsigned int port_base; -struct dsa_loop_vlan vlans[DSA_LOOP_VLANS ]; +struct dsa_loop_vlan vlans[VLAN_N_VID ];struct net_device *netdev;struct dsa_loop_port ports[DSA_MAX_PORTS ];That is 4K x (2 x u16) = 16K RAM. I suppose for a test driver which is never expected to be used in production, that is O.K.
I think so too, if we are worried we could switch to vmalloc() down the road.
Quoted 5 lines
Reviewed-by Andrew Lunn <[email protected]>Andrew
Signature · 1 line
Florian
PATCH 3/5 net: dsa: loop: Move data structures to header
In reply to Florian FainelliIn preparation for adding support for a mockup data path, move the driver data structures to include/linux/dsa/loop.h such that we can share them between net/dsa/ and drivers/net/dsa/ later on.
--- drivers/net/dsa/dsa_loop.c | 32 +----------------------------- include/linux/dsa/loop.h | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 31 deletions(-) create mode 100644 include/linux/dsa/loop.h
drivers/net/dsa/dsa_loop.c +1 -31
@@ -14,28 +14,11 @@#include <linux/workqueue.h> #include <linux/module.h> #include <linux/if_bridge.h> +#include <linux/dsa/loop.h> #include <net/dsa.h> #include "dsa_loop.h" -struct dsa_loop_vlan { -u16 members; -u16 untagged; -}; - -struct dsa_loop_mib_entry { -char name[ETH_GSTRING_LEN ]; -unsigned long val; -}; - -enum dsa_loop_mib_counters { -DSA_LOOP_PHY_READ_OK , -DSA_LOOP_PHY_READ_ERR , -DSA_LOOP_PHY_WRITE_OK , -DSA_LOOP_PHY_WRITE_ERR , - __DSA_LOOP_CNT_MAX, -}; -static struct dsa_loop_mib_entry dsa_loop_mibs[] = { [DSA_LOOP_PHY_READ_OK ] = {"phy_read_ok" , }, [DSA_LOOP_PHY_READ_ERR ] = {"phy_read_err" , },
@@ -43,19 +26,6 @@ static struct dsa_loop_mib_entry dsa_loop_mibs[] = { [DSA_LOOP_PHY_WRITE_ERR] = { "phy_write_err", }, }; -struct dsa_loop_port { -struct dsa_loop_mib_entry mib[__DSA_LOOP_CNT_MAX]; -u16 pvid; -}; - -struct dsa_loop_priv { -struct mii_bus *bus; -unsigned int port_base; -struct dsa_loop_vlan vlans[VLAN_N_VID ]; -struct net_device *netdev; -struct dsa_loop_port ports[DSA_MAX_PORTS ]; -}; -static struct phy_device *phydevs[PHY_MAX_ADDR ]; static enum dsa_tag_protocol dsa_loop_get_protocol(struct dsa_switch *ds,
include/linux/dsa/loop.h new file +40 -0
@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef DSA_LOOP_H +#define DSA_LOOP_H + +#include <linux/types.h> +#include <linux/ethtool.h> +#include <net/dsa.h> + +struct dsa_loop_vlan { +u16 members; +u16 untagged; +}; + +struct dsa_loop_mib_entry { +char name[ETH_GSTRING_LEN ]; +unsigned long val; +}; + +enum dsa_loop_mib_counters { +DSA_LOOP_PHY_READ_OK , +DSA_LOOP_PHY_READ_ERR , +DSA_LOOP_PHY_WRITE_OK , +DSA_LOOP_PHY_WRITE_ERR , + __DSA_LOOP_CNT_MAX, +}; + +struct dsa_loop_port { +struct dsa_loop_mib_entry mib[__DSA_LOOP_CNT_MAX]; +u16 pvid; +}; + +struct dsa_loop_priv { +struct mii_bus *bus; +unsigned int port_base; +struct dsa_loop_vlan vlans[VLAN_N_VID ]; +struct net_device *netdev; +struct dsa_loop_port ports[DSA_MAX_PORTS ]; +}; + +#endif /* DSA_LOOP_H */
Signature · 1 line
2.25.1
PATCH 4/5 net: dsa: loop: Wire-up MTU callbacks
In reply to Florian FainelliFor now we simply store the port MTU into a per-port member.
--- drivers/net/dsa/dsa_loop.c | 17 +++++++++++++++++ include/linux/dsa/loop.h | 1 + 2 files changed, 18 insertions(+)
drivers/net/dsa/dsa_loop.c +17 -0
@@ -225,6 +225,21 @@ static int dsa_loop_port_vlan_del(struct dsa_switch *ds, int port,return 0 ; } +static int dsa_loop_port_change_mtu (struct dsa_switch *ds,int port, +int new_mtu) +{ +struct dsa_loop_priv *priv = ds->priv; + + priv->ports[port].mtu = new_mtu; + +return 0 ; +} + +static int dsa_loop_port_max_mtu (struct dsa_switch *ds,int port) +{ +return ETH_MAX_MTU ; +} +static const struct dsa_switch_ops dsa_loop_driver = { .get_tag_protocol = dsa_loop_get_protocol, .setup = dsa_loop_setup,
@@ -241,6 +256,8 @@ static const struct dsa_switch_ops dsa_loop_driver = { .port_vlan_prepare = dsa_loop_port_vlan_prepare, .port_vlan_add = dsa_loop_port_vlan_add, .port_vlan_del = dsa_loop_port_vlan_del, + .port_change_mtu = dsa_loop_port_change_mtu, + .port_max_mtu = dsa_loop_port_max_mtu, };static int dsa_loop_drv_probe (struct mdio_device *mdiodev)
include/linux/dsa/loop.h +1 -0
@@ -27,6 +27,7 @@ enum dsa_loop_mib_counters {struct dsa_loop_port {struct dsa_loop_mib_entry mib[__DSA_LOOP_CNT_MAX];u16 pvid; +int mtu; };struct dsa_loop_priv {
Signature · 1 line
2.25.1
Re: [PATCH net-next 4/5] net: dsa: loop: Wire-up MTU callbacks
Quoted 3 lines · Florian Fainelli
For now we simply store the port MTU into a per-port member.
Signed-off-by Florian Fainelli <[email protected]>
Andrew
PATCH 5/5 net: dsa: loop: Set correct number of ports
In reply to Florian FainelliWe only support DSA_LOOP_NUM_PORTS in the switch, do not tell the DSA core to allocate up to DSA_MAX_PORTS which is nearly the double (6 vs. 11).
--- drivers/net/dsa/dsa_loop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/dsa_loop.c +1 -1
@@ -275,7 +275,7 @@ static int dsa_loop_drv_probe(struct mdio_device *mdiodev)return -ENOMEM ; ds->dev = &mdiodev->dev; - ds->num_ports =DSA_MAX_PORTS ; + ds->num_ports =DSA_LOOP_NUM_PORTS ; ps =devm_kzalloc (&mdiodev->dev,sizeof (*ps),GFP_KERNEL );if (!ps)
Signature · 1 line
2.25.1
Re: [PATCH net-next 5/5] net: dsa: loop: Set correct number of ports
Quoted 5 lines · Florian Fainelli
We only support
DSA_LOOP_NUM_PORTSin the switch, do not tell the DSA core to allocate up toDSA_MAX_PORTSwhich is nearly the double (6 vs. 11).Signed-off-by Florian Fainelli <[email protected]>
Andrew
Andrew Lunn
maintainerQuoted 5 lines · Florian Fainelli
Hi David,
These patches are all meant to help pave the way for a 802.1Q data path added to the mockup driver, making it more useful than just testing for configuration.
Could you give some more details. I assume the tag driver is going be to more active. At least, that would make sense with the data structure moves.
Andrew
Quoted 10 lines · Andrew Lunn
Quoted 5 lines · Florian Fainelli
Hi David,
These patches are all meant to help pave the way for a 802.1Q data path added to the mockup driver, making it more useful than just testing for configuration.
Could you give some more details. I assume the tag driver is going be to more active. At least, that would make sense with the data structure moves.
Still working on a 802.1Q data path that allows to carry VLAN tags from the DSA CPU interface (guest side) to a tap (host side) and from there you can ping, bridge etc. devices. I am having some problems with the responses sent back to the guest which are incorrectly tagged on ingress.
You can see the WIP here:
https://github.com/ffainelli/linux/commits/dsa-loop-8021q
Signature · 1 line
Florian
David Miller
maintainerFrom: Florian Fainelli <[email protected]>
Date: Mon, 3 Aug 2020 13:03:49 -0700
Quoted 4 lines
These patches are all meant to help pave the way for a 802.1Q data path added to the mockup driver, making it more useful than just testing for configuration. Sending those out now since there is no real need to wait.
Series applied, I added "a 802.1Q data path" to the subject line I integrated into the merge commit for the series as it seems your Subject line here was chopped off.
Quoted 11 lines · David Miller
From: Florian Fainelli <[email protected]>
Date: Mon, 3 Aug 2020 13:03:49 -0700Quoted 4 lines
These patches are all meant to help pave the way for a 802.1Q data path added to the mockup driver, making it more useful than just testing for configuration. Sending those out now since there is no real need to wait.
Series applied, I added "a 802.1Q data path" to the subject line I integrated into the merge commit for the series as it seems your Subject line here was chopped off.
Yes it was, the merge commit looks good to me, thank you.
Signature · 1 line
Florian