2021-06-13 12:02:38

by Reto Schneider

[permalink] [raw]
Subject: [PATCH v1 1/2] dt-bindings: net: mediatek: Support custom ifname

From: Reto Schneider <[email protected]>

The (optional) label property allows to specify customized interfaces
names.

The motivation behind this change is to allow embedded devices to keep
their first switch port be named "eth0", even when switching to the DSA
architecture. In order to do so, it must be possible to name the MAC
interface differently from eth0.

Signed-off-by: Reto Schneider <[email protected]>
---

Documentation/devicetree/bindings/net/mediatek-net.txt | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/mediatek-net.txt b/Documentation/devicetree/bindings/net/mediatek-net.txt
index 72d03e07cf7c..93e35f239a0a 100644
--- a/Documentation/devicetree/bindings/net/mediatek-net.txt
+++ b/Documentation/devicetree/bindings/net/mediatek-net.txt
@@ -51,6 +51,9 @@ Required properties:
is equal to 0 and the MAC uses fixed-link to connect
with internal switch such as MT7530.

+Optional properties:
+- label: Name of interface, defaults to ethX if missing
+
Example:

eth: ethernet@1b100000 {
@@ -76,6 +79,7 @@ eth: ethernet@1b100000 {
compatible = "mediatek,eth-mac";
reg = <0>;
phy-handle = <&phy0>;
+ label = "mac1";
};

gmac2: mac@1 {
--
2.30.2


2021-06-13 15:04:35

by Reto Schneider

[permalink] [raw]
Subject: [PATCH v2 2/2] net: ethernet: mtk_eth_soc: Support custom ifname

From: Reto Schneider <[email protected]>

Name the MAC interface name according to the label property. If the
property is missing, the default name (ethX) gets used.

Labels with more than IFNAMSIZ -1 characters will be truncated silently,
which seems to be what most of the code base does when using strscpy.

Signed-off-by: Reto Schneider <[email protected]>

---

Changes in v2:
- Avoid dangerous usage of strncpy

drivers/net/ethernet/mediatek/mtk_eth_soc.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 64adfd24e134..a921ecc1c997 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -2948,6 +2948,7 @@ static const struct net_device_ops mtk_netdev_ops = {
static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
{
const __be32 *_id = of_get_property(np, "reg", NULL);
+ const char *const name = of_get_property(np, "label", NULL);
phy_interface_t phy_mode;
struct phylink *phylink;
struct mtk_mac *mac;
@@ -3020,6 +3021,9 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)

mac->phylink = phylink;

+ if (name)
+ strscpy(eth->netdev[id]->name, name, IFNAMSIZ);
+
SET_NETDEV_DEV(eth->netdev[id], eth->dev);
eth->netdev[id]->watchdog_timeo = 5 * HZ;
eth->netdev[id]->netdev_ops = &mtk_netdev_ops;
--
2.30.2

2021-06-13 15:06:15

by Reto Schneider

[permalink] [raw]
Subject: [PATCH v2 1/2] dt-bindings: net: mediatek: Support custom ifname

From: Reto Schneider <[email protected]>

The (optional) label property allows to specify customized interfaces
names.

The motivation behind this change is to allow embedded devices to keep
their first switch port be named "eth0", even when switching to the DSA
architecture. In order to do so, it must be possible to name the MAC
interface differently from eth0.

Signed-off-by: Reto Schneider <[email protected]>
---

(no changes since v1)

Documentation/devicetree/bindings/net/mediatek-net.txt | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/mediatek-net.txt b/Documentation/devicetree/bindings/net/mediatek-net.txt
index 72d03e07cf7c..93e35f239a0a 100644
--- a/Documentation/devicetree/bindings/net/mediatek-net.txt
+++ b/Documentation/devicetree/bindings/net/mediatek-net.txt
@@ -51,6 +51,9 @@ Required properties:
is equal to 0 and the MAC uses fixed-link to connect
with internal switch such as MT7530.

+Optional properties:
+- label: Name of interface, defaults to ethX if missing
+
Example:

eth: ethernet@1b100000 {
@@ -76,6 +79,7 @@ eth: ethernet@1b100000 {
compatible = "mediatek,eth-mac";
reg = <0>;
phy-handle = <&phy0>;
+ label = "mac1";
};

gmac2: mac@1 {
--
2.30.2