summaryrefslogtreecommitdiffstats
path: root/hw/serial.c
diff options
context:
space:
mode:
authorAnthony Liguori <aliguori@us.ibm.com>2012-04-01 14:03:21 -0500
committerAnthony Liguori <aliguori@us.ibm.com>2012-04-02 09:43:16 -0500
commit67c5322d7000fd105a926eec44bc1765b7d70bdd (patch)
treef4a211eb911f2f27c21892f67d72a4263475f75e /hw/serial.c
parent6e92466a7c16bc5a33a674b76964f4b1ac7fa44d (diff)
downloadhqemu-67c5322d7000fd105a926eec44bc1765b7d70bdd.zip
hqemu-67c5322d7000fd105a926eec44bc1765b7d70bdd.tar.gz
serial: fix retry logic
I'm not sure if the retry logic has ever worked when not using FIFO mode. I found this while writing a test case although code inspection confirms it is definitely broken. The TSR retry logic will never actually happen because it is guarded by an 'if (s->tsr_rety > 0)' but this is the only place that can ever make the variable greater than zero. That effectively makes the retry logic an 'if (0)'. I believe this is a typo and the intention was >= 0. Once this is fixed though, I see double transmits with my test case. This is because in the non FIFO case, serial_xmit may get invoked while LSR.THRE is still high because the character was processed but the retransmit timer was still active. We can handle this by simply checking for LSR.THRE and returning early. It's possible that the FIFO paths also need some attention. Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/serial.c')
-rw-r--r--hw/serial.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/hw/serial.c b/hw/serial.c
index c0ee55d..b499bca 100644
--- a/hw/serial.c
+++ b/hw/serial.c
@@ -327,6 +327,8 @@ static void serial_xmit(void *opaque)
s->tsr = fifo_get(s,XMIT_FIFO);
if (!s->xmit_fifo.count)
s->lsr |= UART_LSR_THRE;
+ } else if ((s->lsr & UART_LSR_THRE)) {
+ return;
} else {
s->tsr = s->thr;
s->lsr |= UART_LSR_THRE;
@@ -337,7 +339,7 @@ static void serial_xmit(void *opaque)
/* in loopback mode, say that we just received a char */
serial_receive1(s, &s->tsr, 1);
} else if (qemu_chr_fe_write(s->chr, &s->tsr, 1) != 1) {
- if ((s->tsr_retry > 0) && (s->tsr_retry <= MAX_XMIT_RETRY)) {
+ if ((s->tsr_retry >= 0) && (s->tsr_retry <= MAX_XMIT_RETRY)) {
s->tsr_retry++;
qemu_mod_timer(s->transmit_timer, new_xmit_ts + s->char_transmit_time);
return;
OpenPOWER on IntegriCloud