Skip to content

Commit a62ee00

Browse files
xdje42pm215
authored andcommitted
net/npcm7xx_emc.c: Fix handling of receiving packets when RSDR not set
Turning REG_MCMDR_RXON is enough to start receiving packets. Signed-off-by: Doug Evans <dje@google.com> Message-id: 20210319195044.741821-1-dje@google.com Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
1 parent 7993b0f commit a62ee00

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

hw/net/npcm7xx_emc.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,9 @@ static void npcm7xx_emc_write(void *opaque, hwaddr offset,
702702
!(value & REG_MCMDR_RXON)) {
703703
emc->regs[REG_MGSTA] |= REG_MGSTA_RXHA;
704704
}
705-
if (!(value & REG_MCMDR_RXON)) {
705+
if (value & REG_MCMDR_RXON) {
706+
emc->rx_active = true;
707+
} else {
706708
emc_halt_rx(emc, 0);
707709
}
708710
break;

tests/qtest/npcm7xx_emc-test.c

+21-9
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,6 @@ static void enable_tx(QTestState *qts, const EMCModule *mod,
492492
mcmdr |= REG_MCMDR_TXON;
493493
emc_write(qts, mod, REG_MCMDR, mcmdr);
494494
}
495-
496-
/* Prod the device to send the packet. */
497-
emc_write(qts, mod, REG_TSDR, 1);
498495
}
499496

500497
static void emc_send_verify1(QTestState *qts, const EMCModule *mod, int fd,
@@ -558,6 +555,9 @@ static void emc_send_verify(QTestState *qts, const EMCModule *mod, int fd,
558555
enable_tx(qts, mod, &desc[0], NUM_TX_DESCRIPTORS, desc_addr,
559556
with_irq ? REG_MIEN_ENTXINTR : 0);
560557

558+
/* Prod the device to send the packet. */
559+
emc_write(qts, mod, REG_TSDR, 1);
560+
561561
/*
562562
* It's problematic to observe the interrupt for each packet.
563563
* Instead just wait until all the packets go out.
@@ -643,13 +643,10 @@ static void enable_rx(QTestState *qts, const EMCModule *mod,
643643
mcmdr |= REG_MCMDR_RXON | mcmdr_flags;
644644
emc_write(qts, mod, REG_MCMDR, mcmdr);
645645
}
646-
647-
/* Prod the device to accept a packet. */
648-
emc_write(qts, mod, REG_RSDR, 1);
649646
}
650647

651648
static void emc_recv_verify(QTestState *qts, const EMCModule *mod, int fd,
652-
bool with_irq)
649+
bool with_irq, bool pump_rsdr)
653650
{
654651
NPCM7xxEMCRxDesc desc[NUM_RX_DESCRIPTORS];
655652
uint32_t desc_addr = DESC_ADDR;
@@ -679,6 +676,15 @@ static void emc_recv_verify(QTestState *qts, const EMCModule *mod, int fd,
679676
enable_rx(qts, mod, &desc[0], NUM_RX_DESCRIPTORS, desc_addr,
680677
with_irq ? REG_MIEN_ENRXINTR : 0, 0);
681678

679+
/*
680+
* If requested, prod the device to accept a packet.
681+
* This isn't necessary, the linux driver doesn't do this.
682+
* Test doing/not-doing this for robustness.
683+
*/
684+
if (pump_rsdr) {
685+
emc_write(qts, mod, REG_RSDR, 1);
686+
}
687+
682688
/* Send test packet to device's socket. */
683689
ret = iov_send(fd, iov, 2, 0, sizeof(len) + sizeof(test));
684690
g_assert_cmpint(ret, == , sizeof(test) + sizeof(len));
@@ -826,8 +832,14 @@ static void test_rx(gconstpointer test_data)
826832

827833
qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic");
828834

829-
emc_recv_verify(qts, td->module, test_sockets[0], /*with_irq=*/false);
830-
emc_recv_verify(qts, td->module, test_sockets[0], /*with_irq=*/true);
835+
emc_recv_verify(qts, td->module, test_sockets[0], /*with_irq=*/false,
836+
/*pump_rsdr=*/false);
837+
emc_recv_verify(qts, td->module, test_sockets[0], /*with_irq=*/false,
838+
/*pump_rsdr=*/true);
839+
emc_recv_verify(qts, td->module, test_sockets[0], /*with_irq=*/true,
840+
/*pump_rsdr=*/false);
841+
emc_recv_verify(qts, td->module, test_sockets[0], /*with_irq=*/true,
842+
/*pump_rsdr=*/true);
831843
emc_test_ptle(qts, td->module, test_sockets[0]);
832844

833845
qtest_quit(qts);

0 commit comments

Comments
 (0)