Skip to content

Commit

Permalink
Merge branch 'rtl8366-cleanups'
Browse files Browse the repository at this point in the history
Linus Walleij says:

====================
RTL8366(RB) cleanups part 1

This is a first set of patches making the RTL8366RB work out of
the box with a default OpenWrt userspace.

We achieve bridge port isolation with the first patch, and the
next 5 patches removes the very weird VLAN set-up with one
VLAN with PVID per port that has been in this driver in all
vendor trees and in OpenWrt for years.

The switch is now managed the way a modern bridge/DSA switch
shall be managed.

After these patches are merged, I will send the next set which
adds new features, some which have circulated before.

ChangeLog v4->v5:
- Drop the patch disabling 4K VLAN.
- Drop the patch forcing VLAN0 untagged.
- Fix a semantic bug in the filer enablement code.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Sep 27, 2021
2 parents d06d54a + d310b14 commit 13807de
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 105 deletions.
3 changes: 0 additions & 3 deletions drivers/net/dsa/realtek-smi-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ int rtl8366_set_pvid(struct realtek_smi *smi, unsigned int port,
int rtl8366_enable_vlan4k(struct realtek_smi *smi, bool enable);
int rtl8366_enable_vlan(struct realtek_smi *smi, bool enable);
int rtl8366_reset_vlan(struct realtek_smi *smi);
int rtl8366_init_vlan(struct realtek_smi *smi);
int rtl8366_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering,
struct netlink_ext_ack *extack);
int rtl8366_vlan_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan,
struct netlink_ext_ack *extack);
Expand Down
96 changes: 5 additions & 91 deletions drivers/net/dsa/rtl8366.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,89 +292,6 @@ int rtl8366_reset_vlan(struct realtek_smi *smi)
}
EXPORT_SYMBOL_GPL(rtl8366_reset_vlan);

int rtl8366_init_vlan(struct realtek_smi *smi)
{
int port;
int ret;

ret = rtl8366_reset_vlan(smi);
if (ret)
return ret;

/* Loop over the available ports, for each port, associate
* 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));
if (ret)
return ret;
}

return rtl8366_enable_vlan(smi, true);
}
EXPORT_SYMBOL_GPL(rtl8366_init_vlan);

int rtl8366_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering,
struct netlink_ext_ack *extack)
{
struct realtek_smi *smi = ds->priv;
struct rtl8366_vlan_4k vlan4k;
int ret;

/* Use VLAN nr port + 1 since VLAN0 is not valid */
if (!smi->ops->is_vlan_valid(smi, port + 1))
return -EINVAL;

dev_info(smi->dev, "%s filtering on port %d\n",
vlan_filtering ? "enable" : "disable",
port);

/* TODO:
* The hardware support filter ID (FID) 0..7, I have no clue how to
* support this in the driver when the callback only says on/off.
*/
ret = smi->ops->get_vlan_4k(smi, port + 1, &vlan4k);
if (ret)
return ret;

/* Just set the filter to FID 1 for now then */
ret = rtl8366_set_vlan(smi, port + 1,
vlan4k.member,
vlan4k.untag,
1);
if (ret)
return ret;

return 0;
}
EXPORT_SYMBOL_GPL(rtl8366_vlan_filtering);

int rtl8366_vlan_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan,
struct netlink_ext_ack *extack)
Expand All @@ -401,12 +318,9 @@ int rtl8366_vlan_add(struct dsa_switch *ds, int port,
return ret;
}

dev_info(smi->dev, "add VLAN %d on port %d, %s, %s\n",
vlan->vid, port, untagged ? "untagged" : "tagged",
pvid ? " PVID" : "no PVID");

if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
dev_err(smi->dev, "port is DSA or CPU port\n");
dev_dbg(smi->dev, "add VLAN %d on port %d, %s, %s\n",
vlan->vid, port, untagged ? "untagged" : "tagged",
pvid ? "PVID" : "no PVID");

member |= BIT(port);

Expand Down Expand Up @@ -439,7 +353,7 @@ int rtl8366_vlan_del(struct dsa_switch *ds, int port,
struct realtek_smi *smi = ds->priv;
int ret, i;

dev_info(smi->dev, "del VLAN %04x on port %d\n", vlan->vid, port);
dev_dbg(smi->dev, "del VLAN %d on port %d\n", vlan->vid, port);

for (i = 0; i < smi->num_vlan_mc; i++) {
struct rtl8366_vlan_mc vlanmc;
Expand All @@ -457,7 +371,7 @@ int rtl8366_vlan_del(struct dsa_switch *ds, int port,
* anymore then clear the whole member
* config so it can be reused.
*/
if (!vlanmc.member && vlanmc.untag) {
if (!vlanmc.member) {
vlanmc.vid = 0;
vlanmc.priority = 0;
vlanmc.fid = 0;
Expand Down
Loading

0 comments on commit 13807de

Please sign in to comment.