risc-v/esp32c3: correct receive buffer size
1. correct receive buffer size, d_len should keep the l2 header size
2. fix race condition issue of de/enqueue rx queue
@@ -269,6 +269,34 @@ static inline void wlan_cache_txpkt_tail(struct wlan_priv_s *priv)
netdev_iob_clear(&priv->dev);
}
+/****************************************************************************
+ * Function: wlan_recvframe
+ *
+ * Description:
+ * Try to receive RX packet from RX done packet queue.
+ *
+ * Input Parameters:
+ * priv - Reference to the driver state structure
+ *
+ * Returned Value:
+ * RX packet if success or NULl if no packet in queue.
+ *
+ ****************************************************************************/
+
+static struct iob_s *wlan_recvframe(struct wlan_priv_s *priv)
+{
+ struct iob_s *iob;
+ irqstate_t flags;
+
+ flags = enter_critical_section();
+
+ iob = iob_remove_queue(&priv->rxb);
+
+ leave_critical_section(flags);
+
+ return iob;
+}
+
/****************************************************************************
* Name: wlan_transmit
*
@@ -362,6 +390,7 @@ static void wlan_tx_done(struct wlan_priv_s *priv)
static int wlan_rx_done(struct wlan_priv_s *priv, void *buffer,
uint16_t len, void *eb)
{
+ struct net_driver_s *dev = &priv->dev;
struct iob_s *iob = NULL;
irqstate_t flags;
int ret = 0;
@@ -392,6 +421,8 @@ static int wlan_rx_done(struct wlan_priv_s *priv, void *buffer,
goto out;
}
+ iob_reserve(iob, CONFIG_NET_LL_GUARDSIZE - NET_LL_HDRLEN(dev));
+
ret = iob_trycopyin(iob, buffer, len, 0, false);
if (ret != len)
{
@@ -399,8 +430,6 @@ static int wlan_rx_done(struct wlan_priv_s *priv, void *buffer,
goto out;
}
- iob_reserve(iob, CONFIG_NET_LL_GUARDSIZE);
-
flags = enter_critical_section();
ret = iob_tryadd_queue(iob, &priv->rxb);
leave_critical_section(flags);
@@ -471,11 +500,13 @@ static void wlan_rxpoll(void *arg)
net_lock();
- while ((iob = iob_remove_queue(&priv->rxb)) != NULL)
+ while ((iob = wlan_recvframe(priv)) != NULL)
{
dev->d_iob = iob;
dev->d_len = iob->io_pktlen;
+ iob_reserve(iob, CONFIG_NET_LL_GUARDSIZE);
+
#ifdef CONFIG_NET_PKT
/* When packet sockets are enabled,
