Skip to content

Commit

Permalink
drivers: nxp_enet: Check link state in iface init
Browse files Browse the repository at this point in the history
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 <declan.snyder@nxp.com>
  • Loading branch information
decsny authored and mmahadevan108 committed Nov 13, 2024
1 parent 0da16f7 commit c139825
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions drivers/ethernet/nxp_enet/eth_nxp_enet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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);
Expand Down

0 comments on commit c139825

Please sign in to comment.