From fa10db3e54c9ef3f62871a9e2f74e89298628b28 Mon Sep 17 00:00:00 2001 From: Jani Paalijarvi Date: Wed, 4 Dec 2024 13:21:01 +0200 Subject: [PATCH] mpfs_ethernet.c: Modify interrupt worker Process all data in the buffer which have come during the interrupt work. It's still possible to lost an interrupt because re-enabling interrupts does not trigger an interrupt from events that have occured during interrupts were disabled. Signed-off-by: Jani Paalijarvi --- arch/risc-v/src/mpfs/mpfs_ethernet.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/arch/risc-v/src/mpfs/mpfs_ethernet.c b/arch/risc-v/src/mpfs/mpfs_ethernet.c index 6750523739a09..3407f2b731a68 100644 --- a/arch/risc-v/src/mpfs/mpfs_ethernet.c +++ b/arch/risc-v/src/mpfs/mpfs_ethernet.c @@ -964,6 +964,7 @@ static void mpfs_interrupt_work(void *arg) uint32_t tsr; uint32_t regval; uint32_t queue = 0; /* todo: get from arg */ + uint32_t retries = 5; /* Process pending Ethernet interrupts */ @@ -983,7 +984,7 @@ static void mpfs_interrupt_work(void *arg) * one to this bit. */ - if (tsr != 0) + while (tsr != 0 && retries > 0) { ninfo("TX tsr=0x%X\n", tsr); uint32_t tx_error = 0; @@ -1068,6 +1069,12 @@ static void mpfs_interrupt_work(void *arg) mpfs_txdone(priv, queue); } + + /* Re-read transmit status */ + + tsr = mac_getreg(priv, TRANSMIT_STATUS); + + retries--; } /* Check for the receipt of an RX packet. @@ -1077,7 +1084,9 @@ static void mpfs_interrupt_work(void *arg) * in memory. This indication is cleared by writing a one to this bit. */ - if (rsr != 0) + retries = 5; + + while (rsr != 0 && retries > 0) { uint32_t rx_error = 0; ninfo("RX: rsr=0x%X\n", rsr); @@ -1095,7 +1104,7 @@ static void mpfs_interrupt_work(void *arg) if ((rsr & RECEIVE_STATUS_BUFFER_NOT_AVAILABLE) != 0) { ++rx_error; -// nerr("ERROR: Buffer not available RSR: %08" PRIx32 "\n", rsr); + nerr("ERROR: Buffer not available RSR: %08" PRIx32 "\n", rsr); } /* Check for HRESP not OK */ @@ -1112,7 +1121,7 @@ static void mpfs_interrupt_work(void *arg) if (rx_error != 0) { -// nerr("RX ERROR: reset\n"); + nerr("RX ERROR: reset\n"); mpfs_rxreset(priv); *priv->queue[queue].int_status = 0xffffffff; mac_putreg(priv, RECEIVE_STATUS, 0xffffffff); @@ -1129,8 +1138,19 @@ static void mpfs_interrupt_work(void *arg) mpfs_receive(priv, queue); } + + /* Re-read receive status */ + + rsr = mac_getreg(priv, RECEIVE_STATUS); + + retries--; } + /* NOTE: We might lost an interrupt here. + * Re-enabling interrupts does not trigger an interrupt from events that + * have occured during interrupts were disabled. + */ + net_unlock(); /* Re-enable Ethernet interrupts */