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
Subject: [PATCH net-next v8 09/11] net: dsa: realtek: rtl8365mb: refactor L2 MAC handling
Date: Wed, 4 Nov 2026 00:35:33 +0100 [thread overview]
Message-ID: <3685f73e-0c28-4ff1-8c8e-3c39643a6649@yahoo.com> (raw)
In-Reply-To: <08611959-c555-46d9-8e7e-20b85d0c4056@yahoo.com>
Move the L2 MAC pack/unpack helpers above the family C serializers
and use them there instead of open-coding the byte packing, since the
layout of the MAC address words is the same for both families. The
now unused per-field MAC masks are dropped.
Rename the family C serializers to rtl8365mb_c_l2_*() and keep
rtl8365mb_l2_{data_to_uc,uc_to_data,data_to_mc,mc_to_data}() as thin
dispatchers taking priv, so that a following patch can add the family
D layout without touching the family C code again.
No functional change.
Signed-off-by: Mieczyslaw Nalewaj <namiltd@yahoo.com>
---
drivers/net/dsa/realtek/rtl8365mb_l2.c | 117 +++++++++++++------------
1 file changed, 62 insertions(+), 55 deletions(-)
diff --git a/drivers/net/dsa/realtek/rtl8365mb_l2.c b/drivers/net/dsa/realtek/rtl8365mb_l2.c
index 0494d8a..01cf2d5 100644
--- a/drivers/net/dsa/realtek/rtl8365mb_l2.c
+++ b/drivers/net/dsa/realtek/rtl8365mb_l2.c
@@ -12,12 +12,6 @@
#define RTL8365MB_L2_ENTRY_SIZE 6
-#define RTL8365MB_L2_UC_D0_MAC5_MSK GENMASK(7, 0)
-#define RTL8365MB_L2_UC_D0_MAC4_MSK GENMASK(15, 8)
-#define RTL8365MB_L2_UC_D1_MAC3_MSK GENMASK(7, 0)
-#define RTL8365MB_L2_UC_D1_MAC2_MSK GENMASK(15, 8)
-#define RTL8365MB_L2_UC_D2_MAC1_MSK GENMASK(7, 0)
-#define RTL8365MB_L2_UC_D2_MAC0_MSK GENMASK(15, 8)
#define RTL8365MB_L2_UC_D3_VID_MSK GENMASK(11, 0)
#define RTL8365MB_L2_UC_D3_IVL_MSK GENMASK(13, 13)
#define RTL8365MB_L2_UC_D3_PORT_EXT_MSK GENMASK(15, 15)
@@ -36,12 +30,6 @@
#define RTL8365MB_L2_UC_D5_FWD_PRI_MSK GENMASK(4, 4)
#define RTL8365MB_L2_UC_D5_STATIC_MSK GENMASK(5, 5)
-#define RTL8365MB_L2_MC_D0_MAC5_MSK GENMASK(7, 0)
-#define RTL8365MB_L2_MC_D0_MAC4_MSK GENMASK(15, 8)
-#define RTL8365MB_L2_MC_D1_MAC3_MSK GENMASK(7, 0)
-#define RTL8365MB_L2_MC_D1_MAC2_MSK GENMASK(15, 8)
-#define RTL8365MB_L2_MC_D2_MAC1_MSK GENMASK(7, 0)
-#define RTL8365MB_L2_MC_D2_MAC0_MSK GENMASK(15, 8)
#define RTL8365MB_L2_MC_D3_VID_MSK GENMASK(11, 0)
#define RTL8365MB_L2_MC_D3_IVL_MSK GENMASK(13, 13)
#define RTL8365MB_L2_MC_D3_MBR_HI1_MSK GENMASK(15, 14)
@@ -131,16 +119,29 @@ struct rtl8365mb_l2_mc {
bool igmp_asic;
};
-static void rtl8365mb_l2_data_to_uc(const u16 *data, struct rtl8365mb_l2_uc *uc)
+static void rtl8365mb_l2_mac_to_data(const u8 *m, u16 *data)
+{
+ data[0] = (m[4] << 8) | m[5];
+ data[1] = (m[2] << 8) | m[3];
+ data[2] = (m[0] << 8) | m[1];
+}
+
+static void rtl8365mb_l2_data_to_mac(const u16 *data, u8 *m)
+{
+ m[5] = data[0] & 0xff;
+ m[4] = data[0] >> 8;
+ m[3] = data[1] & 0xff;
+ m[2] = data[1] >> 8;
+ m[1] = data[2] & 0xff;
+ m[0] = data[2] >> 8;
+}
+
+static void rtl8365mb_c_l2_data_to_uc(const u16 *data,
+ struct rtl8365mb_l2_uc *uc)
{
u32 val;
- uc->key.mac_addr[5] = FIELD_GET(RTL8365MB_L2_UC_D0_MAC5_MSK, data[0]);
- uc->key.mac_addr[4] = FIELD_GET(RTL8365MB_L2_UC_D0_MAC4_MSK, data[0]);
- uc->key.mac_addr[3] = FIELD_GET(RTL8365MB_L2_UC_D1_MAC3_MSK, data[1]);
- uc->key.mac_addr[2] = FIELD_GET(RTL8365MB_L2_UC_D1_MAC2_MSK, data[1]);
- uc->key.mac_addr[1] = FIELD_GET(RTL8365MB_L2_UC_D2_MAC1_MSK, data[2]);
- uc->key.mac_addr[0] = FIELD_GET(RTL8365MB_L2_UC_D2_MAC0_MSK, data[2]);
+ rtl8365mb_l2_data_to_mac(data, uc->key.mac_addr);
uc->key.efid = FIELD_GET(RTL8365MB_L2_UC_D4_EFID_MSK, data[4]);
uc->key.vid = FIELD_GET(RTL8365MB_L2_UC_D3_VID_MSK, data[3]);
uc->key.ivl = FIELD_GET(RTL8365MB_L2_UC_D3_IVL_MSK, data[3]);
@@ -161,23 +162,13 @@ static void rtl8365mb_l2_data_to_uc(const u16 *data, struct rtl8365mb_l2_uc *uc)
uc->is_static = FIELD_GET(RTL8365MB_L2_UC_D5_STATIC_MSK, data[5]);
}
-static void rtl8365mb_l2_uc_to_data(const struct rtl8365mb_l2_uc *uc, u16 *data)
+static void rtl8365mb_c_l2_uc_to_data(const struct rtl8365mb_l2_uc *uc,
+ u16 *data)
{
u32 val;
memset(data, 0, RTL8365MB_L2_ENTRY_SIZE * 2);
- data[0] |=
- FIELD_PREP(RTL8365MB_L2_UC_D0_MAC5_MSK, uc->key.mac_addr[5]);
- data[0] |=
- FIELD_PREP(RTL8365MB_L2_UC_D0_MAC4_MSK, uc->key.mac_addr[4]);
- data[1] |=
- FIELD_PREP(RTL8365MB_L2_UC_D1_MAC3_MSK, uc->key.mac_addr[3]);
- data[1] |=
- FIELD_PREP(RTL8365MB_L2_UC_D1_MAC2_MSK, uc->key.mac_addr[2]);
- data[2] |=
- FIELD_PREP(RTL8365MB_L2_UC_D2_MAC1_MSK, uc->key.mac_addr[1]);
- data[2] |=
- FIELD_PREP(RTL8365MB_L2_UC_D2_MAC0_MSK, uc->key.mac_addr[0]);
+ rtl8365mb_l2_mac_to_data(uc->key.mac_addr, data);
data[3] |= FIELD_PREP(RTL8365MB_L2_UC_D3_VID_MSK, uc->key.vid);
data[3] |= FIELD_PREP(RTL8365MB_L2_UC_D3_IVL_MSK, uc->key.ivl);
@@ -200,16 +191,12 @@ static void rtl8365mb_l2_uc_to_data(const struct rtl8365mb_l2_uc *uc, u16 *data)
data[5] |= FIELD_PREP(RTL8365MB_L2_UC_D5_STATIC_MSK, uc->is_static);
}
-static void rtl8365mb_l2_data_to_mc(const u16 *data, struct rtl8365mb_l2_mc *mc)
+static void rtl8365mb_c_l2_data_to_mc(const u16 *data,
+ struct rtl8365mb_l2_mc *mc)
{
u32 val;
- mc->key.mac_addr[5] = FIELD_GET(RTL8365MB_L2_MC_D0_MAC5_MSK, data[0]);
- mc->key.mac_addr[4] = FIELD_GET(RTL8365MB_L2_MC_D0_MAC4_MSK, data[0]);
- mc->key.mac_addr[3] = FIELD_GET(RTL8365MB_L2_MC_D1_MAC3_MSK, data[1]);
- mc->key.mac_addr[2] = FIELD_GET(RTL8365MB_L2_MC_D1_MAC2_MSK, data[1]);
- mc->key.mac_addr[1] = FIELD_GET(RTL8365MB_L2_MC_D2_MAC1_MSK, data[2]);
- mc->key.mac_addr[0] = FIELD_GET(RTL8365MB_L2_MC_D2_MAC0_MSK, data[2]);
+ rtl8365mb_l2_data_to_mac(data, mc->key.mac_addr);
/* key.vid,key.fid shares the same memory space */
mc->key.vid = FIELD_GET(RTL8365MB_L2_MC_D3_VID_MSK, data[3]);
mc->key.ivl = FIELD_GET(RTL8365MB_L2_MC_D3_IVL_MSK, data[3]);
@@ -228,17 +215,13 @@ static void rtl8365mb_l2_data_to_mc(const u16 *data, struct rtl8365mb_l2_mc *mc)
mc->igmp_asic = FIELD_GET(RTL8365MB_L2_MC_D5_IGMP_ASIC_MSK, data[5]);
}
-static void rtl8365mb_l2_mc_to_data(const struct rtl8365mb_l2_mc *mc, u16 *data)
+static void rtl8365mb_c_l2_mc_to_data(const struct rtl8365mb_l2_mc *mc,
+ u16 *data)
{
u32 val;
memset(data, 0, RTL8365MB_L2_ENTRY_SIZE * 2);
- data[0] |= FIELD_PREP(RTL8365MB_L2_MC_D0_MAC5_MSK, mc->key.mac_addr[5]);
- data[0] |= FIELD_PREP(RTL8365MB_L2_MC_D0_MAC4_MSK, mc->key.mac_addr[4]);
- data[1] |= FIELD_PREP(RTL8365MB_L2_MC_D1_MAC3_MSK, mc->key.mac_addr[3]);
- data[1] |= FIELD_PREP(RTL8365MB_L2_MC_D1_MAC2_MSK, mc->key.mac_addr[2]);
- data[2] |= FIELD_PREP(RTL8365MB_L2_MC_D2_MAC1_MSK, mc->key.mac_addr[1]);
- data[2] |= FIELD_PREP(RTL8365MB_L2_MC_D2_MAC0_MSK, mc->key.mac_addr[0]);
+ rtl8365mb_l2_mac_to_data(mc->key.mac_addr, data);
data[3] |= FIELD_PREP(RTL8365MB_L2_MC_D3_VID_MSK, mc->key.vid);
data[3] |= FIELD_PREP(RTL8365MB_L2_MC_D3_IVL_MSK, mc->key.ivl);
@@ -258,6 +241,30 @@ static void rtl8365mb_l2_mc_to_data(const struct rtl8365mb_l2_mc *mc, u16 *data)
data[5] |= FIELD_PREP(RTL8365MB_L2_MC_D5_MBR_HI2_MSK, val);
}
+static void rtl8365mb_l2_data_to_uc(struct realtek_priv *priv, const u16 *data,
+ struct rtl8365mb_l2_uc *uc)
+{
+ rtl8365mb_c_l2_data_to_uc(data, uc);
+}
+
+static void rtl8365mb_l2_uc_to_data(struct realtek_priv *priv,
+ const struct rtl8365mb_l2_uc *uc, u16 *data)
+{
+ rtl8365mb_c_l2_uc_to_data(uc, data);
+}
+
+static void rtl8365mb_l2_data_to_mc(struct realtek_priv *priv, const u16 *data,
+ struct rtl8365mb_l2_mc *mc)
+{
+ rtl8365mb_c_l2_data_to_mc(data, mc);
+}
+
+static void rtl8365mb_l2_mc_to_data(struct realtek_priv *priv,
+ const struct rtl8365mb_l2_mc *mc, u16 *data)
+{
+ rtl8365mb_c_l2_mc_to_data(mc, data);
+}
+
/*
* rtl8365mb_l2_get_next_uc() - get the next Unicast L2 entry
* @priv: realtek_priv pointer
@@ -293,7 +300,7 @@ int rtl8365mb_l2_get_next_uc(struct realtek_priv *priv, u16 *addr, int port,
if (ret)
return ret;
- rtl8365mb_l2_data_to_uc(data, &uc);
+ rtl8365mb_l2_data_to_uc(priv, data, &uc);
ether_addr_copy(entry->mac_addr, uc.key.mac_addr);
entry->vid = uc.key.vid;
@@ -326,7 +333,7 @@ int rtl8365mb_l2_add_uc(struct realtek_priv *priv, int port,
uc.is_static = true;
/* age greater than 0 adds/updates entries */
uc.age = 1;
- rtl8365mb_l2_uc_to_data(&uc, data);
+ rtl8365mb_l2_uc_to_data(priv, &uc, data);
/* add the new entry or update an existing one */
ret = rtl8365mb_table_query(priv, RTL8365MB_TABLE_L2,
@@ -358,7 +365,7 @@ int rtl8365mb_l2_del_uc(struct realtek_priv *priv, int port,
uc.key.vid = vid;
/* age 0 deletes the entry */
uc.age = 0;
- rtl8365mb_l2_uc_to_data(&uc, data);
+ rtl8365mb_l2_uc_to_data(priv, &uc, data);
/* it looks like the switch will always add/update the entry,
* even when age is 0 or uc.key did not match an existing entry,
@@ -463,7 +470,7 @@ int rtl8365mb_l2_add_mc(struct realtek_priv *priv, int port,
*/
mc.member |= BIT(port);
mc.is_static = 1;
- rtl8365mb_l2_mc_to_data(&mc, data);
+ rtl8365mb_l2_mc_to_data(priv, &mc, data);
/* First look for an existing entry (to get existing port members) */
ret = rtl8365mb_table_query(priv, RTL8365MB_TABLE_L2,
@@ -472,7 +479,7 @@ int rtl8365mb_l2_add_mc(struct realtek_priv *priv, int port,
data, RTL8365MB_L2_ENTRY_SIZE);
if (!ret) {
/* There is already an entry... */
- rtl8365mb_l2_data_to_mc(data, &mc);
+ rtl8365mb_l2_data_to_mc(priv, data, &mc);
dev_dbg(priv->dev,
"%s: found %pM addr=%d member=0x%x igmpidx=0x%x %s\n",
__func__, mac_addr, addr, mc.member, mc.igmpidx,
@@ -487,7 +494,7 @@ int rtl8365mb_l2_add_mc(struct realtek_priv *priv, int port,
mc.is_static = 1;
}
- rtl8365mb_l2_mc_to_data(&mc, data);
+ rtl8365mb_l2_mc_to_data(priv, &mc, data);
} else if (ret == -ENOENT) {
/* New entry, no need to update data again as it already
* includes the member.
@@ -529,7 +536,7 @@ int rtl8365mb_l2_del_mc(struct realtek_priv *priv, int port,
memcpy(mc.key.mac_addr, mac_addr, ETH_ALEN);
mc.key.vid = vid;
mc.key.ivl = true;
- rtl8365mb_l2_mc_to_data(&mc, data);
+ rtl8365mb_l2_mc_to_data(priv, &mc, data);
/* First look for an existing entry (to get existing port members) */
ret = rtl8365mb_table_query(priv, RTL8365MB_TABLE_L2,
@@ -547,7 +554,7 @@ int rtl8365mb_l2_del_mc(struct realtek_priv *priv, int port,
/* Return on any other error */
return ret;
- rtl8365mb_l2_data_to_mc(data, &mc);
+ rtl8365mb_l2_data_to_mc(priv, data, &mc);
dev_dbg(priv->dev,
"%s: found %pM addr=%d member=0x%x igmpidx=0x%x %s\n",
__func__, mac_addr, addr, mc.member, mc.igmpidx,
@@ -565,7 +572,7 @@ int rtl8365mb_l2_del_mc(struct realtek_priv *priv, int port,
mc.fwd_pri = 0;
mc.igmp_asic = 0;
}
- rtl8365mb_l2_mc_to_data(&mc, data);
+ rtl8365mb_l2_mc_to_data(priv, &mc, data);
/* update the existing entry. */
ret = rtl8365mb_table_query(priv, RTL8365MB_TABLE_L2,
--
2.53.0
next prev parent reply other threads:[~2026-11-03 23:35 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <08611959-c555-46d9-8e7e-20b85d0c4056.ref@yahoo.com>
2026-11-03 23:26 ` [PATCH net-next v8 00/11] net: dsa: realtek: rtl8365mb: add support for RTL8367S-VB Mieczyslaw Nalewaj
2026-11-03 23:28 ` [PATCH net-next v8 01/11] dt-bindings: net: dsa: realtek: add RTL8367S-VB Mieczyslaw Nalewaj
2026-11-03 23:28 ` [PATCH net-next v8 02/11] net: dsa: realtek: rtl8365mb: add chip family infrastructure Mieczyslaw Nalewaj
2026-11-03 23:29 ` [PATCH net-next v8 03/11] net: dsa: realtek: rtl8365mb: set speed for family D Mieczyslaw Nalewaj
2026-11-03 23:30 ` [PATCH net-next v8 04/11] net: dsa: realtek: rtl8365mb: set RGMII mode " Mieczyslaw Nalewaj
2026-11-03 23:31 ` [PATCH net-next v8 05/11] net: dsa: realtek: rtl8365mb: set and get vlan 4k " Mieczyslaw Nalewaj
2026-11-03 23:32 ` [PATCH net-next v8 06/11] net: dsa: realtek: rtl8365mb: use raw VID for PVID on " Mieczyslaw Nalewaj
2026-11-03 23:33 ` [PATCH net-next v8 07/11] net: dsa: realtek: rtl8365mb: add family D SDS13 PCS support Mieczyslaw Nalewaj
2026-11-03 23:34 ` [PATCH net-next v8 08/11] net: dsa: realtek: rtl8365mb: re-latch the family D SerDes Mieczyslaw Nalewaj
2026-11-03 23:35 ` Mieczyslaw Nalewaj [this message]
2026-11-03 23:36 ` [PATCH net-next v8 10/11] net: dsa: realtek: rtl8365mb: make L2/LUT access work on family D Mieczyslaw Nalewaj
2026-11-03 23:37 ` [PATCH net-next v8 11/11] net: dsa: realtek: rtl8365mb: add support for RTL8367S-VB 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=3685f73e-0c28-4ff1-8c8e-3c39643a6649@yahoo.com \
--to=namiltd@yahoo.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--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=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®