Re: [PATCH net-next v7 05/10] net: dsa: realtek: rtl8365mb: set and get vlan 4k for family D

From: Mieczyslaw Nalewaj

Date: Mon Nov 09 2026 - 17:07:02 EST


On Mon, Nov 9, 2026 at 2:31 AM, Luiz Angelo Daros de Luca wrote:
> This is how I'm structuring it now, though it might migrate to
> function pointers later. A family check inside a shared function only
> makes sense for very localized differences. Since family A is shaping
> up well and family B sits conceptually between A and C, `is_d` doesn't
> scale well for future variants.

We are completely on the same page here. In the upcoming v10 patchset,
I have already migrated to function pointers to handle these
family-specific differences cleanly.

I introduced a dedicated `struct rtl8365mb_family_info` which has made it possible to reduce the use of `switch` statements:


struct rtl8365mb_family_info {
enum rtl8365mb_family family;
unsigned int num_ports;
const struct rtl8365mb_jam_tbl_entry *jam_table;
size_t jam_size;
int (*ext_config_forcemode)(struct realtek_priv *priv, int port,
bool link, int speed, int duplex,
bool tx_pause, bool rx_pause);
int (*vlan_4k_read)(struct realtek_priv *priv, u16 vid,
struct rtl8365mb_vlan4k *vlan4k);
int (*vlan_4k_write)(struct realtek_priv *priv,
const struct rtl8365mb_vlan4k *vlan4k);
size_t l2_entry_size;
void (*l2_data_to_uc)(const u16 *data, struct rtl8365mb_l2_uc *uc);
void (*l2_uc_to_data)(const struct rtl8365mb_l2_uc *uc, u16 *data);
void (*l2_data_to_mc)(const u16 *data, struct rtl8365mb_l2_mc *mc);
void (*l2_mc_to_data)(const struct rtl8365mb_l2_mc *mc, u16 *data);
};

static const struct rtl8365mb_family_info rtl8365mb_family_c = {
.family = RTL8365MB_FAMILY_C,
.num_ports = RTL8365MB_C_MAX_NUM_PORTS,
.jam_table = rtl8365mb_init_jam_8365mb_vc,
.jam_size = ARRAY_SIZE(rtl8365mb_init_jam_8365mb_vc),
.ext_config_forcemode = rtl8365mb_c_ext_config_forcemode,
.vlan_4k_read = rtl8365mb_c_vlan_4k_read,
.vlan_4k_write = rtl8365mb_c_vlan_4k_write,
.l2_entry_size = RTL8365MB_C_L2_ENTRY_SIZE,
.l2_data_to_uc = rtl8365mb_c_l2_data_to_uc,
.l2_uc_to_data = rtl8365mb_c_l2_uc_to_data,
.l2_data_to_mc = rtl8365mb_c_l2_data_to_mc,
.l2_mc_to_data = rtl8365mb_c_l2_mc_to_data,
};

static const struct rtl8365mb_family_info rtl8365mb_family_d = {
.family = RTL8365MB_FAMILY_D,
.num_ports = RTL8365MB_D_MAX_NUM_PORTS,
.jam_table = rtl8365mb_init_jam_8365mb_vc,
.jam_size = ARRAY_SIZE(rtl8365mb_init_jam_8365mb_vc),
.ext_config_forcemode = rtl8365mb_d_ext_config_forcemode,
.vlan_4k_read = rtl8365mb_d_vlan_4k_read,
.vlan_4k_write = rtl8365mb_d_vlan_4k_write,
.l2_entry_size = RTL8365MB_D_L2_ENTRY_SIZE,
.l2_data_to_uc = rtl8365mb_d_l2_data_to_uc,
.l2_uc_to_data = rtl8365mb_d_l2_uc_to_data,
.l2_data_to_mc = rtl8365mb_d_l2_data_to_mc,
.l2_mc_to_data = rtl8365mb_d_l2_mc_to_data,
};


This infrastructure should make it very straightforward to hook up
your upcoming Family A support without duplicating logic or bloating
the shared functions.

Best regards,
Mieczyslaw