Commit d39e1342 authored by Wei Fang's avatar Wei Fang Committed by Jakub Kicinski
Browse files

net: fec: add fec_set_hw_mac_addr() helper function



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: default avatarWei Fang <wei.fang@nxp.com>
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Link: https://patch.msgid.link/20250711091639.1374411-4-wei.fang@nxp.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 2d33dc60
Loading
Loading
Loading
Loading
+14 −12
Original line number Diff line number Diff line
@@ -1123,6 +1123,17 @@ 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);

	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);
}

/*
 * This function is called to start or restart the FEC during a link
 * change, transmit timeout, or to reconfigure the FEC.  The network
@@ -1132,7 +1143,6 @@ static void
fec_restart(struct net_device *ndev)
{
	struct fec_enet_private *fep = netdev_priv(ndev);
	u32 temp_mac[2];
	u32 rcntl = OPT_FRAME_SIZE | FEC_RCR_MII;
	u32 ecntl = FEC_ECR_ETHEREN;

@@ -1145,11 +1155,7 @@ fec_restart(struct net_device *ndev)
	 * enet-mac reset will reset mac address registers too,
	 * so need to reconfigure it.
	 */
	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);
	fec_set_hw_mac_addr(ndev);

	/* Clear any outstanding interrupt, except MDIO. */
	writel((0xffffffff & ~FEC_ENET_MII), fep->hwp + FEC_IEVENT);
@@ -3693,7 +3699,6 @@ static void set_multicast_list(struct net_device *ndev)
static int
fec_set_mac_address(struct net_device *ndev, void *p)
{
	struct fec_enet_private *fep = netdev_priv(ndev);
	struct sockaddr *addr = p;

	if (addr) {
@@ -3710,11 +3715,8 @@ fec_set_mac_address(struct net_device *ndev, void *p)
	if (!netif_running(ndev))
		return 0;

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

	return 0;
}