drivers: mdio_nxp_enet: Fix busy wait

Fix the busy wait in the MDIO driver that was causing timing
problems in systems with real time requirements performing tasks
more frequently than about a millisecond.

Restructure the code to be less redundant and change the busy wait
kconfig to microseconds instead of millliseconds. Also actually signal
to the mdio driver that it can use the interrupt instead of busy
waiting, this seems to have been forgotten.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
This commit is contained in:
Declan Snyder 2024-07-08 17:30:27 -05:00 committed by Anas Nashif
parent 9864852540
commit 6ac0d8bf84
3 changed files with 14 additions and 29 deletions

View file

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

View file

@ -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

View file

@ -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;
};
@ -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 */
@ -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), \