[PATCH net-next v12 02/13] net: dsa: realtek: rtl8365mb: add chip family infrastructure

From: Mieczyslaw Nalewaj

Date: Thu Nov 19 2026 - 19:00:10 EST


Add enum rtl8365mb_family and struct rtl8365mb_family_info, which holds
the data shared by all chips of one family: the family id and the init
jam table. struct rtl8365mb_chip_info now points to it through a
family_info member, and all existing chips use the RTL8365MB_FAMILY_C
instance. rtl8365mb_get_family_info() and rtl8365mb_is_d() are declared
in a new rtl8365mb.h so that the VLAN code can use them too.

The available ports of a chip are already described by port_mask in
struct rtl8365mb_chip_info, so the family info does not carry a port
count.

RTL8365MB_FAMILY_D is defined here but no chip uses it yet; it is
needed by the following patches, which add family D handling for chips
whose register layout differs from the existing ones.

No functional change.

Tested-by: Gustavo Foletto Mora <gusfmora@xxxxxxxxx>
Tested-by: Stanislaw Pal <kuncy7@xxxxxxxxx>
Tested-by: Oleg Gavrilov <gabonpivovich@xxxxxxxxx>
Signed-off-by: Mieczyslaw Nalewaj <namiltd@xxxxxxxxx>
Reviewed-by: Linus Walleij <linusw@xxxxxxxxxx>
---
drivers/net/dsa/realtek/rtl8365mb.h | 28 ++++++++++++++
drivers/net/dsa/realtek/rtl8365mb_main.c | 47 ++++++++++++++----------
2 files changed, 56 insertions(+), 19 deletions(-)
create mode 100644 drivers/net/dsa/realtek/rtl8365mb.h

diff --git a/drivers/net/dsa/realtek/rtl8365mb.h b/drivers/net/dsa/realtek/rtl8365mb.h
new file mode 100644
index 0000000..7b0c710
--- /dev/null
+++ b/drivers/net/dsa/realtek/rtl8365mb.h
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _RTL8365MB_H
+#define _RTL8365MB_H
+
+#include "realtek.h"
+
+enum rtl8365mb_family {
+ RTL8365MB_FAMILY_C,
+ RTL8365MB_FAMILY_D,
+};
+
+struct rtl8365mb_jam_tbl_entry;
+
+struct rtl8365mb_family_info {
+ enum rtl8365mb_family family;
+ const struct rtl8365mb_jam_tbl_entry *jam_table;
+ size_t jam_size;
+};
+
+const struct rtl8365mb_family_info *
+rtl8365mb_get_family_info(struct realtek_priv *priv);
+
+static inline bool rtl8365mb_is_d(struct realtek_priv *priv)
+{
+ return rtl8365mb_get_family_info(priv)->family == RTL8365MB_FAMILY_D;
+}
+
+#endif /* _RTL8365MB_H */
diff --git a/drivers/net/dsa/realtek/rtl8365mb_main.c b/drivers/net/dsa/realtek/rtl8365mb_main.c
index 6c11c36..e101d15 100644
--- a/drivers/net/dsa/realtek/rtl8365mb_main.c
+++ b/drivers/net/dsa/realtek/rtl8365mb_main.c
@@ -112,6 +112,7 @@
#include "rtl8365mb_qos.h"
#include "rtl8365mb_l2.h"
#include "rtl8365mb_vlan.h"
+#include "rtl8365mb.h"

/* Family-specific data and limits */
#define RTL8365MB_PHYADDRMAX 7
@@ -704,15 +705,20 @@ struct rtl8365mb_extint {
unsigned int supported_interfaces;
};

