From 60125038fce71aea3ba06e79595f70fdef471063 Mon Sep 17 00:00:00 2001 From: wangzhi16 Date: Thu, 23 Jan 2025 19:54:18 +0800 Subject: [PATCH] Use small lock to protect resources related to ethernet. Signed-off-by: wangzhi16 --- arch/arm/src/c5471/c5471_ethernet.c | 9 +++-- arch/arm/src/lpc17xx_40xx/lpc17_40_ethernet.c | 34 +++++++++++-------- arch/arm/src/lpc43xx/lpc43_ethernet.c | 9 +++-- arch/arm/src/lpc54xx/lpc54_ethernet.c | 13 ++++--- arch/arm/src/stm32f7/stm32_ethernet.c | 9 +++-- arch/arm/src/stm32h5/stm32_ethernet.c | 9 +++-- arch/arm/src/stm32h7/stm32_ethernet.c | 9 +++-- arch/arm/src/tiva/lm/lm3s_ethernet.c | 21 +++++++----- arch/hc/src/m9s12/m9s12_ethernet.c | 13 ++++--- arch/mips/src/pic32mx/pic32mx_ethernet.c | 13 ++++--- arch/mips/src/pic32mz/pic32mz_ethernet.c | 13 ++++--- arch/risc-v/src/mpfs/mpfs_ethernet.c | 9 +++-- 12 files changed, 100 insertions(+), 61 deletions(-) diff --git a/arch/arm/src/c5471/c5471_ethernet.c b/arch/arm/src/c5471/c5471_ethernet.c index dcfe6cf0702f6..80c801b159f10 100644 --- a/arch/arm/src/c5471/c5471_ethernet.c +++ b/arch/arm/src/c5471/c5471_ethernet.c @@ -40,7 +40,7 @@ #include #include -#include +#include #include #include #include @@ -299,6 +299,7 @@ struct c5471_driver_s struct wdog_s c_txtimeout; /* TX timeout timer */ struct work_s c_irqwork; /* For deferring interrupt work to the work queue */ struct work_s c_pollwork; /* For deferring poll work to the work queue */ + spinlock_t c_lock; /* Spinlock */ /* Note: According to the C547x documentation: "The software has to * maintain two pointers to the current RX-CPU and TX-CPU descriptors. @@ -1786,7 +1787,7 @@ static int c5471_ifdown(struct net_driver_s *dev) /* Disable the Ethernet interrupt */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->c_lock); up_disable_irq(C5471_IRQ_ETHER); /* Disable interrupts going from EIM Module to Interrupt Module. */ @@ -1809,7 +1810,7 @@ static int c5471_ifdown(struct net_driver_s *dev) /* Reset the device */ priv->c_bifup = false; - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->c_lock, flags); return OK; } @@ -2335,6 +2336,8 @@ void arm_netinitialize(void) #endif g_c5471[0].c_dev.d_private = g_c5471; /* Used to recover private state from dev */ + spin_lock_init(&g_c5471[0].c_lock); /* Initialize spinlock */ + /* Register the device with the OS so that socket IOCTLs can be performed */ netdev_register(&g_c5471[0].c_dev, NET_LL_ETHERNET); diff --git a/arch/arm/src/lpc17xx_40xx/lpc17_40_ethernet.c b/arch/arm/src/lpc17xx_40xx/lpc17_40_ethernet.c index 81ea81b1cd3b6..e9eb72632f215 100644 --- a/arch/arm/src/lpc17xx_40xx/lpc17_40_ethernet.c +++ b/arch/arm/src/lpc17xx_40xx/lpc17_40_ethernet.c @@ -40,7 +40,7 @@ #include #include -#include +#include #include #include #include @@ -298,6 +298,7 @@ struct lpc17_40_driver_s struct work_s lp_rxwork; /* RX work continuation */ struct work_s lp_pollwork; /* Poll work continuation */ uint32_t status; + spinlock_t lp_lock; /* Spinlock */ /* This holds the information visible to the NuttX networking layer */ @@ -424,6 +425,7 @@ static inline void lpc17_40_txdescinit(struct lpc17_40_driver_s *priv); static inline void lpc17_40_rxdescinit(struct lpc17_40_driver_s *priv); static inline void lpc17_40_macmode(uint8_t mode); static void lpc17_40_ethreset(struct lpc17_40_driver_s *priv); +static void lpc17_40_ethreset_nolock(struct lpc17_40_driver_s *priv); /**************************************************************************** * Private Functions @@ -1003,14 +1005,14 @@ static void lpc17_40_rxdone_work(void *arg) * lp-txpending TX underrun state is in effect. */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->lp_lock); if (!priv->lp_txpending) { priv->lp_inten |= ETH_RXINTS; lpc17_40_putreg(priv->lp_inten, LPC17_40_ETH_INTEN); } - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->lp_lock, flags); } /**************************************************************************** @@ -1534,7 +1536,7 @@ static int lpc17_40_ifdown(struct net_driver_s *dev) /* Disable the Ethernet interrupt */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->lp_lock); up_disable_irq(LPC17_40_IRQ_ETH); /* Cancel the TX timeout timers */ @@ -1543,9 +1545,9 @@ static int lpc17_40_ifdown(struct net_driver_s *dev) /* Reset the device and mark it as down. */ - lpc17_40_ethreset(priv); + lpc17_40_ethreset_nolock(priv); priv->lp_ifup = false; - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->lp_lock, flags); return OK; } @@ -2909,14 +2911,8 @@ static inline void lpc17_40_macmode(uint8_t mode) * ****************************************************************************/ -static void lpc17_40_ethreset(struct lpc17_40_driver_s *priv) +static void lpc17_40_ethreset_nolock(struct lpc17_40_driver_s *priv) { - irqstate_t flags; - - /* Reset the MAC */ - - flags = enter_critical_section(); - /* Put the MAC into the reset state */ lpc17_40_putreg((ETH_MAC1_TXRST | ETH_MAC1_MCSTXRST | ETH_MAC1_RXRST | @@ -2965,7 +2961,15 @@ static void lpc17_40_ethreset(struct lpc17_40_driver_s *priv) /* Clear any pending interrupts (shouldn't be any) */ lpc17_40_putreg(0xffffffff, LPC17_40_ETH_INTCLR); - leave_critical_section(flags); +} + +static void lpc17_40_ethreset(struct lpc17_40_driver_s *priv) +{ + irqstate_t flags; + + flags = spin_lock_irqsave(&priv->lp_lock); + lpc17_40_ethreset_nolock(priv); + spin_unlock_irqrestore(&priv->lp_lock, flags); } /**************************************************************************** @@ -3033,6 +3037,8 @@ static inline int lpc17_40_ethinitialize(int intf) #endif priv->lp_dev.d_private = priv; /* Used to recover private state from dev */ + spin_lock_init(&priv->lp_lock); /* Initialize spinlock */ + #if CONFIG_LPC17_40_NINTERFACES > 1 # error "A mechanism to associate base address an IRQ with an interface is needed" priv->lp_base = ??; /* Ethernet controller base address */ diff --git a/arch/arm/src/lpc43xx/lpc43_ethernet.c b/arch/arm/src/lpc43xx/lpc43_ethernet.c index cbb1f9d9f6787..533979ecd1330 100644 --- a/arch/arm/src/lpc43xx/lpc43_ethernet.c +++ b/arch/arm/src/lpc43xx/lpc43_ethernet.c @@ -39,7 +39,7 @@ #include #include -#include +#include #include #include #include @@ -512,6 +512,7 @@ struct lpc43_ethmac_s struct wdog_s txtimeout; /* TX timeout timer */ struct work_s irqwork; /* For deferring work to the work queue */ struct work_s pollwork; /* For deferring work to the work queue */ + spinlock_t lock; /* Spinlock */ /* This holds the information visible to the NuttX network */ @@ -2126,7 +2127,7 @@ static int lpc43_ifdown(struct net_driver_s *dev) /* Disable the Ethernet interrupt */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->lock); up_disable_irq(LPC43M4_IRQ_ETHERNET); /* Cancel the TX timeout timers */ @@ -2143,7 +2144,7 @@ static int lpc43_ifdown(struct net_driver_s *dev) /* Mark the device "down" */ priv->ifup = false; - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->lock, flags); return OK; } @@ -3607,6 +3608,8 @@ static inline int lpc43_ethinitialize(void) #endif priv->dev.d_private = &g_lpc43ethmac; /* Used to recover private state from dev */ + spin_lock_init(&priv->lock); /* Initialize spinlock */ + /* Configure GPIO pins to support Ethernet */ lpc43_ethgpioconfig(priv); diff --git a/arch/arm/src/lpc54xx/lpc54_ethernet.c b/arch/arm/src/lpc54xx/lpc54_ethernet.c index c2343ecbf9bfd..7124cfc1e5124 100644 --- a/arch/arm/src/lpc54xx/lpc54_ethernet.c +++ b/arch/arm/src/lpc54xx/lpc54_ethernet.c @@ -71,7 +71,7 @@ #include #include -#include +#include #include #include #include @@ -297,6 +297,7 @@ struct lpc54_ethdriver_s struct work_s eth_pollwork; /* For deferring poll work to the work queue */ struct work_s eth_timeoutwork; /* For deferring timeout work to the work queue */ struct sq_queue_s eth_freebuf; /* Free packet buffers */ + spinlock_t lock; /* Spinlock */ /* Ring state */ @@ -1450,7 +1451,7 @@ static void lpc54_eth_interrupt_work(void *arg) lpc54_eth_channel_work(priv, 1); } - /* Un-lock the network and re-enable Ethernet interrupts */ + /* Un-eth_lock the network and re-enable Ethernet interrupts */ net_unlock(); up_enable_irq(LPC54_IRQ_ETHERNET); @@ -2001,7 +2002,7 @@ static int lpc54_eth_ifdown(struct net_driver_s *dev) /* Disable the Ethernet interrupt */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->eth_lock); up_disable_irq(LPC54_IRQ_ETHERNET); /* Cancel the TX timeout timers */ @@ -2040,14 +2041,14 @@ static int lpc54_eth_ifdown(struct net_driver_s *dev) if (ret < 0) { nerr("ERROR: lpc54_phy_reset failed: %d\n", ret); - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->eth_lock, flags); return ret; } /* Mark the device "down" */ priv->eth_bifup = 0; - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->eth_lock, flags); return OK; } @@ -2881,6 +2882,8 @@ void arm_netinitialize(void) #endif priv->eth_dev.d_private = &g_ethdriver; /* Used to recover private state from dev */ + spin_lock_init(&priv->eth_lock); /* Initialize spinlock */ + /* Configure GPIO pins to support Ethernet */ /* Common MIIM interface */ diff --git a/arch/arm/src/stm32f7/stm32_ethernet.c b/arch/arm/src/stm32f7/stm32_ethernet.c index ade5283d1b928..4ca9a6cf51083 100644 --- a/arch/arm/src/stm32f7/stm32_ethernet.c +++ b/arch/arm/src/stm32f7/stm32_ethernet.c @@ -40,7 +40,7 @@ #include #include -#include +#include #include #include #include @@ -614,6 +614,7 @@ struct stm32_ethmac_s struct wdog_s txtimeout; /* TX timeout timer */ struct work_s irqwork; /* For deferring interrupt work to the work queue */ struct work_s pollwork; /* For deferring poll work to the work queue */ + spinlock_t lock; /* Spinlock */ /* This holds the information visible to the NuttX network */ @@ -2359,7 +2360,7 @@ static int stm32_ifdown(struct net_driver_s *dev) /* Disable the Ethernet interrupt */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->lock); up_disable_irq(STM32_IRQ_ETH); /* Cancel the TX timeout timers */ @@ -2376,7 +2377,7 @@ static int stm32_ifdown(struct net_driver_s *dev) /* Mark the device "down" */ priv->ifup = false; - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->lock, flags); return OK; } @@ -3931,6 +3932,8 @@ int stm32_ethinitialize(int intf) priv->dev.d_private = g_stm32ethmac; /* Used to recover private state from dev */ priv->intf = intf; /* Remember the interface number */ + spin_lock_init(&priv->lock); /* Initialize spinlock */ + stm32_get_uniqueid(uid); crc = crc64(uid, 12); diff --git a/arch/arm/src/stm32h5/stm32_ethernet.c b/arch/arm/src/stm32h5/stm32_ethernet.c index ff193f57b17d9..476ed3be5423a 100644 --- a/arch/arm/src/stm32h5/stm32_ethernet.c +++ b/arch/arm/src/stm32h5/stm32_ethernet.c @@ -38,7 +38,7 @@ #include #include -#include +#include #include #include #include @@ -613,6 +613,7 @@ struct stm32_ethmac_s struct wdog_s txtimeout; /* TX timeout timer */ struct work_s irqwork; /* For deferring interrupt work to the work queue */ struct work_s pollwork; /* For deferring poll work to the work queue */ + spinlock_t lock; /* Spinlock */ /* This holds the information visible to the NuttX network */ @@ -2472,7 +2473,7 @@ static int stm32_ifdown(struct net_driver_s *dev) /* Disable the Ethernet interrupt */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->lock); up_disable_irq(STM32_IRQ_ETH); /* Cancel the TX timeout timers */ @@ -2489,7 +2490,7 @@ static int stm32_ifdown(struct net_driver_s *dev) /* Mark the device "down" */ priv->ifup = false; - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->lock, flags); return OK; } @@ -4192,6 +4193,8 @@ static inline int stm32_ethinitialize(int intf) priv->dev.d_private = g_stm32ethmac; /* Used to recover private state */ priv->intf = intf; /* Remember the interface number */ + spin_lock_init(&priv->lock); /* Initialize spinlock */ + stm32_get_uniqueid(uid); crc = crc64(uid, 12); diff --git a/arch/arm/src/stm32h7/stm32_ethernet.c b/arch/arm/src/stm32h7/stm32_ethernet.c index 84d56876089e8..121095a146d7b 100644 --- a/arch/arm/src/stm32h7/stm32_ethernet.c +++ b/arch/arm/src/stm32h7/stm32_ethernet.c @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include #include @@ -614,6 +614,7 @@ struct stm32_ethmac_s struct wdog_s txtimeout; /* TX timeout timer */ struct work_s irqwork; /* For deferring interrupt work to the work queue */ struct work_s pollwork; /* For deferring poll work to the work queue */ + spinlock_t lock; /* Spinlock */ /* This holds the information visible to the NuttX network */ @@ -2473,7 +2474,7 @@ static int stm32_ifdown(struct net_driver_s *dev) /* Disable the Ethernet interrupt */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->lock); up_disable_irq(STM32_IRQ_ETH); /* Cancel the TX timeout timers */ @@ -2490,7 +2491,7 @@ static int stm32_ifdown(struct net_driver_s *dev) /* Mark the device "down" */ priv->ifup = false; - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->lock, flags); return OK; } @@ -4191,6 +4192,8 @@ static inline int stm32_ethinitialize(int intf) priv->dev.d_private = g_stm32ethmac; /* Used to recover private state */ priv->intf = intf; /* Remember the interface number */ + spin_lock_init(&priv->lock); /* Initialize spinlock */ + stm32_get_uniqueid(uid); crc = crc64(uid, 12); diff --git a/arch/arm/src/tiva/lm/lm3s_ethernet.c b/arch/arm/src/tiva/lm/lm3s_ethernet.c index 73be2530e4a60..896912945c741 100644 --- a/arch/arm/src/tiva/lm/lm3s_ethernet.c +++ b/arch/arm/src/tiva/lm/lm3s_ethernet.c @@ -40,7 +40,7 @@ #include #include -#include +#include #include #include #include @@ -191,6 +191,7 @@ struct tiva_driver_s struct wdog_s ld_txtimeout; /* TX timeout timer */ struct work_s ld_irqwork; /* For deferring interrupt work to the work queue */ struct work_s ld_pollwork; /* For deferring poll work to the work queue */ + spinlock_t ld_lock; /* Spinlock */ /* This holds the information visible to the NuttX network */ @@ -353,7 +354,7 @@ static void tiva_ethreset(struct tiva_driver_s *priv) /* Make sure that clocking is enabled for the Ethernet&PHY peripherals */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->ld_lock); regval = getreg32(TIVA_SYSCON_RCGC2); regval |= (SYSCON_RCGC2_EMAC0 | SYSCON_RCGC2_EPHY0); putreg32(regval, TIVA_SYSCON_RCGC2); @@ -400,7 +401,7 @@ static void tiva_ethreset(struct tiva_driver_s *priv) regval = tiva_ethin(priv, TIVA_MAC_RIS_OFFSET); tiva_ethout(priv, TIVA_MAC_IACK_OFFSET, regval); - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->ld_lock, flags); } /**************************************************************************** @@ -510,7 +511,7 @@ static int tiva_transmit(struct tiva_driver_s *priv) /* Verify that the hardware is ready to send another packet */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->ld_lock); if ((tiva_ethin(priv, TIVA_MAC_TR_OFFSET) & MAC_TR_NEWTX) == 0) { /* Increment statistics */ @@ -582,7 +583,7 @@ static int tiva_transmit(struct tiva_driver_s *priv) ret = OK; } - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->ld_lock, flags); return ret; } @@ -1140,7 +1141,7 @@ static int tiva_ifup(struct net_driver_s *dev) /* Enable and reset the Ethernet controller */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->ld_lock); tiva_ethreset(priv); /* Set the management clock divider register for access to the PHY @@ -1259,7 +1260,7 @@ static int tiva_ifup(struct net_driver_s *dev) tiva_ethout(priv, TIVA_MAC_IA1_OFFSET, regval); priv->ld_bifup = true; - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->ld_lock, flags); return OK; } @@ -1292,7 +1293,7 @@ static int tiva_ifdown(struct net_driver_s *dev) /* Cancel the TX timeout timers */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->ld_lock); wd_cancel(&priv->ld_txtimeout); /* Disable the Ethernet interrupt */ @@ -1341,7 +1342,7 @@ static int tiva_ifdown(struct net_driver_s *dev) /* The interface is now DOWN */ priv->ld_bifup = false; - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->ld_lock, flags); return OK; } @@ -1547,6 +1548,8 @@ static inline int tiva_ethinitialize(int intf) priv->ld_irq = ??; /* Ethernet controller IRQ number */ #endif + spin_lock_init(&priv->ld_lock); /* Initialize spinlock */ + #ifdef CONFIG_TIVA_BOARDMAC /* If the board can provide us with a MAC address, get the address * from the board now. The MAC will not be applied until tiva_ifup() diff --git a/arch/hc/src/m9s12/m9s12_ethernet.c b/arch/hc/src/m9s12/m9s12_ethernet.c index 3c6a43bddb973..c1be5b231a101 100644 --- a/arch/hc/src/m9s12/m9s12_ethernet.c +++ b/arch/hc/src/m9s12/m9s12_ethernet.c @@ -38,7 +38,7 @@ #include #include -#include +#include #include #include #include @@ -79,6 +79,7 @@ struct emac_driver_s { bool d_bifup; /* true:ifup false:ifdown */ struct wdog_s d_txtimeout; /* TX timeout timer */ + spinlock_t d_lock; /* Spinlock */ /* This holds the information visible to the NuttX network */ @@ -475,7 +476,7 @@ static int emac_ifdown(struct net_driver_s *dev) /* Disable the Ethernet interrupt */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->d_lock); up_disable_irq(CONFIG_HCS12_IRQ); /* Cancel the TX timeout timers */ @@ -490,7 +491,7 @@ static int emac_ifdown(struct net_driver_s *dev) /* Mark the device "down" */ priv->d_bifup = false; - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->d_lock, flags); return OK; } @@ -523,7 +524,7 @@ static int emac_txavail(struct net_driver_s *dev) * level processing. */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->d_lock); /* Ignore the notification if the interface is not yet up */ @@ -536,7 +537,7 @@ static int emac_txavail(struct net_driver_s *dev) devif_poll(&priv->d_dev, emac_txpoll); } - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->d_lock, flags); return OK; } @@ -654,6 +655,8 @@ int emac_initialize(int intf) #endif priv->d_dev.d_private = priv; /* Used to recover private state from dev */ + spin_lock_init(&priv->d_lock); /* Initialize spinlock */ + /* Put the interface in the down state. This usually amounts to resetting * the device and/or calling emac_ifdown(). */ diff --git a/arch/mips/src/pic32mx/pic32mx_ethernet.c b/arch/mips/src/pic32mx/pic32mx_ethernet.c index dc4e3ffeffe2b..39968f38b2563 100644 --- a/arch/mips/src/pic32mx/pic32mx_ethernet.c +++ b/arch/mips/src/pic32mx/pic32mx_ethernet.c @@ -39,7 +39,7 @@ #include -#include +#include #include #include #include @@ -304,6 +304,7 @@ struct pic32mx_driver_s struct wdog_s pd_txtimeout; /* TX timeout timer */ struct work_s pd_irqwork; /* For deferring interrupt work to the work queue */ struct work_s pd_pollwork; /* For deferring poll work to the work queue */ + spinlock_t pd_lock; /* Spinlock */ sq_queue_t pd_freebuffers; /* The free buffer list */ @@ -2217,7 +2218,7 @@ static int pic32mx_ifdown(struct net_driver_s *dev) /* Disable the Ethernet interrupt */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->pd_lock); #if CONFIG_PIC32MX_NINTERFACES > 1 up_disable_irq(priv->pd_irqsrc); #else @@ -2232,7 +2233,7 @@ static int pic32mx_ifdown(struct net_driver_s *dev) pic32mx_ethreset(priv); priv->pd_ifup = false; - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->pd_lock, flags); return OK; } @@ -3082,7 +3083,7 @@ static void pic32mx_ethreset(struct pic32mx_driver_s *priv) /* Reset the MAC */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->pd_lock); /* Ethernet Controller Initialization *************************************/ @@ -3146,7 +3147,7 @@ static void pic32mx_ethreset(struct pic32mx_driver_s *priv) up_udelay(50); pic32mx_putreg(0, PIC32MX_EMAC1_CFG1); - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->pd_lock, flags); } /**************************************************************************** @@ -3200,6 +3201,8 @@ static inline int pic32mx_ethinitialize(int intf) priv->pd_irqsrc = ??; /* Ethernet controller IRQ source number */ #endif + spin_lock_init(&priv->pd_lock); /* Initialize spinlock */ + /* Reset the Ethernet controller and leave in the ifdown state. The * Ethernet controller will be properly re-initialized each time * pic32mx_ifup() is called. diff --git a/arch/mips/src/pic32mz/pic32mz_ethernet.c b/arch/mips/src/pic32mz/pic32mz_ethernet.c index 1baad21b5fdf8..4b2d1440fde40 100644 --- a/arch/mips/src/pic32mz/pic32mz_ethernet.c +++ b/arch/mips/src/pic32mz/pic32mz_ethernet.c @@ -37,7 +37,7 @@ #include -#include +#include #include #include #include @@ -366,6 +366,7 @@ struct pic32mz_driver_s struct wdog_s pd_txtimeout; /* TX timeout timer */ struct work_s pd_irqwork; /* For deferring interrupt work to the work queue */ struct work_s pd_pollwork; /* For deferring poll work to the work queue */ + spinlock_t pd_lock; /* Spinlock */ sq_queue_t pd_freebuffers; /* The free buffer list */ @@ -2366,7 +2367,7 @@ static int pic32mz_ifdown(struct net_driver_s *dev) /* Disable the Ethernet interrupt */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->pd_lock); #if CONFIG_PIC32MZ_NINTERFACES > 1 up_disable_irq(priv->pd_irqsrc); #else @@ -2381,7 +2382,7 @@ static int pic32mz_ifdown(struct net_driver_s *dev) pic32mz_ethreset(priv); priv->pd_ifup = false; - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->pd_lock, flags); return OK; } @@ -3248,7 +3249,7 @@ static void pic32mz_ethreset(struct pic32mz_driver_s *priv) /* Reset the MAC */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->pd_lock); /* Ethernet Controller Initialization *************************************/ @@ -3313,7 +3314,7 @@ static void pic32mz_ethreset(struct pic32mz_driver_s *priv) up_udelay(50); pic32mz_putreg(0, PIC32MZ_EMAC1_CFG1); - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->pd_lock, flags); } /**************************************************************************** @@ -3367,6 +3368,8 @@ static inline int pic32mz_ethinitialize(int intf) priv->pd_irqsrc = ; /* Ethernet controller IRQ source number */ #endif + spin_lock_init(&priv->pd_lock); /* Initialize spinlock */ + /* Configure Ethernet peripheral pin selections */ /* Controlled by DEVCFG FMIIEN and FETHIO settings */ diff --git a/arch/risc-v/src/mpfs/mpfs_ethernet.c b/arch/risc-v/src/mpfs/mpfs_ethernet.c index b47d5cdf7b704..c1ac7749262aa 100644 --- a/arch/risc-v/src/mpfs/mpfs_ethernet.c +++ b/arch/risc-v/src/mpfs/mpfs_ethernet.c @@ -38,7 +38,7 @@ #include #include -#include +#include #include #include #include @@ -272,6 +272,7 @@ struct mpfs_ethmac_s struct wdog_s txtimeout; /* TX timeout timer */ struct work_s irqwork; /* For deferring interrupt work to the work queue */ struct work_s pollwork; /* For deferring poll work to the work queue */ + spinlock_t lock; /* Spinlock */ /* This holds the information visible to the NuttX network */ @@ -1588,7 +1589,7 @@ static int mpfs_ifdown(struct net_driver_s *dev) /* Disable the Ethernet interrupt */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&priv->lock); up_disable_irq(priv->mac_q_int[0]); up_disable_irq(priv->mac_q_int[1]); up_disable_irq(priv->mac_q_int[2]); @@ -1613,7 +1614,7 @@ static int mpfs_ifdown(struct net_driver_s *dev) /* Mark the device "down" */ priv->ifup = false; - leave_critical_section(flags); + spin_unlock_irqrestore(&priv->lock, flags); return OK; } @@ -3608,6 +3609,8 @@ int mpfs_ethinitialize(int intf) priv->queue[2].dma_rxbuf_size = (uint32_t *)(base + DMA_RXBUF_SIZE_Q2); priv->queue[3].dma_rxbuf_size = (uint32_t *)(base + DMA_RXBUF_SIZE_Q3); + spin_lock_init(&priv->lock); /* Initialize spinlock */ + /* Generate a locally administrated MAC address for this ethernet if */ /* Set first byte to 0x02 or 0x06 acc. to the intf */