From 45dc86acce1fa884ed047dd832a2cffc0eaaf92f Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Tue, 27 Oct 2020 21:19:54 +0100 Subject: [PATCH] cpu/stm32: Fix reception bug in periph_eth The reception code hands RX DMA descriptors back to the DMA right after its contents were copied into the network stack internal buffer. This increases the odds that the DMA never runs out of DMA descriptors to fill, even under high load. However, the loop fetching the Ethernet frame stops to iterate at the end of the frame. If the DMA used one more descriptor to store the FCS, this was not returned back to the DMA. This commit fixes it. --- cpu/stm32/periph/eth.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cpu/stm32/periph/eth.c b/cpu/stm32/periph/eth.c index 29fa6557c4..1dfdf30c39 100644 --- a/cpu/stm32/periph/eth.c +++ b/cpu/stm32/periph/eth.c @@ -652,6 +652,13 @@ static int stm32_eth_recv(netdev_t *netdev, void *buf, size_t max_len, rx_curr = rx_curr->desc_next; } + if ((size + ETHERNET_FCS_LEN - 1) % ETH_RX_BUFFER_SIZE < ETHERNET_FCS_LEN) { + /* one additional rx descriptor was needed only for the FCS, hand that + * back to the DMA as well */ + rx_curr->status = RX_DESC_STAT_OWN; + rx_curr = rx_curr->desc_next; + } + _debug_rx_descriptor_info(__LINE__); handle_lost_rx_irqs(); return size;