Skip to contentSkip to conversation

net: ethernet: mediatek: support custom GMAC label

PATCH In review Ilya Lipnitskiy 4 participants 9 messages Apr 19, 2021 – Apr 21, 2021

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v2 cover net: ethernet: mediatek: support custom GMAC label

Add support for specifying GMAC label via DTS. Useful when it is desired to use a master DSA interface name that is different from the "eth%d" pattern.

v2:
- Use alloc_netdev instead of alloc_etherdev followed by rename

Ilya Lipnitskiy (2):
dt-bindings: net: mediatek: add optional GMAC labels
net: ethernet: mediatek: support custom GMAC label

 Documentation/devicetree/bindings/net/mediatek-net.txt | 6 ++++++
 drivers/net/ethernet/mediatek/mtk_eth_soc.c            | 6 ++++--
 2 files changed, 10 insertions(+), 2 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH v2 1/2 dt-bindings: net: mediatek: add optional GMAC labels

Document the mediatek ethernet driver change that adds support for custom labels and provide an example.

---
 Documentation/devicetree/bindings/net/mediatek-net.txt | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/net/mediatek-net.txt +6 -0
index 72d03e07cf7c..500bf9351010 100644
@@ -51,6 +51,10 @@ Required properties:
 	is equal to 0 and the MAC uses fixed-link to connect
 	with internal switch such as MT7530.
 
