Skip to content

Commit

Permalink
mpfs_ethernet.c: Modify interrupt worker
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jpaali committed Dec 4, 2024
1 parent c040a61 commit fa10db3
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions arch/risc-v/src/mpfs/mpfs_ethernet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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);
Expand All @@ -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 */
Expand All @@ -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);
Expand All @@ -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 */
Expand Down

0 comments on commit fa10db3

Please sign in to comment.