From: Linus Walleij <linus.walleij@linaro.org>
To: Andrew Lunn <andrew@lunn.ch>,
Vivien Didelot <vivien.didelot@gmail.com>,
Florian Fainelli <f.fainelli@gmail.com>,
netdev@vger.kernel.org, "David S . Miller" <davem@davemloft.net>
Cc: Linus Walleij <linus.walleij@linaro.org>,
DENG Qingfang <dqfext@gmail.com>,
Mauri Sandberg <sandberg@mailfence.com>
Subject: [net-next PATCH 3/5 v4] net: dsa: rtl8366: Split out default VLAN config
Date: Mon, 6 Jul 2020 22:52:43 +0200 [thread overview]
Message-ID: <20200706205245.937091-4-linus.walleij@linaro.org> (raw)
In-Reply-To: <20200706205245.937091-1-linus.walleij@linaro.org>
We loop over the ports to initialize the default VLAN
and PVID for each port. As we need to reuse the
code to reinitialize a single port, break out the
function rtl8366_set_default_vlan_and_pvid().
Cc: DENG Qingfang <dqfext@gmail.com>
Cc: Mauri Sandberg <sandberg@mailfence.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
ChangeLog v3->v4:
- Resend with the rest
ChangeLog v2->v3:
- Rebased on Andrew's patch for the (int) compile warning
on GENMASK(). change is carried over.
- Collect Andrew's review tag.
ChangeLog v1->v2:
- Rebased on v5.8-rc1 and other changes.
---
drivers/net/dsa/rtl8366.c | 70 ++++++++++++++++++++++++---------------
1 file changed, 43 insertions(+), 27 deletions(-)
diff --git a/drivers/net/dsa/rtl8366.c b/drivers/net/dsa/rtl8366.c
index 993cf3ac59d9..b907c0ed9697 100644
--- a/drivers/net/dsa/rtl8366.c
+++ b/drivers/net/dsa/rtl8366.c
@@ -253,6 +253,48 @@ int rtl8366_reset_vlan(struct realtek_smi *smi)
}
EXPORT_SYMBOL_GPL(rtl8366_reset_vlan);
+static int rtl8366_set_default_vlan_and_pvid(struct realtek_smi *smi,
+ int port)
+{
+ u32 mask;
+ u16 vid;
+ int ret;
+
+ /* This is the reserved default VLAN for this port */
+ vid = port + 1;
+
+ if (port == smi->cpu_port)
+ /* For the CPU port, make all ports members of this
+ * VLAN.
+ */
+ mask = GENMASK((int)smi->num_ports - 1, 0);
+ else
+ /* For all other ports, enable itself plus the
+ * CPU port.
+ */
+ mask = BIT(port) | BIT(smi->cpu_port);
+
+ /* For each port, set the port as member of VLAN (port+1)
+ * and untagged, except for the CPU port: the CPU port (5) is
+ * member of VLAN 6 and so are ALL the other ports as well.
+ * Use filter 0 (no filter).
+ */
+ dev_info(smi->dev, "Set VLAN %04x portmask to %08x (port %d %s)\n",
+ vid, mask, port, (port == smi->cpu_port) ?
+ "CPU PORT and all other ports" : "and CPU port");
+ ret = rtl8366_set_vlan(smi, vid, mask, mask, 0);
+ if (ret)
+ return ret;
+
+ dev_info(smi->dev, "Set PVID %04x on port %d\n",
+ vid, port);
+ ret = rtl8366_set_pvid(smi, port, vid);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
int rtl8366_init_vlan(struct realtek_smi *smi)
{
int port;
@@ -266,33 +308,7 @@ int rtl8366_init_vlan(struct realtek_smi *smi)
* it with the VLAN (port+1)
*/
for (port = 0; port < smi->num_ports; port++) {
- u32 mask;
-
- if (port == smi->cpu_port)
- /* For the CPU port, make all ports members of this
- * VLAN.
- */
- mask = GENMASK((int)smi->num_ports - 1, 0);
- else
- /* For all other ports, enable itself plus the
- * CPU port.
- */
- mask = BIT(port) | BIT(smi->cpu_port);
-
- /* For each port, set the port as member of VLAN (port+1)
- * and untagged, except for the CPU port: the CPU port (5) is
- * member of VLAN 6 and so are ALL the other ports as well.
- * Use filter 0 (no filter).
- */
- dev_info(smi->dev, "VLAN%d port mask for port %d, %08x\n",
- (port + 1), port, mask);
- ret = rtl8366_set_vlan(smi, (port + 1), mask, mask, 0);
- if (ret)
- return ret;
-
- dev_info(smi->dev, "VLAN%d port %d, PVID set to %d\n",
- (port + 1), port, (port + 1));
- ret = rtl8366_set_pvid(smi, port, (port + 1));
+ ret = rtl8366_set_default_vlan_and_pvid(smi, port);
if (ret)
return ret;
}
--
2.26.2
next prev parent reply other threads:[~2020-07-06 20:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-06 20:52 [net-next PATCH 0/5 v4] RTL8366RB DSA tagging and fixes Linus Walleij
2020-07-06 20:52 ` [net-next PATCH 1/5 v4] net: dsa: tag_rtl4_a: Implement Realtek 4 byte A tag Linus Walleij
2020-07-06 20:52 ` [net-next PATCH 2/5 v4] net: dsa: rtl8366rb: Support the CPU DSA tag Linus Walleij
2020-07-06 20:52 ` Linus Walleij [this message]
2020-07-06 20:52 ` [net-next PATCH 4/5 v4] net: dsa: rtl8366: VLAN 0 as disable tagging Linus Walleij
2020-07-06 21:23 ` Florian Fainelli
2020-07-07 7:20 ` Vladimir Oltean
2020-07-08 13:34 ` Linus Walleij
2020-07-06 20:52 ` [net-next PATCH 5/5 v4] net: dsa: rtl8366: Use top VLANs for default Linus Walleij
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=20200706205245.937091-4-linus.walleij@linaro.org \
--to=linus.walleij@linaro.org \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=dqfext@gmail.com \
--cc=f.fainelli@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=sandberg@mailfence.com \
--cc=vivien.didelot@gmail.com \
/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