Merge branch 'dpaa2-eth-devlink-port-number-from-the-dpmac'

Vincent Jardin via says:

====================
dpaa2-eth: devlink port number from the DPMAC

dpaa2-eth registers every DPNI as a physical devlink port without a
port number, so all the DPAA2 interfaces report the same
phys_port_name "p0", including the DPNIs that have no DPMAC behind
them.

Patch 1 uses the DPMAC id as the physical port number. The attributes
of a registered devlink port cannot change, so when the DPNI endpoint
changes at runtime a warning says the number is stale until the DPNI
is rebound.

Patch 2 registers the DPNIs without a DPMAC as virtual ports. They
have no phys_port_name, so "p<dpmac id>" is unique.

With both patches, udev can name an interface using its DPMAC, for
instance:

  SUBSYSTEM=="net", ACTION=="add", DRIVERS=="fsl_dpaa2_eth", \
    ATTR{phys_port_name}=="p3", NAME="dpmac3"
====================

Link: https://patch.msgid.link/20260928-for-upstream-dpaa2_ports-v2-0-1cda148530bf@free.fr
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Jakub Kicinski 2026-10-01 17:08:40 -07:00
commit 58328b5b58
3 changed files with 48 additions and 2 deletions

View File

@ -213,20 +213,61 @@ void dpaa2_eth_dl_unregister(struct dpaa2_eth_priv *priv)
devlink_unregister(priv->devlink);
}
static u32 dpaa2_eth_dl_port_number(struct dpaa2_eth_priv *priv)
{
lockdep_assert_held(&priv->mac_lock);
return dpaa2_eth_has_mac(priv) ? priv->mac->mc_dev->obj_desc.id : 0;
}
int dpaa2_eth_dl_port_add(struct dpaa2_eth_priv *priv)
{
struct devlink_port *devlink_port = &priv->devlink_port;
struct devlink_port_attrs attrs = {};
u32 port_number;
int err;
attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL;
mutex_lock(&priv->mac_lock);
port_number = dpaa2_eth_dl_port_number(priv);
priv->dl_port_number = port_number;
priv->dl_port_valid = true;
mutex_unlock(&priv->mac_lock);
if (port_number)
attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL;
else
attrs.flavour = DEVLINK_PORT_FLAVOUR_VIRTUAL;
attrs.phys.port_number = port_number;
devlink_port_attrs_set(devlink_port, &attrs);
return devlink_port_register(priv->devlink, devlink_port, 0);
err = devlink_port_register(priv->devlink, devlink_port, 0);
if (err) {
mutex_lock(&priv->mac_lock);
priv->dl_port_valid = false;
mutex_unlock(&priv->mac_lock);
}
return err;
}
void dpaa2_eth_dl_port_check(struct dpaa2_eth_priv *priv)
{
mutex_lock(&priv->mac_lock);
if (priv->dl_port_valid &&
priv->dl_port_number != dpaa2_eth_dl_port_number(priv))
netdev_warn(priv->net_dev,
"devlink port number %u is stale, rebind to update\n",
priv->dl_port_number);
mutex_unlock(&priv->mac_lock);
}
void dpaa2_eth_dl_port_del(struct dpaa2_eth_priv *priv)
{
struct devlink_port *devlink_port = &priv->devlink_port;
mutex_lock(&priv->mac_lock);
priv->dl_port_valid = false;
mutex_unlock(&priv->mac_lock);
devlink_port_unregister(devlink_port);
}

View File

@ -4771,6 +4771,8 @@ static irqreturn_t dpni_irq0_handler_thread(int irq_num, void *arg)
dpaa2_eth_disconnect_mac(priv);
else
dpaa2_eth_connect_mac(priv);
dpaa2_eth_dl_port_check(priv);
}
return IRQ_HANDLED;

View File

@ -632,6 +632,8 @@ struct dpaa2_eth_priv {
struct devlink *devlink;
struct dpaa2_eth_trap_data *trap_data;
struct devlink_port devlink_port;
u32 dl_port_number;
bool dl_port_valid;
u32 rx_copybreak;
@ -802,6 +804,7 @@ void dpaa2_eth_dl_unregister(struct dpaa2_eth_priv *priv);
int dpaa2_eth_dl_port_add(struct dpaa2_eth_priv *priv);
void dpaa2_eth_dl_port_del(struct dpaa2_eth_priv *priv);
void dpaa2_eth_dl_port_check(struct dpaa2_eth_priv *priv);
int dpaa2_eth_dl_traps_register(struct dpaa2_eth_priv *priv);
void dpaa2_eth_dl_traps_unregister(struct dpaa2_eth_priv *priv);