When both user ports are joined to the same bridge, the normal
HW MAC learning is enabled. This means that unicast traffic is forwarded
in HW.
If one of the user ports leave the bridge,
the ports goes back to the initial separated operation.
Port separation relies on disabled HW MAC learning. Hence the condition
that both ports must join same bridge.
Add brigde methods port_bridge_join, port_bridge_leave and
port_stp_state_set.
Signed-off-by: Egil Hjelmeland <redacted>
---
drivers/net/dsa/lan9303-core.c | 88 ++++++++++++++++++++++++++++++++++++++++++
drivers/net/dsa/lan9303.h | 1 +
2 files changed, 89 insertions(+)
Prepare for next patch:
Move tag setup from lan9303_separate_ports() to new function
lan9303_setup_tagging()
Signed-off-by: Egil Hjelmeland <redacted>
---
drivers/net/dsa/lan9303-core.c | 42 +++++++++++++++++++++++++-----------------
1 file changed, 25 insertions(+), 17 deletions(-)
@@ -510,11 +511,30 @@ static int lan9303_enable_processing_port(struct lan9303 *chip,LAN9303_MAC_TX_CFG_X_TX_ENABLE);}+/* forward special tagged packets from port 0 to port 1 *or* port 2 */+staticintlan9303_setup_tagging(structlan9303*chip)+{+intret;+/* enable defining the destination port via special VLAN tagging+*forport0+*/+ret=lan9303_write_switch_reg(chip,LAN9303_SWE_INGRESS_PORT_TYPE,+LAN9303_SWE_INGRESS_PORT_TYPE_VLAN);+if(ret)+returnret;++/* tag incoming packets at port 1 and 2 on their way to port 0 to be+*abletodiscovertheirsourceport+*/+returnlan9303_write_switch_reg(+chip,LAN9303_BM_EGRSS_PORT_TYPE,+LAN9303_BM_EGRSS_PORT_TYPE_SPECIAL_TAG_PORT0);+}+/* We want a special working switch:*-donotforwardpacketsbetweenport1and2*-forwardeverythingfromport1toport0*-forwardeverythingfromport2toport0-*-forwardspecialtaggedpacketsfromport0toport1*or*port2*/staticintlan9303_separate_ports(structlan9303*chip){
@@ -529,22 +549,6 @@ static int lan9303_separate_ports(struct lan9303 *chip)if(ret)returnret;-/* enable defining the destination port via special VLAN tagging-*forport0-*/-ret=lan9303_write_switch_reg(chip,LAN9303_SWE_INGRESS_PORT_TYPE,-0x03);-if(ret)-returnret;--/* tag incoming packets at port 1 and 2 on their way to port 0 to be-*abletodiscovertheirsourceport-*/-ret=lan9303_write_switch_reg(chip,LAN9303_BM_EGRSS_PORT_TYPE,-LAN9303_BM_EGRSS_PORT_TYPE_SPECIAL_TAG_PORT0);-if(ret)-returnret;-/* prevent port 1 and 2 from forwarding packets by their own */returnlan9303_write_switch_reg(chip,LAN9303_SWE_PORT_STATE,LAN9303_SWE_PORT_STATE_FORWARDING_PORT0|
@@ -644,6 +648,10 @@ static int lan9303_setup(struct dsa_switch *ds)return-EINVAL;}+ret=lan9303_setup_tagging(chip);+if(ret)+dev_err(chip->dev,"failed to setup port tagging %d\n",ret);+ret=lan9303_separate_ports(chip);if(ret)dev_err(chip->dev,"failed to separate ports %d\n",ret);
Could you replace the 0 with something symbolic which makes this
easier to understand.
#define LAN9303_SWE_PORT_MIRROR_DISABLED 0
quoted hunk
+
static int lan9303_handle_reset(struct lan9303 *chip)
{
if (!chip->reset_gpio)
@@ -844,6 +866,69 @@ static void lan9303_port_disable(struct dsa_switch *ds, int port, } }+static int lan9303_port_bridge_join(struct dsa_switch *ds, int port,+ struct net_device *br)+{+ struct lan9303 *chip = ds->priv;++ dev_dbg(chip->dev, "%s(port %d)\n", __func__, port);+ if (ds->ports[1].bridge_dev == ds->ports[2].bridge_dev) {+ lan9303_bridge_ports(chip);+ chip->is_bridged = true; /* unleash stp_state_set() */+ }++ return 0;+}++static void lan9303_port_bridge_leave(struct dsa_switch *ds, int port,+ struct net_device *br)+{+ struct lan9303 *chip = ds->priv;++ dev_dbg(chip->dev, "%s(port %d)\n", __func__, port);+ if (chip->is_bridged) {+ lan9303_separate_ports(chip);+ chip->is_bridged = false;+ }+}++static void lan9303_port_stp_state_set(struct dsa_switch *ds, int port,+ u8 state)+{+ int portmask, portstate;+ struct lan9303 *chip = ds->priv;++ dev_dbg(chip->dev, "%s(port %d, state %d)\n",+ __func__, port, state);+ if (!chip->is_bridged)+ return; /* touching SWE_PORT_STATE will break port separation */
I'm wondering how this is supposed to work. Please add a good comment
here, since the hardware is forcing you to do something odd.
Maybe it would be a good idea to save the STP state in chip. And then
when chip->is_bridged is set true, change the state in the hardware to
the saved value?
What happens when port 0 is added to the bridge, there is then a
minute pause and then port 1 is added? I would expect that as soon as
port 0 is added, the STP state machine for port 0 will start and move
into listening and then forwarding. Due to hardware limitations it
looks like you cannot do this. So what state is the hardware
effectively in? Blocking? Forwarding?
Then port 1 is added. You can then can respect the states. port 1 will
do blocking->listening->forwarding, but what about port 0? The calls
won't get repeated? How does it transition to forwarding?
Andrew
From: Vivien Didelot <hidden> Date: 2017-09-21 14:30:31
Hi Egil,
Egil Hjelmeland [off-list ref] writes:
When both user ports are joined to the same bridge, the normal
HW MAC learning is enabled. This means that unicast traffic is forwarded
in HW.
If one of the user ports leave the bridge,
the ports goes back to the initial separated operation.
Port separation relies on disabled HW MAC learning. Hence the condition
that both ports must join same bridge.
Add brigde methods port_bridge_join, port_bridge_leave and
port_stp_state_set.
Signed-off-by: Egil Hjelmeland <redacted>
Styling nitpicks below, other than that, the patch LGTM:
Reviewed-by: Vivien Didelot <redacted>
That is unlikely to respect the Kernel Coding Style. Please fill the
line as much as possible and align with the opening parenthesis:
static int lan9303_write_switch_reg_mask(struct lan9303 *chip, u16 regnum,
u32 val, u32 mask)
@@ -21,6 +21,7 @@ struct lan9303 {structdsa_switch*ds;structmutexindirect_mutex;/* protect indexed register access */conststructlan9303_phy_ops*ops;+boolis_bridged;/* true if port 1 and 2 is bridged */};externconststructregmap_access_tablelan9303_register_set;
Please use the checkpatch.pl script to ensure your patch respects the
kernel conventions before submitting, it can spot nice stuffs!
I use a Git alias(*) to check a commit which does basically this:
git format-patch --stdout -1 | ./scripts/checkpatch.pl -
(*) in details, especially convenient during interactive rebases:
$ git config alias.checkcommit '!f () { git format-patch --stdout -1 ${1:-HEAD} | ./scripts/checkpatch.pl - ; }; f'
$ git checkcommit # i.e. current one
$ git checkcommit HEAD^^
$ git checkcommit d329ac88eb21
...
Thanks,
Vivien
From: Vivien Didelot <hidden> Date: 2017-09-21 14:44:14
Hi Egil,
Egil Hjelmeland [off-list ref] writes:
Prepare for next patch:
Move tag setup from lan9303_separate_ports() to new function
lan9303_setup_tagging()
Signed-off-by: Egil Hjelmeland <redacted>
Minor styling issues, otherwise LGTM:
Reviewed-by: Vivien Didelot <redacted>
+/* forward special tagged packets from port 0 to port 1 *or* port 2 */
+static int lan9303_setup_tagging(struct lan9303 *chip)
+{
+ int ret;
+ /* enable defining the destination port via special VLAN tagging
+ * for port 0
+ */
+ ret = lan9303_write_switch_reg(chip, LAN9303_SWE_INGRESS_PORT_TYPE,
+ LAN9303_SWE_INGRESS_PORT_TYPE_VLAN);
+ if (ret)
+ return ret;
+
+ /* tag incoming packets at port 1 and 2 on their way to port 0 to be
+ * able to discover their source port
+ */
+ return lan9303_write_switch_reg(
+ chip, LAN9303_BM_EGRSS_PORT_TYPE,
+ LAN9303_BM_EGRSS_PORT_TYPE_SPECIAL_TAG_PORT0);
Please avoid this kind of alignment as much as possible.
u32 val = LAN9303_BM_EGRSS_PORT_TYPE_SPECIAL_TAG_PORT0;
would do the trick for the +80 chars issue.
BTW, it'd be great to see sometime soon a cleanup patch which makes use
of such temporary u32 val variable for most of the
lan9303_write_switch_reg and lan9303_write_switch_port calls. ;-)
Thanks,
Vivien
Could you replace the 0 with something symbolic which makes this
easier to understand.
#define LAN9303_SWE_PORT_MIRROR_DISABLED 0
OK
quoted
+
static int lan9303_handle_reset(struct lan9303 *chip)
{
if (!chip->reset_gpio)
@@ -844,6 +866,69 @@ static void lan9303_port_disable(struct dsa_switch *ds, int port, } }+static int lan9303_port_bridge_join(struct dsa_switch *ds, int port,+ struct net_device *br)+{+ struct lan9303 *chip = ds->priv;++ dev_dbg(chip->dev, "%s(port %d)\n", __func__, port);+ if (ds->ports[1].bridge_dev == ds->ports[2].bridge_dev) {+ lan9303_bridge_ports(chip);+ chip->is_bridged = true; /* unleash stp_state_set() */+ }++ return 0;+}++static void lan9303_port_bridge_leave(struct dsa_switch *ds, int port,+ struct net_device *br)+{+ struct lan9303 *chip = ds->priv;++ dev_dbg(chip->dev, "%s(port %d)\n", __func__, port);+ if (chip->is_bridged) {+ lan9303_separate_ports(chip);+ chip->is_bridged = false;+ }+}++static void lan9303_port_stp_state_set(struct dsa_switch *ds, int port,+ u8 state)+{+ int portmask, portstate;+ struct lan9303 *chip = ds->priv;++ dev_dbg(chip->dev, "%s(port %d, state %d)\n",+ __func__, port, state);+ if (!chip->is_bridged)+ return; /* touching SWE_PORT_STATE will break port separation */
I'm wondering how this is supposed to work. Please add a good comment
here, since the hardware is forcing you to do something odd.
Maybe it would be a good idea to save the STP state in chip. And then
when chip->is_bridged is set true, change the state in the hardware to
the saved value?
What happens when port 0 is added to the bridge, there is then a
minute pause and then port 1 is added? I would expect that as soon as
port 0 is added, the STP state machine for port 0 will start and move
into listening and then forwarding. Due to hardware limitations it
looks like you cannot do this. So what state is the hardware
effectively in? Blocking? Forwarding?
Then port 1 is added. You can then can respect the states. port 1 will
do blocking->listening->forwarding, but what about port 0? The calls
won't get repeated? How does it transition to forwarding?
Andrew
I see your point with the "minute pause" argument. Although a bit
contrived use case, it is easy to fix by caching the STP state, as
you suggest. So I can do that.
The port separation method is from the original version of the driver,
not by me.
I have read through the datasheet to see if there are other ways
to make port separation, but I could not find anything.
If anybody care to read through the 300+ page lan9303.pdf and prove
me wrong, I am happy to do it differently.
How does other DSA HW chips handle port separation? Knowing that
could perhaps help me know what to look for.
Egil
'
When both user ports are joined to the same bridge, the normal
HW MAC learning is enabled. This means that unicast traffic is forwarded
in HW.
If one of the user ports leave the bridge,
the ports goes back to the initial separated operation.
Port separation relies on disabled HW MAC learning. Hence the condition
that both ports must join same bridge.
Add brigde methods port_bridge_join, port_bridge_leave and
port_stp_state_set.
Signed-off-by: Egil Hjelmeland <redacted>
Styling nitpicks below, other than that, the patch LGTM:
Reviewed-by: Vivien Didelot <redacted>
That is unlikely to respect the Kernel Coding Style. Please fill the
line as much as possible and align with the opening parenthesis:
static int lan9303_write_switch_reg_mask(struct lan9303 *chip, u16 regnum,
u32 val, u32 mask)
OK. Probably this function will go away in v2 due to Andrews comment.
@@ -21,6 +21,7 @@ struct lan9303 {structdsa_switch*ds;structmutexindirect_mutex;/* protect indexed register access */conststructlan9303_phy_ops*ops;+boolis_bridged;/* true if port 1 and 2 is bridged */};externconststructregmap_access_tablelan9303_register_set;
Please use the checkpatch.pl script to ensure your patch respects the
kernel conventions before submitting, it can spot nice stuffs!
I have checked _every_ patch with checkpatch.pl and weeded all warnings
before I submitted them.
I use a Git alias(*) to check a commit which does basically this:
git format-patch --stdout -1 | ./scripts/checkpatch.pl -
(*) in details, especially convenient during interactive rebases:
$ git config alias.checkcommit '!f () { git format-patch --stdout -1 ${1:-HEAD} | ./scripts/checkpatch.pl - ; }; f'
$ git checkcommit # i.e. current one
$ git checkcommit HEAD^^
$ git checkcommit d329ac88eb21
...
Thanks,
Vivien
From: Andrew Lunn <andrew@lunn.ch> Date: 2017-09-22 20:08:17
quoted
I'm wondering how this is supposed to work. Please add a good comment
here, since the hardware is forcing you to do something odd.
Maybe it would be a good idea to save the STP state in chip. And then
when chip->is_bridged is set true, change the state in the hardware to
the saved value?
What happens when port 0 is added to the bridge, there is then a
minute pause and then port 1 is added? I would expect that as soon as
port 0 is added, the STP state machine for port 0 will start and move
into listening and then forwarding. Due to hardware limitations it
looks like you cannot do this. So what state is the hardware
effectively in? Blocking? Forwarding?
Then port 1 is added. You can then can respect the states. port 1 will
do blocking->listening->forwarding, but what about port 0? The calls
won't get repeated? How does it transition to forwarding?
Andrew
I see your point with the "minute pause" argument. Although a bit
contrived use case, it is easy to fix by caching the STP state, as
you suggest. So I can do that.
I don't think it is contrived. I've done bridge configuration by hand
for testing purposes. I've also set the forwarding delay to very small
values, so there is a clear race condition here.
How does other DSA HW chips handle port separation? Knowing that
could perhaps help me know what to look for.
They have better hardware :-)
Generally each port is totally independent. You can change the STP
state per port without restrictions.
Andrew
I'm wondering how this is supposed to work. Please add a good comment
here, since the hardware is forcing you to do something odd.
Maybe it would be a good idea to save the STP state in chip. And then
when chip->is_bridged is set true, change the state in the hardware to
the saved value?
What happens when port 0 is added to the bridge, there is then a
minute pause and then port 1 is added? I would expect that as soon as
port 0 is added, the STP state machine for port 0 will start and move
into listening and then forwarding. Due to hardware limitations it
looks like you cannot do this. So what state is the hardware
effectively in? Blocking? Forwarding?
Then port 1 is added. You can then can respect the states. port 1 will
do blocking->listening->forwarding, but what about port 0? The calls
won't get repeated? How does it transition to forwarding?
Andrew
I see your point with the "minute pause" argument. Although a bit
contrived use case, it is easy to fix by caching the STP state, as
you suggest. So I can do that.
I don't think it is contrived. I've done bridge configuration by hand
for testing purposes. I've also set the forwarding delay to very small
values, so there is a clear race condition here.
quoted
How does other DSA HW chips handle port separation? Knowing that
could perhaps help me know what to look for.
They have better hardware :-)
Generally each port is totally independent. You can change the STP
state per port without restrictions.
We can indeed change the STP state per lan9303 port "without
restrictions".
The point is: Once both external ports are in "forwarding", I see no way
to prevent traffic flowing directly between the external ports.
From: Andrew Lunn <andrew@lunn.ch> Date: 2017-09-23 14:31:33
The point is: Once both external ports are in "forwarding", I see no way
to prevent traffic flowing directly between the external ports.
Generally, there are port vectors. Port X can send frames only to Port
Y.
If you don't have that, there are possibilities with VLANs. Each port
is given a unique VLAN. All incoming untagged traffic is tagged with
the VLAN. You just need to keep the VLAN separated and add/remove the
VLAN tag in the dsa tag driver.
Andrew
The point is: Once both external ports are in "forwarding", I see no way
to prevent traffic flowing directly between the external ports.
Generally, there are port vectors. Port X can send frames only to Port
Y.
If you don't have that, there are possibilities with VLANs. Each port
is given a unique VLAN. All incoming untagged traffic is tagged with
the VLAN. You just need to keep the VLAN separated and add/remove the
VLAN tag in the dsa tag driver.
Andrew
Thanks. The lan9303 has nothing like "port vectors". The port tagging
scheme is VLAN based, but is does not prevent direct forwarding between
the external ports.
In order to not break the strong port separation in the current driver;
I will stick to my solution, and only add caching of the STP state
register.
Egil