diff --git a/cpu/stm32/Makefile.dep b/cpu/stm32/Makefile.dep index 300b294df6..d45a978ad6 100644 --- a/cpu/stm32/Makefile.dep +++ b/cpu/stm32/Makefile.dep @@ -49,7 +49,7 @@ ifneq (,$(filter stm32_eth,$(USEMODULE))) FEATURES_REQUIRED += periph_eth USEMODULE += iolist USEMODULE += netdev_eth - USEMODULE += netdev_legacy_api + USEMODULE += netdev_new_api USEMODULE += ztimer USEMODULE += ztimer_msec diff --git a/cpu/stm32/periph/eth.c b/cpu/stm32/periph/eth.c index eeb18a8f93..2e3fef1cba 100644 --- a/cpu/stm32/periph/eth.c +++ b/cpu/stm32/periph/eth.c @@ -142,9 +142,6 @@ static ztimer_t _link_status_timer; #endif /** @} */ -/* Synchronization between IRQ and thread context */ -mutex_t stm32_eth_tx_completed = MUTEX_INIT_LOCKED; - /* Descriptors */ static edma_desc_t rx_desc[ETH_RX_DESCRIPTOR_COUNT]; static edma_desc_t tx_desc[ETH_TX_DESCRIPTOR_COUNT]; @@ -586,20 +583,26 @@ static int stm32_eth_send(netdev_t *netdev, const struct iolist *iolist) } /* start TX */ ETH->DMATPDR = 0; - /* await completion */ if (IS_ACTIVE(ENABLE_DEBUG_VERBOSE)) { DEBUG("[stm32_eth] Started to send %u B via DMA\n", bytes_to_send); } - mutex_lock(&stm32_eth_tx_completed); + + return 0; +} + +static int stm32_eth_confirm_send(netdev_t *netdev, void *info) +{ + (void)info; + (void)netdev; if (IS_USED(MODULE_STM32_ETH_TRACING)) { gpio_ll_clear(GPIO_PORT(STM32_ETH_TRACING_TX_PORT_NUM), (1U << STM32_ETH_TRACING_TX_PIN_NUM)); } - if (IS_ACTIVE(ENABLE_DEBUG_VERBOSE)) { - DEBUG("[stm32_eth] TX completed\n"); - } + DEBUG("[stm32_eth] TX completed\n"); /* Error check */ + _debug_tx_descriptor_info(__LINE__); + int tx_bytes = 0; int error = 0; while (1) { uint32_t status = tx_curr->status; @@ -624,6 +627,7 @@ static int stm32_eth_send(netdev_t *netdev, const struct iolist *iolist) _reset_eth_dma(); } tx_curr = tx_curr->desc_next; + tx_bytes += tx_curr->control; if (status & TX_DESC_STAT_LS) { break; } @@ -631,11 +635,10 @@ static int stm32_eth_send(netdev_t *netdev, const struct iolist *iolist) _debug_tx_descriptor_info(__LINE__); - netdev->event_callback(netdev, NETDEV_EVENT_TX_COMPLETE); if (error) { return error; } - return (int)bytes_to_send; + return tx_bytes; } static int get_rx_frame_size(void) @@ -811,6 +814,7 @@ static void stm32_eth_isr(netdev_t *netdev) static const netdev_driver_t netdev_driver_stm32f4eth = { .send = stm32_eth_send, + .confirm_send = stm32_eth_confirm_send, .recv = stm32_eth_recv, .init = stm32_eth_init, .isr = stm32_eth_isr, diff --git a/cpu/stm32/periph/eth_common.c b/cpu/stm32/periph/eth_common.c index db9fa528f1..55e5155db5 100644 --- a/cpu/stm32/periph/eth_common.c +++ b/cpu/stm32/periph/eth_common.c @@ -122,14 +122,14 @@ void isr_eth(void) if (IS_USED(MODULE_STM32_ETH)) { extern netdev_t *stm32_eth_netdev; - extern mutex_t stm32_eth_tx_completed; unsigned tmp = ETH->DMASR; ETH->DMASR = ETH_DMASR_NIS | ETH_DMASR_TS | ETH_DMASR_RS; DEBUG("[periph_eth_common] DMASR = 0x%x\n", tmp); if ((tmp & ETH_DMASR_TS)) { DEBUG("isr_eth: TX completed\n"); - mutex_unlock(&stm32_eth_tx_completed); + stm32_eth_netdev->event_callback(stm32_eth_netdev, + NETDEV_EVENT_TX_COMPLETE); } if ((tmp & ETH_DMASR_RS)) { diff --git a/sys/net/gnrc/netif/gnrc_netif.c b/sys/net/gnrc/netif/gnrc_netif.c index 7c33094179..7ae1cb49de 100644 --- a/sys/net/gnrc/netif/gnrc_netif.c +++ b/sys/net/gnrc/netif/gnrc_netif.c @@ -2061,7 +2061,8 @@ static void _event_cb(netdev_t *dev, netdev_event_t event) #if IS_USED(MODULE_NETDEV_NEW_API) else if (gnrc_netif_netdev_new_api(netif) && (event == NETDEV_EVENT_TX_COMPLETE)) { - event_post(&netif->evq, &netif->event_tx_done); + event_post(&netif->evq[GNRC_NETIF_EVQ_INDEX_PRIO_LOW], + &netif->event_tx_done); } #endif else {