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. 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. 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. Signed-off-by: Mieczyslaw Nalewaj --- drivers/net/dsa/realtek/rtl8365mb.h | 8 ++ drivers/net/dsa/realtek/rtl8365mb_main.c | 4 + drivers/net/dsa/realtek/rtl8365mb_vlan.c | 102 +++++++++++++++++++++-- drivers/net/dsa/realtek/rtl8365mb_vlan.h | 6 ++ 4 files changed, 112 insertions(+), 8 deletions(-) diff --git a/drivers/net/dsa/realtek/rtl8365mb.h b/drivers/net/dsa/realtek/rtl8365mb.h index d3d5fb3..e7f03d9 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; @@ -24,6 +26,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 c693046..77ad84e 100644 --- a/drivers/net/dsa/realtek/rtl8365mb_main.c +++ b/drivers/net/dsa/realtek/rtl8365mb_main.c @@ -759,6 +759,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 f3ac294..85880c3 100644 --- a/drivers/net/dsa/realtek/rtl8365mb_vlan.c +++ b/drivers/net/dsa/realtek/rtl8365mb_vlan.c @@ -806,7 +806,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 @@ -816,7 +816,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; @@ -830,6 +831,44 @@ 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 + * + * On family C the neutral PVID is VLANMC index 0, which is already the reset + * value of the PVID control register, so there is nothing to do. Leave it + * untouched 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 @@ -892,8 +931,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 @@ -907,8 +946,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; @@ -1000,7 +1039,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 @@ -1012,7 +1076,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; @@ -1085,3 +1149,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