Implement ndo_get_phys_port_id and ndo_get_phys_port_name callbacks to provide physical port identification for all stmmac-based devices. Default implementations use the permanent MAC address for port ID and bus_id for port name. Glue drivers can override these by setting get_phys_port_id and get_phys_port_name callbacks in plat_stmmacenet_data. Signed-off-by: John Madieu --- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 54 +++++++++++++++++++ include/linux/stmmac.h | 5 ++ 2 files changed, 59 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 15b0c08ebd877..e8f642c9941b6 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -7151,6 +7151,58 @@ static void stmmac_get_stats64(struct net_device *dev, struct rtnl_link_stats64 stats->rx_missed_errors = priv->xstats.rx_missed_cntr; } +/** + * stmmac_get_phys_port_id - Get physical port identification + * @dev: net device structure + * @ppid: pointer to physical port id structure + * + * Returns a unique physical port identifier. If the platform provides + * a custom callback, it is used. Otherwise, the permanent MAC address + * serves as the default identifier. + * + * Return: 0 on success, negative error code otherwise + */ +static int stmmac_get_phys_port_id(struct net_device *dev, + struct netdev_phys_item_id *ppid) +{ + struct stmmac_priv *priv = netdev_priv(dev); + + /* Allow glue driver to override */ + if (priv->plat->get_phys_port_id) + return priv->plat->get_phys_port_id(dev, ppid); + + /* Default: use permanent MAC address as port ID */ + ppid->id_len = ETH_ALEN; + memcpy(ppid->id, dev->perm_addr, ETH_ALEN); + + return 0; +} + +/** + * stmmac_get_phys_port_name - Get physical port name + * @dev: net device structure + * @name: buffer to store the port name + * @len: length of the buffer + * + * Returns a human-readable physical port name. If the platform provides + * a custom callback, it is used. Otherwise, a default name based on + * the bus_id is generated. + * + * Return: 0 on success, negative error code otherwise + */ +static int stmmac_get_phys_port_name(struct net_device *dev, + char *name, size_t len) +{ + struct stmmac_priv *priv = netdev_priv(dev); + + /* Allow glue driver to override */ + if (priv->plat->get_phys_port_name) + return priv->plat->get_phys_port_name(dev, name, len); + + /* Default: use bus_id as port identifier */ + return snprintf(name, len, "p%d", priv->plat->bus_id) >= len ? -EINVAL : 0; +} + static const struct net_device_ops stmmac_netdev_ops = { .ndo_open = stmmac_open, .ndo_start_xmit = stmmac_xmit, @@ -7172,6 +7224,8 @@ static const struct net_device_ops stmmac_netdev_ops = { .ndo_xsk_wakeup = stmmac_xsk_wakeup, .ndo_hwtstamp_get = stmmac_hwtstamp_get, .ndo_hwtstamp_set = stmmac_hwtstamp_set, + .ndo_get_phys_port_id = stmmac_get_phys_port_id, + .ndo_get_phys_port_name = stmmac_get_phys_port_name, }; static void stmmac_reset_subtask(struct stmmac_priv *priv) diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h index 4f70a6551e68c..2b98c2d354804 100644 --- a/include/linux/stmmac.h +++ b/include/linux/stmmac.h @@ -277,6 +277,11 @@ struct plat_stmmacenet_data { void (*pcs_exit)(struct stmmac_priv *priv); struct phylink_pcs *(*select_pcs)(struct stmmac_priv *priv, phy_interface_t interface); + /* Physical port identification callbacks (optional, for glue driver override) */ + int (*get_phys_port_id)(struct net_device *ndev, + struct netdev_phys_item_id *ppid); + int (*get_phys_port_name)(struct net_device *ndev, + char *name, size_t len); void *bsp_priv; struct clk *stmmac_clk; struct clk *pclk; -- 2.25.1 Add optional port-id property to identify ethernet ports on RZ/V2H SoCs. The hardware doesn't provide unique identification registers for multiple ethernet instances, so this property allows explicit port identification from the device tree. Signed-off-by: John Madieu --- .../bindings/net/renesas,rzv2h-gbeth.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Documentation/devicetree/bindings/net/renesas,rzv2h-gbeth.yaml b/Documentation/devicetree/bindings/net/renesas,rzv2h-gbeth.yaml index bd53ab300f500..bb59c6a925d3f 100644 --- a/Documentation/devicetree/bindings/net/renesas,rzv2h-gbeth.yaml +++ b/Documentation/devicetree/bindings/net/renesas,rzv2h-gbeth.yaml @@ -117,6 +117,23 @@ properties: - description: AXI power-on system reset - description: AHB reset + renesas,port-id: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + Optional unique port identifier for this ethernet interface. + Used for physical port identification (phys_port_id, phys_port_name). + If not specified, the ethernet alias index is used as fallback. + minimum: 0 + maximum: 255 + + renesas,port-name: + $ref: /schemas/types.yaml#/definitions/string + description: + Optional custom name for the physical port. Used by + ndo_get_phys_port_name() for interface naming. + If not specified, "p" format is used where N is the port-id + or ethernet alias index. + pcs-handle: description: phandle pointing to a PCS sub-node compatible with @@ -230,6 +247,8 @@ examples: snps,txpbl = <32>; snps,rxpbl = <32>; phy-handle = <&phy0>; + renesas,port-id = <0>; + renesas,port-name = "mgmt"; stmmac_axi_setup: stmmac-axi-config { snps,lpi_en; -- 2.25.1 Implement ndo_get_phys_port_id() and ndo_get_phys_port_name() callbacks for the Renesas RZ/G3E GBETH driver. The port ID is an 8-byte identifier constructed from: - Permanent MAC address if available (addr_assign_type == NET_ADDR_PERM) - Renesas OUI (74:90:50) as fallback for random/generated MACs - Port index from 'port-id' DT property or ethernet alias The port name resolution follows this hierarchy: - 'port-name' DT property if specified (allows custom names like "mgmt") - "p" format using 'port-id' DT property - "p" format using ethernet alias index as fallback Signed-off-by: John Madieu --- .../stmicro/stmmac/dwmac-renesas-gbeth.c | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c index bc7bb975803ca..5acb65b0e4f06 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c @@ -16,7 +16,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -91,6 +93,57 @@ static struct phylink_pcs *renesas_gmac_select_pcs(struct stmmac_priv *priv, return priv->hw->phylink_pcs; } +static int renesas_gbeth_get_port_id(struct device *dev) +{ + int port_id; + + if (!device_property_read_u32(dev, "renesas,port-id", &port_id)) + return port_id; + + port_id = of_alias_get_id(dev_of_node(dev), "ethernet"); + + return port_id < 0 ? 0 : port_id; +} + +static int renesas_gbeth_get_phys_port_name(struct net_device *ndev, + char *name, size_t len) +{ + struct stmmac_priv *priv = netdev_priv(ndev); + struct renesas_gbeth *gbeth = priv->plat->bsp_priv; + const char *port_name; + + if (!device_property_read_string(gbeth->dev, "renesas,port-name", &port_name)) + return snprintf(name, len, "%s", port_name) >= len ? -EINVAL : 0; + + return snprintf(name, len, "p%d", renesas_gbeth_get_port_id(gbeth->dev)) >= len ? -EINVAL : 0; +} + +static int renesas_gbeth_get_phys_port_id(struct net_device *ndev, + struct netdev_phys_item_id *ppid) +{ + struct stmmac_priv *priv = netdev_priv(ndev); + struct renesas_gbeth *gbeth = priv->plat->bsp_priv; + u8 *id = ppid->id; + + if (ndev->addr_assign_type == NET_ADDR_PERM) { + memcpy(id, ndev->perm_addr, ETH_ALEN); + } else { + /* Fallback: Renesas OUI prefix (74:90:50) */ + id[0] = 0x74; + id[1] = 0x90; + id[2] = 0x50; + id[3] = 0x00; + id[4] = 0x00; + id[5] = 0x00; + } + + id[6] = renesas_gbeth_get_port_id(gbeth->dev) & 0xff; + id[7] = 0x00; + ppid->id_len = 8; + + return 0; +} + static int renesas_gbeth_init(struct platform_device *pdev, void *priv) { struct plat_stmmacenet_data *plat_dat; @@ -194,6 +247,9 @@ static int renesas_gbeth_probe(struct platform_device *pdev) plat_dat->select_pcs = renesas_gmac_select_pcs; } + plat_dat->get_phys_port_id = renesas_gbeth_get_phys_port_id; + plat_dat->get_phys_port_name = renesas_gbeth_get_phys_port_name; + return devm_stmmac_pltfr_probe(pdev, plat_dat, &stmmac_res); } -- 2.25.1