[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <DB8PR04MB6985D1FDADE301F4A6C795E3ECE20@DB8PR04MB6985.eurprd04.prod.outlook.com>
Date: Thu, 5 Mar 2020 11:57:37 +0000
From: Madalin Bucur <madalin.bucur@....com>
To: Sascha Hauer <s.hauer@...gutronix.de>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>
Subject: RE: [PATCH] fsl/fman: Use random MAC address when none is given
> -----Original Message-----
> From: Sascha Hauer <s.hauer@...gutronix.de>
> Sent: Thursday, March 5, 2020 1:54 PM
> To: netdev@...r.kernel.org
> Cc: Madalin Bucur <madalin.bucur@....com>; Sascha Hauer
> <s.hauer@...gutronix.de>
> Subject: [PATCH] fsl/fman: Use random MAC address when none is given
>
> There's no need to fail probing when no MAC address is given in the
> device tree, just use a random MAC address.
>
> Signed-off-by: Sascha Hauer <s.hauer@...gutronix.de>
> ---
> drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 13 +++++++++++--
> drivers/net/ethernet/freescale/fman/fman_memac.c | 4 ----
> drivers/net/ethernet/freescale/fman/mac.c | 10 ++--------
> 3 files changed, 13 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
> b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
> index fd93d542f497..18a7235af7c2 100644
> --- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
> +++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
> @@ -233,8 +233,17 @@ static int dpaa_netdev_init(struct net_device
> *net_dev,
> net_dev->features |= net_dev->hw_features;
> net_dev->vlan_features = net_dev->features;
>
> - memcpy(net_dev->perm_addr, mac_addr, net_dev->addr_len);
> - memcpy(net_dev->dev_addr, mac_addr, net_dev->addr_len);
> + if (is_valid_ether_addr(mac_addr)) {
> + dev_info(dev, "FMan MAC address: %pM\n", mac_addr);
> + memcpy(net_dev->perm_addr, mac_addr, net_dev->addr_len);
> + memcpy(net_dev->dev_addr, mac_addr, net_dev->addr_len);
> + } else {
> + eth_hw_addr_random(net_dev);
> + dev_info(dev, "Using random MAC address: %pM\n",
> + net_dev->dev_addr);
> + }
> +
> + dev_info(dev, "FMan perm MAC address: %pM\n", net_dev->perm_addr);
Do you need both prints when using a random MAC address? Otherwise, it's ok.
>
> net_dev->ethtool_ops = &dpaa_ethtool_ops;
>
> diff --git a/drivers/net/ethernet/freescale/fman/fman_memac.c
> b/drivers/net/ethernet/freescale/fman/fman_memac.c
> index e1901874c19f..9e2372688405 100644
> --- a/drivers/net/ethernet/freescale/fman/fman_memac.c
> +++ b/drivers/net/ethernet/freescale/fman/fman_memac.c
> @@ -596,10 +596,6 @@ static void setup_sgmii_internal_phy_base_x(struct
> fman_mac *memac)
>
> static int check_init_parameters(struct fman_mac *memac)
> {
> - if (memac->addr == 0) {
> - pr_err("Ethernet MAC must have a valid MAC address\n");
> - return -EINVAL;
> - }
> if (!memac->exception_cb) {
> pr_err("Uninitialized exception handler\n");
> return -EINVAL;
> diff --git a/drivers/net/ethernet/freescale/fman/mac.c
> b/drivers/net/ethernet/freescale/fman/mac.c
> index 55f2122c3217..9de76bc4ebde 100644
> --- a/drivers/net/ethernet/freescale/fman/mac.c
> +++ b/drivers/net/ethernet/freescale/fman/mac.c
> @@ -724,12 +724,8 @@ static int mac_probe(struct platform_device
> *_of_dev)
>
> /* Get the MAC address */
> mac_addr = of_get_mac_address(mac_node);
> - if (IS_ERR(mac_addr)) {
> - dev_err(dev, "of_get_mac_address(%pOF) failed\n", mac_node);
> - err = -EINVAL;
> - goto _return_of_get_parent;
> - }
> - ether_addr_copy(mac_dev->addr, mac_addr);
> + if (!IS_ERR(mac_addr))
> + ether_addr_copy(mac_dev->addr, mac_addr);
>
> /* Get the port handles */
> nph = of_count_phandle_with_args(mac_node, "fsl,fman-ports", NULL);
> @@ -855,8 +851,6 @@ static int mac_probe(struct platform_device *_of_dev)
> if (err < 0)
> dev_err(dev, "fman_set_mac_active_pause() = %d\n", err);
>
> - dev_info(dev, "FMan MAC address: %pM\n", mac_dev->addr);
> -
> priv->eth_dev = dpaa_eth_add_device(fman_id, mac_dev);
> if (IS_ERR(priv->eth_dev)) {
> dev_err(dev, "failed to add Ethernet platform device for MAC
> %d\n",
> --
> 2.25.1
Powered by blists - more mailing lists