From c1398250e9958eaa67d90c37c612ef392afcf812 Mon Sep 17 00:00:00 2001 From: Declan Snyder Date: Tue, 12 Nov 2024 07:12:57 -0600 Subject: [PATCH] drivers: nxp_enet: Check link state in iface init Still mark the iface as down after ethernet_init, but then actually check the link state and initialize carrier appropriately This fixes the case where, the phy driver doesn't give a callback after iface init due to the link already being up, there was no change from the phy driver perspective, so callback wouldn't happen, and therefore the interface could remain marked as down after boot even if carrier is up. Signed-off-by: Declan Snyder --- drivers/ethernet/nxp_enet/eth_nxp_enet.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/ethernet/nxp_enet/eth_nxp_enet.c b/drivers/ethernet/nxp_enet/eth_nxp_enet.c index dd993e8e3b9589..c5b1ac92b13d0a 100644 --- a/drivers/ethernet/nxp_enet/eth_nxp_enet.c +++ b/drivers/ethernet/nxp_enet/eth_nxp_enet.c @@ -502,6 +502,8 @@ static void eth_nxp_enet_iface_init(struct net_if *iface) const struct device *dev = net_if_get_device(iface); struct nxp_enet_mac_data *data = dev->data; const struct nxp_enet_mac_config *config = dev->config; + const struct device *phy_dev = config->phy_dev; + struct phy_link_state state; net_if_set_link_addr(iface, data->mac_addr, sizeof(data->mac_addr), @@ -518,6 +520,14 @@ static void eth_nxp_enet_iface_init(struct net_if *iface) ethernet_init(iface); net_if_carrier_off(iface); + /* In case the phy driver doesn't report a state change due to link being up + * before calling phy_configure, we should check the state ourself, and then do a + * pseudo-callback + */ + phy_get_link_state(phy_dev, &state); + + nxp_enet_phy_cb(phy_dev, &state, (void *)dev); + config->irq_config_func(); nxp_enet_driver_cb(config->mdio, NXP_ENET_MDIO, NXP_ENET_INTERRUPT_ENABLED, NULL);