diff --git a/arch/risc-v/src/common/espressif/esp_wlan_netdev.c b/arch/risc-v/src/common/espressif/esp_wlan_netdev.c index d8a19dfd767f9..fd94e14d54dfc 100644 --- a/arch/risc-v/src/common/espressif/esp_wlan_netdev.c +++ b/arch/risc-v/src/common/espressif/esp_wlan_netdev.c @@ -117,6 +117,7 @@ struct esp_wlan_priv_s struct esp_common_wifi_s *common; uint32_t mode; + spinlock_t rx_lock; netpkt_queue_t netdev_rx_queue; uint8_t flatbuf[CONFIG_NET_ETH_PKTSIZE]; }; @@ -212,6 +213,7 @@ static int esp_wlan_ifup(struct netdev_lowerhalf_s *dev) { struct esp_wlan_priv_s *priv = (struct esp_wlan_priv_s *)dev; struct net_driver_s *netdev = &priv->dev.netdev; + irqstate_t flags; int ret = OK; #ifdef CONFIG_NET_IPv4 @@ -228,7 +230,9 @@ static int esp_wlan_ifup(struct netdev_lowerhalf_s *dev) /* Clear RX queue */ + flags = spin_lock_irqsave(&priv->rx_lock); netpkt_free_queue(&priv->netdev_rx_queue); + spin_unlock_irqrestore(&priv->rx_lock, flags); /* Start Wi-Fi interface */ @@ -349,7 +353,13 @@ static int esp_wlan_transmit(struct netdev_lowerhalf_s *dev, static netpkt_t *esp_wlan_receive(struct netdev_lowerhalf_s *dev) { struct esp_wlan_priv_s *priv = (struct esp_wlan_priv_s *)dev; - netpkt_t *pkt = netpkt_remove_queue(&priv->netdev_rx_queue); + irqstate_t flags; + netpkt_t *pkt; + + flags = spin_lock_irqsave(&priv->rx_lock); + pkt = netpkt_remove_queue(&priv->netdev_rx_queue); + spin_unlock_irqrestore(&priv->rx_lock, flags); + return pkt; } @@ -1008,6 +1018,7 @@ void IRAM_ATTR esp_wifi_tx_done_cb(uint8_t ifidx, static int wlan_rx_done(struct esp_wlan_priv_s *priv, void *buffer, uint16_t len, void *eb) { + irqstate_t flags; int ret = OK; netpkt_t *pkt = NULL; @@ -1025,7 +1036,9 @@ static int wlan_rx_done(struct esp_wlan_priv_s *priv, goto out; } + flags = spin_lock_irqsave(&priv->rx_lock); ret = netpkt_tryadd_queue(pkt, &priv->netdev_rx_queue); + spin_unlock_irqrestore(&priv->rx_lock, flags); if (ret < 0) { wlerr("ERROR: Failed to add packet to queue\n"); @@ -1221,6 +1234,7 @@ static int esp_wlan_initialize(uint32_t mode) priv->dev.rxtype = NETDEV_RX_THREAD; priv->dev.priority = 100; + spin_lock_init(&priv->rx_lock); IOB_QINIT(&priv->netdev_rx_queue); /* Register RX done callback. Called when the RX packet is received. */ diff --git a/arch/xtensa/src/common/espressif/esp_wlan_netdev.c b/arch/xtensa/src/common/espressif/esp_wlan_netdev.c index 2315af64fd9db..64500b2d0e857 100644 --- a/arch/xtensa/src/common/espressif/esp_wlan_netdev.c +++ b/arch/xtensa/src/common/espressif/esp_wlan_netdev.c @@ -117,6 +117,7 @@ struct esp_wlan_priv_s struct esp_common_wifi_s *common; uint32_t mode; + spinlock_t rx_lock; netpkt_queue_t netdev_rx_queue; uint8_t flatbuf[CONFIG_NET_ETH_PKTSIZE]; }; @@ -212,6 +213,7 @@ static int esp_wlan_ifup(struct netdev_lowerhalf_s *dev) { struct esp_wlan_priv_s *priv = (struct esp_wlan_priv_s *)dev; struct net_driver_s *netdev = &priv->dev.netdev; + irqstate_t flags; int ret = OK; #ifdef CONFIG_NET_IPv4 @@ -228,7 +230,9 @@ static int esp_wlan_ifup(struct netdev_lowerhalf_s *dev) /* Clear RX queue */ + flags = spin_lock_irqsave(&priv->rx_lock); netpkt_free_queue(&priv->netdev_rx_queue); + spin_unlock_irqrestore(&priv->rx_lock, flags); /* Start Wi-Fi interface */ @@ -349,7 +353,13 @@ static int esp_wlan_transmit(struct netdev_lowerhalf_s *dev, static netpkt_t *esp_wlan_receive(struct netdev_lowerhalf_s *dev) { struct esp_wlan_priv_s *priv = (struct esp_wlan_priv_s *)dev; - netpkt_t *pkt = netpkt_remove_queue(&priv->netdev_rx_queue); + irqstate_t flags; + netpkt_t *pkt; + + flags = spin_lock_irqsave(&priv->rx_lock); + pkt = netpkt_remove_queue(&priv->netdev_rx_queue); + spin_unlock_irqrestore(&priv->rx_lock, flags); + return pkt; } @@ -1008,6 +1018,7 @@ void IRAM_ATTR esp_wifi_tx_done_cb(uint8_t ifidx, static int wlan_rx_done(struct esp_wlan_priv_s *priv, void *buffer, uint16_t len, void *eb) { + irqstate_t flags; int ret = OK; netpkt_t *pkt = NULL; @@ -1025,7 +1036,9 @@ static int wlan_rx_done(struct esp_wlan_priv_s *priv, goto out; } + flags = spin_lock_irqsave(&priv->rx_lock); ret = netpkt_tryadd_queue(pkt, &priv->netdev_rx_queue); + spin_unlock_irqrestore(&priv->rx_lock, flags); if (ret != OK) { wlerr("ERROR: Failed to add packet to queue\n"); @@ -1224,6 +1237,7 @@ static int esp_wlan_initialize(uint32_t mode) priv->dev.rxtype = NETDEV_RX_THREAD; priv->dev.priority = 100; + spin_lock_init(&priv->rx_lock); IOB_QINIT(&priv->netdev_rx_queue); /* Register RX done callback. Called when the RX packet is received. */