From: Maxime Chevallier <maxime.chevallier@bootlin.com>
To: Wei Fang <wei.fang@nxp.com>
Cc: shenwei.wang@nxp.com, xiaoning.wang@nxp.com,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH net-next 3/3] net: fec: add fec_set_hw_mac_addr() helper function
Date: Thu, 10 Jul 2025 15:57:28 +0200 [thread overview]
Message-ID: <20250710155728.363bcfd6@fedora> (raw)
In-Reply-To: <20250710090902.1171180-4-wei.fang@nxp.com>
Hi,
On Thu, 10 Jul 2025 17:09:02 +0800
Wei Fang <wei.fang@nxp.com> wrote:
> In the current driver, the MAC address is set in both fec_restart() and
> fec_set_mac_address(), so a generic helper function fec_set_hw_mac_addr()
> is added to set the hardware MAC address to make the code more compact.
>
> Signed-off-by: Wei Fang <wei.fang@nxp.com>
> ---
> drivers/net/ethernet/freescale/fec_main.c | 27 +++++++++++++----------
> 1 file changed, 15 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
> index 00f8be4119ed..883b28e59a3c 100644
> --- a/drivers/net/ethernet/freescale/fec_main.c
> +++ b/drivers/net/ethernet/freescale/fec_main.c
> @@ -1123,6 +1123,18 @@ static void fec_ctrl_reset(struct fec_enet_private *fep, bool allow_wol)
> }
> }
>
> +static void fec_set_hw_mac_addr(struct net_device *ndev)
> +{
> + struct fec_enet_private *fep = netdev_priv(ndev);
> + u32 temp_mac[2];
> +
> + memcpy(temp_mac, ndev->dev_addr, ETH_ALEN);
> + writel((__force u32)cpu_to_be32(temp_mac[0]),
> + fep->hwp + FEC_ADDR_LOW);
> + writel((__force u32)cpu_to_be32(temp_mac[1]),
> + fep->hwp + FEC_ADDR_HIGH);
> +}
[ ... ]
> - writel(ndev->dev_addr[3] | (ndev->dev_addr[2] << 8) |
> - (ndev->dev_addr[1] << 16) | (ndev->dev_addr[0] << 24),
> - fep->hwp + FEC_ADDR_LOW);
> - writel((ndev->dev_addr[5] << 16) | (ndev->dev_addr[4] << 24),
> - fep->hwp + FEC_ADDR_HIGH);
> + fec_set_hw_mac_addr(ndev);
It's more of a personal preference, but I find this implementation to
be much more readable than the one based on
writel((__force u32)cpu_to_be32(temp_mac[...]), ...);
Maxime
next prev parent reply other threads:[~2025-07-10 13:57 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-10 9:08 [PATCH net-next 0/3] net: fec: add some optimizations Wei Fang
2025-07-10 9:09 ` [PATCH net-next 1/3] net: fec: use phy_interface_mode_is_rgmii() to check RGMII mode Wei Fang
2025-07-10 13:52 ` Maxime Chevallier
2025-07-10 9:09 ` [PATCH net-next 2/3] net: fec: add more macros for bits of FEC_ECR Wei Fang
2025-07-10 13:53 ` Maxime Chevallier
2025-07-10 9:09 ` [PATCH net-next 3/3] net: fec: add fec_set_hw_mac_addr() helper function Wei Fang
2025-07-10 13:57 ` Maxime Chevallier [this message]
2025-07-10 14:50 ` Andrew Lunn
2025-07-11 1:28 ` Wei Fang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250710155728.363bcfd6@fedora \
--to=maxime.chevallier@bootlin.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=imx@lists.linux.dev \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shenwei.wang@nxp.com \
--cc=wei.fang@nxp.com \
--cc=xiaoning.wang@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox