netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: ftgmac100: support getting MAC address from NVMEM
@ 2023-07-13  9:57 Paul Fertser
  2023-07-14  4:44 ` Pavan Chebbi
  2023-07-18  7:30 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 5+ messages in thread
From: Paul Fertser @ 2023-07-13  9:57 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Lunn, Liang He, Geoff Levand, Leon Romanovsky, Tao Ren,
	Wolfram Sang, Paul Fertser, openbmc, linux-kernel

Make use of of_get_ethdev_address() to support reading MAC address not
only from the usual DT nodes but also from an NVMEM provider (e.g. using
a dedicated area in an FRU EEPROM).

Signed-off-by: Paul Fertser <fercerpav@gmail.com>
---
 drivers/net/ethernet/faraday/ftgmac100.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
index a03879a27b04..9135b918dd49 100644
--- a/drivers/net/ethernet/faraday/ftgmac100.c
+++ b/drivers/net/ethernet/faraday/ftgmac100.c
@@ -177,16 +177,20 @@ static void ftgmac100_write_mac_addr(struct ftgmac100 *priv, const u8 *mac)
 	iowrite32(laddr, priv->base + FTGMAC100_OFFSET_MAC_LADR);
 }
 
-static void ftgmac100_initial_mac(struct ftgmac100 *priv)
+static int ftgmac100_initial_mac(struct ftgmac100 *priv)
 {
 	u8 mac[ETH_ALEN];
 	unsigned int m;
 	unsigned int l;
+	int err;
 
-	if (!device_get_ethdev_address(priv->dev, priv->netdev)) {
+	err = of_get_ethdev_address(priv->dev->of_node, priv->netdev);
+	if (err == -EPROBE_DEFER)
+		return err;
+	if (!err) {
 		dev_info(priv->dev, "Read MAC address %pM from device tree\n",
 			 priv->netdev->dev_addr);
-		return;
+		return 0;
 	}
 
 	m = ioread32(priv->base + FTGMAC100_OFFSET_MAC_MADR);
@@ -207,6 +211,8 @@ static void ftgmac100_initial_mac(struct ftgmac100 *priv)
 		dev_info(priv->dev, "Generated random MAC address %pM\n",
 			 priv->netdev->dev_addr);
 	}
+
+	return 0;
 }
 
 static int ftgmac100_set_mac_addr(struct net_device *dev, void *p)
@@ -1843,7 +1849,9 @@ static int ftgmac100_probe(struct platform_device *pdev)
 	priv->aneg_pause = true;
 
 	/* MAC address from chip or random one */
-	ftgmac100_initial_mac(priv);
+	err = ftgmac100_initial_mac(priv);
+	if (err)
+		goto err_phy_connect;
 
 	np = pdev->dev.of_node;
 	if (np && (of_device_is_compatible(np, "aspeed,ast2400-mac") ||
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: ftgmac100: support getting MAC address from NVMEM
  2023-07-13  9:57 [PATCH] net: ftgmac100: support getting MAC address from NVMEM Paul Fertser
@ 2023-07-14  4:44 ` Pavan Chebbi
  2023-07-14  5:18   ` Paul Fertser
  2023-07-18  7:30 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 5+ messages in thread
From: Pavan Chebbi @ 2023-07-14  4:44 UTC (permalink / raw)
  To: Paul Fertser
  Cc: netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Andrew Lunn, Liang He, Geoff Levand,
	Leon Romanovsky, Tao Ren, Wolfram Sang, openbmc, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2598 bytes --]

On Thu, Jul 13, 2023 at 3:28 PM Paul Fertser <fercerpav@gmail.com> wrote:
>
> Make use of of_get_ethdev_address() to support reading MAC address not
> only from the usual DT nodes but also from an NVMEM provider (e.g. using
> a dedicated area in an FRU EEPROM).
>

Looks like earlier ftgmac100_probe() would move on with self generated
(random) MAC addr if getting it from the device failed.
Now you will fail the probe in a failure case. Is that OK?

> Signed-off-by: Paul Fertser <fercerpav@gmail.com>
> ---
>  drivers/net/ethernet/faraday/ftgmac100.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
> index a03879a27b04..9135b918dd49 100644
> --- a/drivers/net/ethernet/faraday/ftgmac100.c
> +++ b/drivers/net/ethernet/faraday/ftgmac100.c
> @@ -177,16 +177,20 @@ static void ftgmac100_write_mac_addr(struct ftgmac100 *priv, const u8 *mac)
>         iowrite32(laddr, priv->base + FTGMAC100_OFFSET_MAC_LADR);
>  }
>
> -static void ftgmac100_initial_mac(struct ftgmac100 *priv)
> +static int ftgmac100_initial_mac(struct ftgmac100 *priv)
>  {
>         u8 mac[ETH_ALEN];
>         unsigned int m;
>         unsigned int l;
> +       int err;
>
> -       if (!device_get_ethdev_address(priv->dev, priv->netdev)) {
> +       err = of_get_ethdev_address(priv->dev->of_node, priv->netdev);
> +       if (err == -EPROBE_DEFER)
> +               return err;
> +       if (!err) {
>                 dev_info(priv->dev, "Read MAC address %pM from device tree\n",
>                          priv->netdev->dev_addr);
> -               return;
> +               return 0;
>         }
>
>         m = ioread32(priv->base + FTGMAC100_OFFSET_MAC_MADR);
> @@ -207,6 +211,8 @@ static void ftgmac100_initial_mac(struct ftgmac100 *priv)
>                 dev_info(priv->dev, "Generated random MAC address %pM\n",
>                          priv->netdev->dev_addr);
>         }
> +
> +       return 0;
>  }
>
>  static int ftgmac100_set_mac_addr(struct net_device *dev, void *p)
> @@ -1843,7 +1849,9 @@ static int ftgmac100_probe(struct platform_device *pdev)
>         priv->aneg_pause = true;
>
>         /* MAC address from chip or random one */
> -       ftgmac100_initial_mac(priv);
> +       err = ftgmac100_initial_mac(priv);
> +       if (err)
> +               goto err_phy_connect;
>
>         np = pdev->dev.of_node;
>         if (np && (of_device_is_compatible(np, "aspeed,ast2400-mac") ||
> --
> 2.34.1
>
>

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4209 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: ftgmac100: support getting MAC address from NVMEM
  2023-07-14  4:44 ` Pavan Chebbi
