[PATCH net-next 2/7] net: dsa: motorcomm: Check port type with runtime info
From: David Yang
Date: Wed Sep 09 2026 - 15:20:47 EST
The yt921x_port_is_internal/external() macros hardcoded the port layout:
they treat ports 8 and 9 as external on every chip and count the dummy
ports as internal. Drop them and identify the port type using chip info
and runtime configuration.
Signed-off-by: David Yang <mmyangfl@xxxxxxxxx>
---
drivers/net/dsa/motorcomm/chip.c | 36 ++++++++++++++++++++++----------
drivers/net/dsa/motorcomm/chip.h | 11 +++++-----
2 files changed, 31 insertions(+), 16 deletions(-)
diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index 64fdc5109cc6..946949a3aba8 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -3743,6 +3743,7 @@ yt921x_dsa_port_set_apptrust(struct dsa_switch *ds, int port, const u8 *sel,
static int yt921x_port_down(struct yt921x_priv *priv, int port)
{
+ const struct yt921x_info *info = priv->info;
u32 mask;
int res;
@@ -3751,12 +3752,13 @@ static int yt921x_port_down(struct yt921x_priv *priv, int port)
if (res)
return res;
- if (yt921x_port_is_external(port)) {
+ if (BIT(port) & info->serdes_mask) {
mask = YT921X_SERDES_LINK;
res = yt921x_reg_clear_bits(priv, YT921X_SERDESn(port), mask);
if (res)
return res;
-
+ }
+ if (BIT(port) & info->xmii_mask) {
mask = YT921X_XMII_LINK;
res = yt921x_reg_clear_bits(priv, YT921X_XMIIn(port), mask);
if (res)
@@ -3771,6 +3773,8 @@ yt921x_port_up(struct yt921x_priv *priv, int port, unsigned int mode,
phy_interface_t interface, int speed, int duplex,
bool tx_pause, bool rx_pause)
{
+ const struct yt921x_info *info = priv->info;
+ struct yt921x_port *pp = &priv->ports[port];
u32 mask;
u32 ctrl;
int res;
@@ -3805,7 +3809,10 @@ yt921x_port_up(struct yt921x_priv *priv, int port, unsigned int mode,
if (res)
return res;
- if (yt921x_port_is_external(port)) {
+ if (!(BIT(port) & (info->serdes_mask | info->xmii_mask)))
+ return 0;
+
+ if (pp->serdes) {
mask = YT921X_SERDES_SPEED_M;
switch (speed) {
case SPEED_10:
@@ -3841,7 +3848,7 @@ yt921x_port_up(struct yt921x_priv *priv, int port, unsigned int mode,
mask, ctrl);
if (res)
return res;
-
+ } else {
mask = YT921X_XMII_LINK;
res = yt921x_reg_set_bits(priv, YT921X_XMIIn(port), mask);
if (res)
@@ -3881,17 +3888,16 @@ static int
yt921x_port_config(struct yt921x_priv *priv, int port, unsigned int mode,
phy_interface_t interface)
{
+ const struct yt921x_info *info = priv->info;
+ struct yt921x_port *pp = &priv->ports[port];
struct device *dev = to_device(priv);
u32 mask;
u32 ctrl;
int res;
- if (!yt921x_port_is_external(port)) {
- if (interface != PHY_INTERFACE_MODE_INTERNAL) {
- dev_err(dev, "Wrong mode %d on port %d\n",
- interface, port);
- return -EINVAL;
- }
+ if (BIT(port) & info->internal_mask) {
+ if (interface != PHY_INTERFACE_MODE_INTERNAL)
+ goto err;
return 0;
}
@@ -3901,6 +3907,9 @@ yt921x_port_config(struct yt921x_priv *priv, int port, unsigned int mode,
case PHY_INTERFACE_MODE_100BASEX:
case PHY_INTERFACE_MODE_1000BASEX:
case PHY_INTERFACE_MODE_2500BASEX:
+ if (!(BIT(port) & info->serdes_mask))
+ goto err;
+
mask = YT921X_SERDES_CTRL_PORTn(port);
res = yt921x_reg_set_bits(priv, YT921X_SERDES_CTRL, mask);
if (res)
@@ -3933,13 +3942,18 @@ yt921x_port_config(struct yt921x_priv *priv, int port, unsigned int mode,
if (res)
return res;
+ pp->serdes = true;
break;
/* add XMII support here */
default:
- return -EINVAL;
+ goto err;
}
return 0;
+
+err:
+ dev_err(dev, "Wrong mode %d on port %d\n", interface, port);
+ return -EINVAL;
}
static void
diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h
index bc2641ded101..6f0123d219e0 100644
--- a/drivers/net/dsa/motorcomm/chip.h
+++ b/drivers/net/dsa/motorcomm/chip.h
@@ -858,9 +858,6 @@ enum yt921x_fdb_entry_status {
#define YT921X_NAME "yt921x"
-#define yt921x_port_is_internal(port) ((port) < 8)
-#define yt921x_port_is_external(port) ((port) == 8 || (port) == 9)
-
struct yt921x_mib {
u64 rx_broadcast;
u64 rx_pause;
@@ -936,8 +933,12 @@ struct yt921x_acl_blk {
struct yt921x_port {
unsigned char index;
- bool hairpin;
- bool isolated;
+ /* SerDes in use */
+ bool serdes:1;
+ /* BR_HAIRPIN_MODE */
+ bool hairpin:1;
+ /* BR_ISOLATED */
+ bool isolated:1;
struct delayed_work mib_read;
struct yt921x_mib mib;
--
2.53.0