net: dsa: realtek: rtl8365mb: add VLAN support
authorAlvin Šipraga <alsi@bang-olufsen.dk>
Sat, 6 Jun 2026 08:29:30 +0000 (05:29 -0300)
committerJakub Kicinski <kuba@kernel.org>
Wed, 10 Jun 2026 02:35:42 +0000 (19:35 -0700)
commit9da2c8672f77108a1f09232320f22225ab53dde9
treebf6be69a7f1df08d8fe794bcff496f7a0625a764
parentfbafdd3b224a03b7b335de144f44a600de937586
net: dsa: realtek: rtl8365mb: add VLAN support

Realtek RTL8365MB switches (a.k.a. RTL8367C family) use two different
structures for VLANs:

- VLAN4K: A full table with 4096 entries defining port membership and
  tagging.
- VLANMC: A smaller table with 32 entries used primarily for PVID
  assignment.

In this hardware, a port's PVID must point to an index in the VLANMC
table rather than a VID directly. Since the VLANMC table is limited to
32 entries, the driver implements a dynamic allocation scheme to
maximize resource usage:

- VLAN4K is treated by the driver as the source of truth for membership.
- A VLANMC entry is only allocated when a port is configured to use a
  specific VID as its PVID.
- VLANMC entries are deleted when no longer needed as a PVID by any port.

Although VLANMC has a members field, the switch only checks membership
in the VLAN4K table. This driver will use VLANMC members field as way to
track which ports are using that entry as PVID.

VLANMC index 0, although a valid entry, is reserved in this driver as a
neutral PVID value for ports not using a specific PVID.

In the subsequent RTL8367D switch family, VLANMC table was
removed and PVID assignment was delegated to a dedicated set of
registers.

The use of FIELD_PREP for reconstructing LO/HI values was suggested by
Yury Norov.

Fix for vlan_setup and vlan_filtering was suggested by Abdulkader
Alrezej.

Suggested-by: Yury Norov <ynorov@nvidia.com>
Suggested-by: Abdulkader Alrezej <abdulkader.alrezej@gmail.com>
Signed-off-by: Alvin Šipraga <alsi@bang-olufsen.dk>
Reviewed-by: Linus Walleij <linusw@kernel.org>
Reviewed-by: Mieczyslaw Nalewaj <namiltd@yahoo.com>
Co-developed-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
Link: https://patch.msgid.link/20260606-realtek_forward-v13-6-b9e409687cbe@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/dsa/realtek/Makefile
drivers/net/dsa/realtek/realtek.h
drivers/net/dsa/realtek/rtl8365mb_main.c
drivers/net/dsa/realtek/rtl8365mb_vlan.c [new file with mode: 0644]
drivers/net/dsa/realtek/rtl8365mb_vlan.h [new file with mode: 0644]
drivers/net/dsa/realtek/rtl83xx.c