Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: mdio_nxp_enet: Fix busy wait #75625

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions drivers/ethernet/nxp_enet/eth_nxp_enet.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ static void eth_nxp_enet_iface_init(struct net_if *iface)
net_eth_carrier_off(data->iface);

config->irq_config_func();

nxp_enet_driver_cb(config->mdio, NXP_ENET_MDIO, NXP_ENET_INTERRUPT_ENABLED, NULL);
}

static enum ethernet_hw_caps eth_nxp_enet_get_capabilities(const struct device *dev)
Expand Down
4 changes: 2 additions & 2 deletions drivers/mdio/Kconfig.nxp_enet
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ if MDIO_NXP_ENET

config MDIO_NXP_ENET_TIMEOUT
int "NXP ENET MDIO Timeout time"
default 1
default 250
help
Time in milliseconds before an MDIO transaction that has not
Time in microseconds before an MDIO transaction that has not
finished is considered to have timed out.

endif # MDIO_NXP_ENET
37 changes: 10 additions & 27 deletions drivers/mdio/mdio_nxp_enet.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ struct nxp_enet_mdio_config {
const struct device *clock_dev;
clock_control_subsys_t clock_subsys;
uint32_t mdc_freq;
uint16_t timeout;
bool disable_preamble;
};

Expand All @@ -41,42 +40,27 @@ struct nxp_enet_mdio_data {
*/
static int nxp_enet_mdio_wait_xfer(const struct device *dev)
{
const struct nxp_enet_mdio_config *config = dev->config;
struct nxp_enet_mdio_data *data = dev->data;
ENET_Type *base = data->base;
int ret = 0;

/* This function will not make sense from IRQ context */
if (k_is_in_isr()) {
return -EWOULDBLOCK;
}

/* Enable the interrupt */
base->EIMR |= ENET_EIMR_MII_MASK;

/* Wait for operation to complete or time out */
if (!data->interrupt_up) {
/* In the case where the interrupt has not been enabled yet because
* ethernet driver has not initiaized, just do a busy wait
*/
k_busy_wait(USEC_PER_MSEC * config->timeout);
if (base->EIR & ENET_EIR_MII_MASK) {
ret = 0;
} else {
ret = -ETIMEDOUT;
}
} else if (k_sem_take(&data->mdio_sem, K_MSEC(config->timeout))) {
/* Interrupt was enabled but did not occur in time */
ret = -ETIMEDOUT;
} else if (base->EIR & ENET_EIR_MII_MASK) {
/* Interrupt happened meaning mdio transaction completed */
ret = 0;
if (data->interrupt_up) {
/* Enable the interrupt */
base->EIMR |= ENET_EIMR_MII_MASK;
} else {
/* No idea what happened */
ret = -EIO;
/* If the interrupt is not available to use yet, just busy wait */
k_busy_wait(CONFIG_MDIO_NXP_ENET_TIMEOUT);
k_sem_give(&data->mdio_sem);
}

return ret;
/* Wait for the MDIO transaction to finish or time out */
k_sem_take(&data->mdio_sem, K_USEC(CONFIG_MDIO_NXP_ENET_TIMEOUT));

return 0;
}

/* MDIO Read API implementation */
Expand Down Expand Up @@ -268,7 +252,6 @@ static int nxp_enet_mdio_init(const struct device *dev)
static const struct nxp_enet_mdio_config nxp_enet_mdio_cfg_##inst = { \
.module_dev = DEVICE_DT_GET(DT_INST_PARENT(inst)), \
.pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
.timeout = CONFIG_MDIO_NXP_ENET_TIMEOUT, \
.clock_dev = DEVICE_DT_GET(DT_CLOCKS_CTLR(DT_INST_PARENT(inst))), \
.clock_subsys = (void *) DT_CLOCKS_CELL_BY_IDX( \
DT_INST_PARENT(inst), 0, name), \
Expand Down
Loading