@ 2023-07-14  5:18   ` Paul Fertser
  2023-07-18  7:15     ` Paolo Abeni
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Fertser @ 2023-07-14  5:18 UTC (permalink / raw)
  To: Pavan Chebbi
  Cc: netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Andrew Lunn, Liang He, Geoff Levand,
	Leon Romanovsky, Tao Ren, Wolfram Sang, openbmc, linux-kernel

Hello Pavan,

On Fri, Jul 14, 2023 at 10:14:02AM +0530, Pavan Chebbi wrote:
> On Thu, Jul 13, 2023 at 3:28 PM Paul Fertser <fercerpav@gmail.com> wrote:
> > Make use of of_get_ethdev_address() to support reading MAC address not
> > only from the usual DT nodes but also from an NVMEM provider (e.g. using
> > a dedicated area in an FRU EEPROM).
> 
> Looks like earlier ftgmac100_probe() would move on with self generated
> (random) MAC addr if getting it from the device failed.
> Now you will fail the probe in a failure case. Is that OK?

I think the previous behaviour is preserved with this patch in all the
cases other than of_get_ethdev_address returning -EPROBE_DEFER. Can
you please explain what failure case you have in mind and how the
probe is going to be failed in that case?

-- 
Be free, use free (http://www.gnu.org/philosophy/free-sw.html) software!
mailto:fercerpav@gmail.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: ftgmac100: support getting MAC address from NVMEM
  2023-07-14  5:18   ` Paul Fertser
@ 2023-07-18  7:15     ` Paolo Abeni
  0 siblings, 0 replies; 5+ messages in thread
From: Paolo Abeni @ 2023-07-18  7:15 UTC (permalink / raw)
  To: Paul Fertser, Pavan Chebbi
  Cc: netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Andrew Lunn, Liang He, Geoff Levand, Leon Romanovsky, Tao Ren,
	Wolfram Sang, openbmc, linux-kernel

On Fri, 2023-07-14 at 08:18 +0300, Paul Fertser wrote:
> Hello Pavan,
> 
> On Fri, Jul 14, 2023 at 10:14:02AM +0530, Pavan Chebbi wrote:
> > On Thu, Jul 13, 2023 at 3:28 PM Paul Fertser <fercerpav@gmail.com> wrote:
> > > Make use of of_get_ethdev_address() to support reading MAC address not
> > > only from the usual DT nodes but also from an NVMEM provider (e.g. using
> > > a dedicated area in an FRU EEPROM).
> > 
> > Looks like earlier ftgmac100_probe() would move on with self generated
> > (random) MAC addr if getting it from the device failed.
> > Now you will fail the probe in a failure case. Is that OK?
> 
> I think the previous behaviour is preserved with this patch in all the
> cases other than of_get_ethdev_address returning -EPROBE_DEFER. Can
> you please explain what failure case you have in mind and how the
> probe is going to be failed in that case?

FTR, I agree with the above: it looks like the old behavior is
preserved. The patch LGTM, thanks!

Paolo


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: ftgmac100: support getting MAC address from NVMEM
  2023-07-13  9:57 [PATCH] net: ftgmac100: support getting MAC address from NVMEM Paul Fertser
  2023-07-14  4:44 ` Pavan Chebbi
@ 2023-07-18  7:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-07-18  7:30 UTC (permalink / raw)
  To: Paul Fertser
  Cc: netdev, davem, edumazet, kuba, pabeni, andrew, windhl, geoff,
	leon, rentao.bupt, wsa+renesas, openbmc, linux-kernel

Hello:

This patch was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Thu, 13 Jul 2023 12:57:43 +0300 you wrote:
> Make use of of_get_ethdev_address() to support reading MAC address not
> only from the usual DT nodes but also from an NVMEM provider (e.g. using
> a dedicated area in an FRU EEPROM).
> 
> Signed-off-by: Paul Fertser <fercerpav@gmail.com>
> ---
>  drivers/net/ethernet/faraday/ftgmac100.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)

Here is the summary with links:
  - net: ftgmac100: support getting MAC address from NVMEM
    https://git.kernel.org/netdev/net-next/c/2cee73cef253

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-07-18  7:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-13  9:57 [PATCH] net: ftgmac100: support getting MAC address from NVMEM Paul Fertser
2023-07-14  4:44 ` Pavan Chebbi
2023-07-14  5:18   ` Paul Fertser
2023-07-18  7:15     ` Paolo Abeni
2023-07-18  7:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).