diff mbox series

[net-next,v2,2/2] net: ethernet: mediatek: support custom GMAC label

Message ID 20210419154659.44096-3-ilya.lipnitskiy@gmail.com (mailing list archive)
State Rejected
Delegated to: Netdev Maintainers
Headers show
Series net: ethernet: mediatek: support custom GMAC label | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers success CCed 11 of 11 maintainers
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 19 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link

Commit Message

Ilya Lipnitskiy April 19, 2021, 3:46 p.m. UTC
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.

Suggested-by: René van Dorst <opensource@vdorst.com>
Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com>
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Andrew Lunn April 20, 2021, 1:22 a.m. UTC | #1
On Mon, Apr 19, 2021 at 08:46:59AM -0700, Ilya Lipnitskiy wrote:
> 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.
> 
> Suggested-by: René van Dorst <opensource@vdorst.com>
> Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
Rob Herring (Arm) April 20, 2021, 7:51 p.m. UTC | #2
On Mon, Apr 19, 2021 at 08:46:59AM -0700, Ilya Lipnitskiy wrote:
> 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.
> 
> Suggested-by: René van Dorst <opensource@vdorst.com>
> Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com>
> ---
>  drivers/net/ethernet/mediatek/mtk_eth_soc.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index 6b00c12c6c43..df3cda63a8c5 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -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);

'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
Ilya Lipnitskiy April 20, 2021, 7:57 p.m. UTC | #3
On Tue, Apr 20, 2021 at 12:51 PM Rob Herring <robh@kernel.org> wrote:
>
> On Mon, Apr 19, 2021 at 08:46:59AM -0700, Ilya Lipnitskiy wrote:
> > 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.
> >
> > Suggested-by: René van Dorst <opensource@vdorst.com>
> > Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com>
> > ---
> >  drivers/net/ethernet/mediatek/mtk_eth_soc.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> > index 6b00c12c6c43..df3cda63a8c5 100644
> > --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> > +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> > @@ -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);
>
> '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.
>
> 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
Frank Wunderlich April 21, 2021, 2:04 p.m. UTC | #4
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
Rob Herring (Arm) April 21, 2021, 4:12 p.m. UTC | #5
On Wed, Apr 21, 2021 at 9:05 AM Frank Wunderlich
<frank-w@public-files.de> wrote:
>
> 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.

> 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
Frank Wunderlich April 21, 2021, 4:48 p.m. UTC | #6
Am 21. April 2021 18:12:41 MESZ schrieb Rob Herring <robh@kernel.org>:
>On Wed, Apr 21, 2021 at 9:05 AM Frank Wunderlich
><frank-w@public-files.de> wrote:
>>
>> 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)

>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).

>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
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 6b00c12c6c43..df3cda63a8c5 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -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]);