+Optional properties:
+- label: overrides the default netdevice name. Useful when a custom name for the
+	DSA master interface is desired.
+
 Example:
 
 eth: ethernet@1b100000 {
@@ -74,12 +78,14 @@ eth: ethernet@1b100000 {
 
 	gmac1: mac@0 {
 		compatible = "mediatek,eth-mac";
+		label = "gmac1";
 		reg = <0>;
 		phy-handle = <&phy0>;
 	};
 
 	gmac2: mac@1 {
 		compatible = "mediatek,eth-mac";
+		label = "gmac2";
 		reg = <1>;
 		phy-handle = <&phy1>;
 	};
Signature · 1 line
2.31.1
#2 lore raw

PATCH v2 2/2 net: ethernet: mediatek: support custom GMAC label

In reply to Ilya Lipnitskiy

The MAC device name can now be set within DTS file instead of always being "ethX". This is helpful for DSA to clearly label the DSA master device and distinguish it from DSA slave ports.

For example, some devices, such as the Ubiquiti EdgeRouter X, may have ports labeled ethX. Labeling the master GMAC with a different prefix than DSA ports helps with clarity.

---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +4 -2
index 6b00c12c6c43..df3cda63a8c5 100644
@@ -2845,6 +2845,7 @@ static const struct net_device_ops mtk_netdev_ops = {
 
 static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
 {
+	const char *label = of_get_property(np, "label", NULL);
 	const __be32 *_id = of_get_property(np, "reg", NULL);
 	phy_interface_t phy_mode;
 	struct phylink *phylink;
@@ -2867,9 +2868,10 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
 		return -EINVAL;
 	}
 
-	eth->netdev[id] = alloc_etherdev(sizeof(*mac));
+	eth->netdev[id] = alloc_netdev(sizeof(*mac), label ? label : "eth%d",
+				       NET_NAME_UNKNOWN, ether_setup);
 	if (!eth->netdev[id]) {
-		dev_err(eth->dev, "alloc_etherdev failed\n");
+		dev_err(eth->dev, "alloc_netdev failed\n");
 		return -ENOMEM;
 	}
 	mac = netdev_priv(eth->netdev[id]);
Signature · 1 line
2.31.1
Reviewed-by on v2 2/2
#3 lore raw
Quoted 10 lines · Ilya Lipnitskiy

The MAC device name can now be set within DTS file instead of always being "ethX". This is helpful for DSA to clearly label the DSA master device and distinguish it from DSA slave ports.

For example, some devices, such as the Ubiquiti EdgeRouter X, may have ports labeled ethX. Labeling the master GMAC with a different prefix than DSA ports helps with clarity.

Andrew

maintainer
#4 lore raw
In reply to Ilya Lipnitskiy
Quoted 27 lines · Ilya Lipnitskiy

The MAC device name can now be set within DTS file instead of always being "ethX". This is helpful for DSA to clearly label the DSA master device and distinguish it from DSA slave ports.

For example, some devices, such as the Ubiquiti EdgeRouter X, may have ports labeled ethX. Labeling the master GMAC with a different prefix than DSA ports helps with clarity.

---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +1 -0
index 6b00c12c6c43..df3cda63a8c5 100644
@@ -2845,6 +2845,7 @@ static const struct net_device_ops mtk_netdev_ops = {
 
 static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
 {
+	const char *label = of_get_property(np, "label", NULL);
 	const __be32 *_id = of_get_property(np, "reg", NULL);
 	phy_interface_t phy_mode;
 	struct phylink *phylink;

drivers/net/ethernet/mediatek/mtk_eth_soc.c static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np) · line 2872

Quoted 6 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +2 -1
@@ -2867,9 +2868,10 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
 		return -EINVAL;
 	}
 
-	eth->netdev[id] = alloc_etherdev(sizeof(*mac));
+	eth->netdev[id] = alloc_netdev(sizeof(*mac), label ? label : "eth%d",
+				       NET_NAME_UNKNOWN, ether_setup);

'label' is generally supposed to correspond to the sticker for the device connector for a human to id. I can't really tell if that's the case here. I don't see how 'gmacX' vs. 'ethX' maps to DSA master vs. slave.

I don't think this should be handled within a specific driver either. If we're going to have a way to name things, then fix it in alloc_etherdev().

It can also be argued that device naming for userspace is a userspace (udev) problem.

Rob

#5 lore raw
Quoted 32 lines · Rob Herring
Quoted 30 lines · Ilya Lipnitskiy

The MAC device name can now be set within DTS file instead of always being "ethX". This is helpful for DSA to clearly label the DSA master device and distinguish it from DSA slave ports.

For example, some devices, such as the Ubiquiti EdgeRouter X, may have ports labeled ethX. Labeling the master GMAC with a different prefix than DSA ports helps with clarity.

---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +1 -0
index 6b00c12c6c43..df3cda63a8c5 100644
@@ -2845,6 +2845,7 @@ static const struct net_device_ops mtk_netdev_ops = {
 
 static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
 {
+     const char *label = of_get_property(np, "label", NULL);
      const __be32 *_id = of_get_property(np, "reg", NULL);
      phy_interface_t phy_mode;
      struct phylink *phylink;
@@ -2867,9 +2868,10 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
              return -EINVAL;
      }
 
Quoted 8 lines

drivers/net/ethernet/mediatek/mtk_eth_soc.c static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np) · line 2872

Quoted 3 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +2 -1
-     eth->netdev[id] = alloc_etherdev(sizeof(*mac));
+     eth->netdev[id] = alloc_netdev(sizeof(*mac), label ? label : "eth%d",
+                                    NET_NAME_UNKNOWN, ether_setup);

'label' is generally supposed to correspond to the sticker for the device connector for a human to id. I can't really tell if that's the case here. I don't see how 'gmacX' vs. 'ethX' maps to DSA master vs. slave.

The ports on devices such as Ubiquiti ER-X are named eth0 through eth4, all of them DSA slaves. The gmac (DSA master) is hard-coded to eth0 without this change.

Quoted 7 lines

I don't think this should be handled within a specific driver either. If we're going to have a way to name things, then fix it in alloc_etherdev().

It can also be argued that device naming for userspace is a userspace (udev) problem.

Yeah, that is a valid argument. We can drop this changeset if the agreement is that it doesn't belong in the specific driver or the kernel-space at all.
Some discussion (and device picture) here if you are interested:
https://github.com/openwrt/openwrt/pull/3971

Ilya

#6 lore raw

Hi,

for dsa slave-ports there is already a property "label", but not for master/cpu-ports

https://elixir.bootlin.com/linux/v5.12-rc8/source/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts#L163

handled here:

https://elixir.bootlin.com/linux/v5.12-rc8/source/net/dsa/dsa2.c#L1113

@ilya maybe you can rename slave-ports instead of master-port without code change?

i also prefer a more generic way to name interfaces in dts, not only in the mtk-driver, but the udev-approach is a way too, but this needs to be configured on each system manually...a preset by kernel/dts will be nice (at least to distinguish master/cpu- and user-ports).

regards Frank

maintainer
#7 lore raw
Quoted 4 lines · Frank Wunderlich

Hi,

for dsa slave-ports there is already a property "label", but not for master/cpu-ports

Is that because slave ports are external and master are not? If so, that makes sense.

Quoted 9 lines

https://elixir.bootlin.com/linux/v5.12-rc8/source/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts#L163

handled here:

https://elixir.bootlin.com/linux/v5.12-rc8/source/net/dsa/dsa2.c#L1113

@ilya maybe you can rename slave-ports instead of master-port without code change?

i also prefer a more generic way to name interfaces in dts, not only in the mtk-driver, but the udev-approach is a way too, but this needs to be configured on each system manually...a preset by kernel/dts will be nice (at least to distinguish master/cpu- and user-ports).

Seems like it could be possible to want to distinguish port types for reasons other than just what to name the device. Better to describe that difference in DT and then base the device name off of that.

If you just want fixed numbering, then 'aliases' node is generally how that is done (either because it sneaks in or fatigue from arguing fixed /dev nodes are an anti-feature). There's already 'ethernetN' which u-boot uses, but the kernel so far does not.

Rob

#8 lore raw

Am 21. April 2021 18:12:41 MESZ schrieb Rob Herring <[email protected]>:

Quoted 10 lines
Quoted 4 lines · Frank Wunderlich

Hi,

for dsa slave-ports there is already a property "label", but not for

master/cpu-ports

Is that because slave ports are external and master are not? If so, that makes sense.

In my case gmac is internal,yes...i don't know if ilyas device is similar.

But in a previous kernel-version the gmac of bpi-r2 can be passed through mt7530 switch and gets available external while bypassing dsa core. Here i wanted renaming of this port (gmac1=eth1 mapped as wan-port,while gmac0=eth0 was splitted by dsa switch driver to lan0-lan3)

Quoted 3 lines

Seems like it could be possible to want to distinguish port types for reasons other than just what to name the device. Better to describe that difference in DT and then base the device name off of that.

Interface names should be not only numbering as they can have different meaning (wan vs. lan).

Quoted 4 lines

If you just want fixed numbering, then 'aliases' node is generally how that is done (either because it sneaks in or fatigue from arguing fixed /dev nodes are an anti-feature). There's already 'ethernetN' which u-boot uses, but the kernel so far does not.

Aliases are not yet used as interface name...do you want this way (use alias name as ifname)? imho we can define multiple aliases to one dt node which is imho not the best way as interface can have only one name, and interface is created feom target node from where the alias needs to be found.

regards Frank