+static const struct rtl8365mb_family_info rtl8365mb_family_c = {
+ .family = RTL8365MB_FAMILY_C,
+ .jam_table = rtl8365mb_init_jam_8365mb_vc,
+ .jam_size = ARRAY_SIZE(rtl8365mb_init_jam_8365mb_vc),
+};
+
/**
* struct rtl8365mb_chip_info - static chip-specific info
* @name: human-readable chip name
* @chip_id: chip identifier
* @chip_ver: chip silicon revision
* @port_mask: ports the chip has
+ * @family_info: data shared by all chips of the same family
* @extints: available external interfaces
- * @jam_table: chip-specific initialization jam table
- * @jam_size: size of the chip's jam table
* @num_tx_queues: number of egress queues exposed by the chip
*
* These data are specific to a given chip in the family of switches supported
@@ -724,9 +730,8 @@ struct rtl8365mb_chip_info {
u32 chip_id;
u32 chip_ver;
u32 port_mask;
+ const struct rtl8365mb_family_info *family_info;
const struct rtl8365mb_extint extints[RTL8365MB_MAX_NUM_EXTINTS];
- const struct rtl8365mb_jam_tbl_entry *jam_table;
- size_t jam_size;
unsigned int num_tx_queues;
};

@@ -746,33 +751,32 @@ static const struct rtl8365mb_chip_info rtl8365mb_chip_infos[] = {
.name = "RTL8365MB-VC",
.chip_id = 0x6367,
.chip_ver = 0x0040,
+ .family_info = &rtl8365mb_family_c,
.port_mask = PORT_MASK(GENMASK(3, 0) | BIT(6)),
.extints = {
{ 6, 1, PHY_INTF(MII) | PHY_INTF(TMII) |
PHY_INTF(RMII) | PHY_INTF(RGMII) },
},
- .jam_table = rtl8365mb_init_jam_8365mb_vc,
- .jam_size = ARRAY_SIZE(rtl8365mb_init_jam_8365mb_vc),
.num_tx_queues = 8,
},
{
.name = "RTL8367S",
.chip_id = 0x6367,
.chip_ver = 0x00A0,
+ .family_info = &rtl8365mb_family_c,
.port_mask = PORT_MASK(GENMASK(4, 0) | BIT(6) | BIT(7)),
.extints = {
{ 6, 1, PHY_INTF(SGMII) | PHY_INTF(HSGMII) },
{ 7, 2, PHY_INTF(MII) | PHY_INTF(TMII) |
PHY_INTF(RMII) | PHY_INTF(RGMII) },
},
- .jam_table = rtl8365mb_init_jam_8365mb_vc,
- .jam_size = ARRAY_SIZE(rtl8365mb_init_jam_8365mb_vc),
.num_tx_queues = 8,
},
{
.name = "RTL8367SB",
.chip_id = 0x6367,
.chip_ver = 0x0010,
+ .family_info = &rtl8365mb_family_c,
.port_mask = PORT_MASK(GENMASK(4, 0) | BIT(6) | BIT(7)),
.extints = {
{ 6, 1, PHY_INTF(MII) | PHY_INTF(TMII) |
@@ -781,14 +785,13 @@ static const struct rtl8365mb_chip_info rtl8365mb_chip_infos[] = {
{ 7, 2, PHY_INTF(MII) | PHY_INTF(TMII) |
PHY_INTF(RMII) | PHY_INTF(RGMII) },
},
- .jam_table = rtl8365mb_init_jam_8365mb_vc,
- .jam_size = ARRAY_SIZE(rtl8365mb_init_jam_8365mb_vc),
.num_tx_queues = 8,
},
{
.name = "RTL8367RB-VB",
.chip_id = 0x6367,
.chip_ver = 0x0020,
+ .family_info = &rtl8365mb_family_c,
.port_mask = PORT_MASK(GENMASK(4, 0) | BIT(6) | BIT(7)),
.extints = {
{ 6, 1, PHY_INTF(MII) | PHY_INTF(TMII) |
@@ -796,8 +799,6 @@ static const struct rtl8365mb_chip_info rtl8365mb_chip_infos[] = {
{ 7, 2, PHY_INTF(MII) | PHY_INTF(TMII) |
PHY_INTF(RMII) | PHY_INTF(RGMII) },
},
- .jam_table = rtl8365mb_init_jam_8365mb_vc,
- .jam_size = ARRAY_SIZE(rtl8365mb_init_jam_8365mb_vc),
.num_tx_queues = 8,
},
};
@@ -897,6 +898,14 @@ struct rtl8365mb {

#define pcs_to_rtl8365mb(_pcs) container_of((_pcs), struct rtl8365mb, pcs)

+const struct rtl8365mb_family_info *
+rtl8365mb_get_family_info(struct realtek_priv *priv)
+{
+ struct rtl8365mb *mb = priv->chip_data;
+
+ return mb->chip_info->family_info;
+}
+
static int rtl8365mb_phy_poll_busy(struct realtek_priv *priv)
{
u32 val;
@@ -3059,17 +3068,17 @@ static int rtl8365mb_change_tag_protocol(struct dsa_switch *ds,
static int rtl8365mb_switch_init(struct realtek_priv *priv)
{
struct rtl8365mb *mb = priv->chip_data;
- const struct rtl8365mb_chip_info *ci;
+ const struct rtl8365mb_family_info *fi;
int ret;
int i;

- ci = mb->chip_info;
+ fi = mb->chip_info->family_info;

- /* Do any chip-specific init jam before getting to the common stuff */
- if (ci->jam_table) {
- for (i = 0; i < ci->jam_size; i++) {
- ret = regmap_write(priv->map, ci->jam_table[i].reg,
- ci->jam_table[i].val);
+ /* Do any family-specific init jam before getting to the common stuff */
+ if (fi->jam_table) {
+ for (i = 0; i < fi->jam_size; i++) {
+ ret = regmap_write(priv->map, fi->jam_table[i].reg,
+ fi->jam_table[i].val);
if (ret)
return ret;
}
--
2.53.0