From: Mieczyslaw Nalewaj <namiltd@yahoo.com>
To: linusw@kernel.org, andrew@lunn.ch, olteanv@gmail.com,
kuba@kernel.org, davem@davemloft.net, edumazet@google.com,
pabeni@redhat.com, linux@armlinux.org.uk, luizluca@gmail.com,
maxime.chevallier@bootlin.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, alvin.sipraga@analog.com,
gusfmora@gmail.com, kuncy7@gmail.com, fabianotassotti@gmail.com,
gabonpivovich@gmail.com, contact@c127.dev,
o.rempel@pengutronix.de
Subject: [PATCH net-next v20 08/15] net: dsa: realtek: rtl8365mb: refactor PVID handling
Date: Fri, 4 Dec 2026 23:06:56 +0100 [thread overview]
Message-ID: <76c9fc36-6926-46ab-bdc0-e8eefcd0c8d5@yahoo.com> (raw)
In-Reply-To: <9efcb80a-517c-4413-8261-4f9380e0eb83@yahoo.com>
The PVID helpers (rtl8365mb_vlan_port_get_pvid(),
rtl8365mb_vlan_pvid_port_set() and rtl8365mb_vlan_pvid_port_clear())
work on a VLAN MC table index, which only family C has. Family D stores
a raw VID in a per-port register, so it needs its own implementation, and
also needs its PVID registers cleared at setup.
Move the helpers behind struct rtl8365mb_family_info, as already done
for the VLAN 4k accessors: the existing code becomes the family C
implementation (rtl8365mb_c_vlan_port_get_pvid() and the like), and
the three functions above only call it through the vlan_port_get_pvid,
vlan_pvid_port_set and vlan_pvid_port_clear pointers in the family
info. Also add a vlan_port_reset_pvid hook, implemented as a no-op on
family C (rtl8365mb_c_vlan_port_reset_pvid()) so existing setup
behavior is preserved. The callers are not changed. The following patch
adds the family D implementation without any is_d() check in the shared
code.
No functional change.
The family C functions are not static because they are referenced from
the family C info in rtl8365mb_main.c.
Tested-by: Gustavo Foletto Mora <gusfmora@gmail.com>
Signed-off-by: Mieczyslaw Nalewaj <namiltd@yahoo.com>
---
drivers/net/dsa/realtek/rtl8365mb.h | 8 ++
drivers/net/dsa/realtek/rtl8365mb_main.c | 4 +
drivers/net/dsa/realtek/rtl8365mb_vlan.c | 101 +++++++++++++++++++++--
drivers/net/dsa/realtek/rtl8365mb_vlan.h | 6 ++
4 files changed, 111 insertions(+), 8 deletions(-)
diff --git a/drivers/net/dsa/realtek/rtl8365mb.h b/drivers/net/dsa/realtek/rtl8365mb.h
index be0f49e..c59e657 100644
--- a/drivers/net/dsa/realtek/rtl8365mb.h
+++ b/drivers/net/dsa/realtek/rtl8365mb.h
@@ -9,6 +9,8 @@ enum rtl8365mb_family {
RTL8365MB_FAMILY_D,
};
+struct dsa_switch;
+struct netlink_ext_ack;
struct rtl8365mb_jam_tbl_entry;
struct rtl8365mb_vlan4k;
@@ -23,6 +25,12 @@ struct rtl8365mb_family_info {
struct rtl8365mb_vlan4k *vlan4k);
int (*vlan_4k_write)(struct realtek_priv *priv,
const struct rtl8365mb_vlan4k *vlan4k);
+ int (*vlan_port_get_pvid)(struct realtek_priv *priv, int port,
+ u16 *pvid);
+ int (*vlan_port_reset_pvid)(struct realtek_priv *priv, int port);
+ int (*vlan_pvid_port_set)(struct dsa_switch *ds, int port, u16 vid,
+ struct netlink_ext_ack *extack);
+ int (*vlan_pvid_port_clear)(struct dsa_switch *ds, int port, u16 vid);
};
const struct rtl8365mb_family_info *
diff --git a/drivers/net/dsa/realtek/rtl8365mb_main.c b/drivers/net/dsa/realtek/rtl8365mb_main.c
index d1f1b4a..0aa4d96 100644
--- a/drivers/net/dsa/realtek/rtl8365mb_main.c
+++ b/drivers/net/dsa/realtek/rtl8365mb_main.c
@@ -765,6 +765,10 @@ static const struct rtl8365mb_family_info rtl8365mb_family_c = {
.ext_config_forcemode = rtl8365mb_c_ext_config_forcemode,
.vlan_4k_read = rtl8365mb_c_vlan_4k_read,
.vlan_4k_write = rtl8365mb_c_vlan_4k_write,
+ .vlan_port_get_pvid = rtl8365mb_c_vlan_port_get_pvid,
+ .vlan_port_reset_pvid = rtl8365mb_c_vlan_port_reset_pvid,
+ .vlan_pvid_port_set = rtl8365mb_c_vlan_pvid_port_set,
+ .vlan_pvid_port_clear = rtl8365mb_c_vlan_pvid_port_clear,
};
/**
diff --git a/drivers/net/dsa/realtek/rtl8365mb_vlan.c b/drivers/net/dsa/realtek/rtl8365mb_vlan.c
index ca2815b..1463d5f 100644
--- a/drivers/net/dsa/realtek/rtl8365mb_vlan.c
+++ b/drivers/net/dsa/realtek/rtl8365mb_vlan.c
@@ -864,7 +864,7 @@ static int rtl8365mb_vlan_get_pvid_mc(struct realtek_priv *priv,
}
/*
- * rtl8365mb_vlan_port_get_pvid - Retrieve the port PVID
+ * rtl8365mb_c_vlan_port_get_pvid - Retrieve the port PVID (family C)
* @priv: realtek switch private structure
* @port: port index
* @pvid: pointer to store the retrieved VLAN ID
@@ -874,7 +874,8 @@ static int rtl8365mb_vlan_get_pvid_mc(struct realtek_priv *priv,
* Context: Can sleep. Takes and releases &priv->map_lock.
* Return: 0 on success or a negative error code on failure.
*/
-int rtl8365mb_vlan_port_get_pvid(struct realtek_priv *priv, int port, u16 *pvid)
+int rtl8365mb_c_vlan_port_get_pvid(struct realtek_priv *priv, int port,
+ u16 *pvid)
{
struct rtl8365mb_vlanmc vlanmc;
u8 vlanmc_idx;
@@ -888,6 +889,43 @@ int rtl8365mb_vlan_port_get_pvid(struct realtek_priv *priv, int port, u16 *pvid)
return 0;
}
+/*
+ * rtl8365mb_c_vlan_port_reset_pvid() - Put a port's PVID in its neutral state
+ * (family C)
+ * @priv: realtek_priv pointer
+ * @port: the port number
+ *
+ * Family C is left as it was before family D support: its PVID registers are
+ * not touched at setup, to preserve existing driver behavior.
+ *
+ * Return: 0.
+ */
+int rtl8365mb_c_vlan_port_reset_pvid(struct realtek_priv *priv, int port)
+{
+ return 0;
+}
+
+/*
+ * rtl8365mb_vlan_port_get_pvid() - Retrieve the port PVID
+ * @priv: realtek switch private structure
+ * @port: port index
+ * @pvid: pointer to store the retrieved VLAN ID
+ *
+ * Returns the port PVID if defined or 0 if not, as implemented by the chip
+ * family.
+ *
+ * Context: Can sleep. Takes and releases &priv->map_lock.
+ * Return: 0 on success or a negative error code on failure.
+ */
+int rtl8365mb_vlan_port_get_pvid(struct realtek_priv *priv, int port, u16 *pvid)
+{
+ const struct rtl8365mb_family_info *fi;
+
+ fi = rtl8365mb_get_family_info(priv);
+
+ return fi->vlan_port_get_pvid(priv, port, pvid);
+}
+
/*
* rtl8365mb_vlan_port_get_framefilter() - Get the ingress frame filtering mode
* for a port
@@ -950,8 +988,8 @@ rtl8365mb_vlan_port_set_framefilter(struct realtek_priv *priv,
}
/*
- * rtl8365mb_vlan_pvid_port_set() - Configure a port's PVID and associated
- * VLANMC entry
+ * rtl8365mb_c_vlan_pvid_port_set() - Configure a port's PVID and associated
+ * VLANMC entry (family C)
* @ds: dsa switch instance
* @port: port index
* @vid: target VID
@@ -965,8 +1003,8 @@ rtl8365mb_vlan_port_set_framefilter(struct realtek_priv *priv,
* Takes and releases &priv->map_lock.
* Return: 0 on success, or a negative error code on failure.
*/
-int rtl8365mb_vlan_pvid_port_set(struct dsa_switch *ds, int port, u16 vid,
- struct netlink_ext_ack *extack)
+int rtl8365mb_c_vlan_pvid_port_set(struct dsa_switch *ds, int port, u16 vid,
+ struct netlink_ext_ack *extack)
{
enum rtl8365mb_frame_ingress accepted_frame, prev_accepted_frame;
struct realtek_priv *priv = ds->priv;
@@ -1058,7 +1096,32 @@ undo_vlan_mc_port_set:
}
/*
- * rtl8365mb_vlan_pvid_port_clear() - Remove a port's PVID configuration
+ * rtl8365mb_vlan_pvid_port_set() - Configure a port's PVID
+ * @ds: dsa switch instance
+ * @port: port index
+ * @vid: target VID
+ * @extack: netlink extended ACK for error reporting
+ *
+ * Configures the PVID as implemented by the chip family.
+ *
+ * Context: Can sleep. Must be called with &priv->vlan_lock held.
+ * Takes and releases &priv->map_lock.
+ * Return: 0 on success, or a negative error code on failure.
+ */
+int rtl8365mb_vlan_pvid_port_set(struct dsa_switch *ds, int port, u16 vid,
+ struct netlink_ext_ack *extack)
+{
+ const struct rtl8365mb_family_info *fi;
+ struct realtek_priv *priv = ds->priv;
+
+ fi = rtl8365mb_get_family_info(priv);
+
+ return fi->vlan_pvid_port_set(ds, port, vid, extack);
+}
+
+/*
+ * rtl8365mb_c_vlan_pvid_port_clear() - Remove a port's PVID configuration
+ * (family C)
* @ds: dsa switch instance
* @port: port index
* @vid: VLAN VID for PVID
@@ -1070,7 +1133,7 @@ undo_vlan_mc_port_set:
* Takes and releases &priv->map_lock.
* Return: 0 on success, or a negative error code on failure.
*/
-int rtl8365mb_vlan_pvid_port_clear(struct dsa_switch *ds, int port, u16 vid)
+int rtl8365mb_c_vlan_pvid_port_clear(struct dsa_switch *ds, int port, u16 vid)
{
enum rtl8365mb_frame_ingress accepted_frame, prev_accepted_frame;
struct realtek_priv *priv = ds->priv;
@@ -1143,3 +1206,25 @@ undo_set_framefilter:
return ret;
}
+
+/*
+ * rtl8365mb_vlan_pvid_port_clear() - Remove a port's PVID configuration
+ * @ds: dsa switch instance
+ * @port: port index
+ * @vid: VLAN VID for PVID
+ *
+ * Removes the PVID as implemented by the chip family.
+ *
+ * Context: Can sleep. Must be called with &priv->vlan_lock held.
+ * Takes and releases &priv->map_lock.
+ * Return: 0 on success, or a negative error code on failure.
+ */
+int rtl8365mb_vlan_pvid_port_clear(struct dsa_switch *ds, int port, u16 vid)
+{
+ const struct rtl8365mb_family_info *fi;
+ struct realtek_priv *priv = ds->priv;
+
+ fi = rtl8365mb_get_family_info(priv);
+
+ return fi->vlan_pvid_port_clear(ds, port, vid);
+}
diff --git a/drivers/net/dsa/realtek/rtl8365mb_vlan.h b/drivers/net/dsa/realtek/rtl8365mb_vlan.h
index 625d4c1..62ee59c 100644
--- a/drivers/net/dsa/realtek/rtl8365mb_vlan.h
+++ b/drivers/net/dsa/realtek/rtl8365mb_vlan.h
@@ -28,6 +28,12 @@ int rtl8365mb_d_vlan_4k_read(struct realtek_priv *priv, u16 vid,
struct rtl8365mb_vlan4k *vlan4k);
int rtl8365mb_d_vlan_4k_write(struct realtek_priv *priv,
const struct rtl8365mb_vlan4k *vlan4k);
+int rtl8365mb_c_vlan_port_get_pvid(struct realtek_priv *priv, int port,
+ u16 *pvid);
+int rtl8365mb_c_vlan_port_reset_pvid(struct realtek_priv *priv, int port);
+int rtl8365mb_c_vlan_pvid_port_set(struct dsa_switch *ds, int port, u16 vid,
+ struct netlink_ext_ack *extack);
+int rtl8365mb_c_vlan_pvid_port_clear(struct dsa_switch *ds, int port, u16 vid);
int rtl8365mb_vlan_port_get_pvid(struct realtek_priv *priv, int port,
u16 *pvid);
--
2.53.0
next prev parent reply other threads:[~2026-12-04 22:07 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <9efcb80a-517c-4413-8261-4f9380e0eb83.ref@yahoo.com>
2026-12-04 22:01 ` [PATCH net-next v20 00/15] net: dsa: realtek: rtl8365mb: add support for RTL8367S-VB Mieczyslaw Nalewaj
2026-12-04 22:03 ` [PATCH net-next v20 01/15] dt-bindings: net: dsa: realtek: add RTL8367S-VB Mieczyslaw Nalewaj
2026-12-04 22:03 ` [PATCH net-next v20 02/15] net: dsa: realtek: rtl8365mb: add chip family infrastructure Mieczyslaw Nalewaj
2026-12-04 22:04 ` [PATCH net-next v20 03/15] net: dsa: realtek: rtl8365mb: refactor forcemode handling Mieczyslaw Nalewaj
2026-12-04 22:04 ` [PATCH net-next v20 04/15] net: dsa: realtek: rtl8365mb: set speed for family D Mieczyslaw Nalewaj
2026-12-04 22:04 ` [PATCH net-next v20 05/15] net: dsa: realtek: rtl8365mb: set RGMII mode " Mieczyslaw Nalewaj
2026-12-04 22:04 ` [PATCH net-next v20 06/15] net: dsa: realtek: rtl8365mb: refactor VLAN 4k handling Mieczyslaw Nalewaj
2026-12-04 22:04 ` [PATCH net-next v20 07/15] net: dsa: realtek: rtl8365mb: add VLAN 4k/IVL for family D Mieczyslaw Nalewaj
2026-12-04 22:06 ` Mieczyslaw Nalewaj [this message]
2026-12-04 22:07 ` [PATCH net-next v20 09/15] net: dsa: realtek: rtl8365mb: use raw VID for PVID on " Mieczyslaw Nalewaj
2026-12-04 22:07 ` [PATCH net-next v20 10/15] net: dsa: realtek: rtl8365mb: add family D SDS13 PCS support Mieczyslaw Nalewaj
2026-12-04 22:07 ` [PATCH net-next v20 11/15] net: dsa: realtek: rtl8365mb: refactor L2 MAC handling Mieczyslaw Nalewaj
2026-12-04 22:07 ` [PATCH net-next v20 13/15] net: dsa: realtek: rtl8365mb: refactor QoS priority handling Mieczyslaw Nalewaj
2026-12-04 22:07 ` [PATCH net-next v20 12/15] net: dsa: realtek: rtl8365mb: make L2/LUT access work on family D Mieczyslaw Nalewaj
2026-12-04 22:07 ` [PATCH net-next v20 15/15] net: dsa: realtek: rtl8365mb: add support for RTL8367S-VB Mieczyslaw Nalewaj
2026-12-04 22:08 ` [PATCH net-next v20 14/15] net: dsa: realtek: rtl8365mb: use PCP numbering on family D Mieczyslaw Nalewaj
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=76c9fc36-6926-46ab-bdc0-e8eefcd0c8d5@yahoo.com \
--to=namiltd@yahoo.com \
--cc=alvin.sipraga@analog.com \
--cc=andrew@lunn.ch \
--cc=contact@c127.dev \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=fabianotassotti@gmail.com \
--cc=gabonpivovich@gmail.com \
--cc=gusfmora@gmail.com \
--cc=kuba@kernel.org \
--cc=kuncy7@gmail.com \
--cc=linusw@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=luizluca@gmail.com \
--cc=maxime.chevallier@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=o.rempel@pengutronix.de \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.