[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <DB8PR04MB6985F8A2EB05F426F2CF8C0AECE20@DB8PR04MB6985.eurprd04.prod.outlook.com>
Date: Thu, 5 Mar 2020 13:38:01 +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 v2] fsl/fman: Use random MAC address when none is given
> -----Original Message-----
> From: Sascha Hauer <s.hauer@...gutronix.de>
> Sent: Thursday, March 5, 2020 2:34 PM
> To: netdev@...r.kernel.org
> Cc: Madalin Bucur <madalin.bucur@....com>; Sascha Hauer
> <s.hauer@...gutronix.de>
> Subject: [PATCH v2] 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>
> ---
>
> Changes since v1:
> - Remove printing of permanent MAC address
>
> drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 11 +++++++++--
> drivers/net/ethernet/freescale/fman/fman_memac.c | 4 ----
> drivers/net/ethernet/freescale/fman/mac.c | 10 ++--------
> 3 files changed, 11 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..fc117eab788d 100644
> --- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
> +++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
> @@ -233,8 +233,15 @@ 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);
> + }
To make the HW MAC aware of the new random address you set in the dpaa_eth,
you also need to call mac_dev->change_addr() after eth_hw_addr_random(), like
it's done in dpaa_set_mac_address():
err = mac_dev->change_addr(mac_dev->fman_mac,
(enet_addr_t *)net_dev->dev_addr);
This will write the new MAC address in the MAC HW registers.
>
> 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