From 4eb118afd1d18d8a2bdfe4413643dae8b7cf4a2e Mon Sep 17 00:00:00 2001 From: Dave Marples Date: Wed, 26 Sep 2018 10:59:47 -0600 Subject: [PATCH] arch/arm/src/imxrt/imxrt_enet.c: Fix a race condition in setting up the Ethernet Tx transfer. --- arch/arm/src/imxrt/imxrt_enet.c | 11 +++++++++-- configs/imxrt1050-evk/src/imxrt_bringup.c | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/arch/arm/src/imxrt/imxrt_enet.c b/arch/arm/src/imxrt/imxrt_enet.c index cac04e12e8..643b954e47 100644 --- a/arch/arm/src/imxrt/imxrt_enet.c +++ b/arch/arm/src/imxrt/imxrt_enet.c @@ -461,6 +461,7 @@ static bool imxrt_txringfull(FAR struct imxrt_driver_s *priv) static int imxrt_transmit(FAR struct imxrt_driver_s *priv) { struct enet_desc_s *txdesc; + irqstate_t flags; uint32_t regval; uint8_t *buf; @@ -526,9 +527,9 @@ static int imxrt_transmit(FAR struct imxrt_driver_s *priv) DEBUGASSERT(txdesc->data == buf); } - /* Start the TX transfer (if it was not already waiting for buffers) */ + /* Make the following operations atomic */ - putreg32(ENET_TDAR, IMXRT_ENET_TDAR); + flags = spin_lock_irqsave(); /* Enable TX interrupts */ @@ -540,6 +541,12 @@ static int imxrt_transmit(FAR struct imxrt_driver_s *priv) (void)wd_start(priv->txtimeout, IMXRT_TXTIMEOUT, imxrt_txtimeout_expiry, 1, (wdparm_t)priv); + + /* Start the TX transfer (if it was not already waiting for buffers) */ + + putreg32(ENET_TDAR, IMXRT_ENET_TDAR); + + spin_unlock_irqrestore(flags); return OK; } diff --git a/configs/imxrt1050-evk/src/imxrt_bringup.c b/configs/imxrt1050-evk/src/imxrt_bringup.c index 9872cc0fd7..c4486a976b 100644 --- a/configs/imxrt1050-evk/src/imxrt_bringup.c +++ b/configs/imxrt1050-evk/src/imxrt_bringup.c @@ -57,6 +57,7 @@ * Private Functions ****************************************************************************/ +#if defined(CONFIG_I2C_DRIVER) && defined(CONFIG_IMXRT_LPI2C1) static void imxrt_i2c_register(int bus) { FAR struct i2c_master_s *i2c; @@ -77,6 +78,7 @@ static void imxrt_i2c_register(int bus) } } } +#endif /**************************************************************************** * Public Functions @@ -109,7 +111,7 @@ int imxrt_bringup(void) } #endif -#if defined ( CONFIG_I2C_DRIVER ) & (CONFIG_IMXRT_LPI2C1) +#if defined(CONFIG_I2C_DRIVER) && defined(CONFIG_IMXRT_LPI2C1) imxrt_i2c_register(1); #endif