From b26eb8f8489005a2cfb18e7a836c62421655678d Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Wed, 9 Apr 2008 16:03:40 +0100 Subject: [PATCH] ioemu: Fix rtl8139 emulation so that reboot works correctly in 64-bit Windows VMs. Return an error if the guest OS tries to transmit a packet with the transmitter disabled, so that it doesn't spin forever waiting for it to complete. Signed-off-by: Steven Smith --- tools/ioemu/hw/rtl8139.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tools/ioemu/hw/rtl8139.c b/tools/ioemu/hw/rtl8139.c index 42e25e8855..f0414edc91 100644 --- a/tools/ioemu/hw/rtl8139.c +++ b/tools/ioemu/hw/rtl8139.c @@ -1416,6 +1416,8 @@ static uint32_t rtl8139_ChipCmd_read(RTL8139State *s) static void rtl8139_CpCmd_write(RTL8139State *s, uint32_t val) { + int i; + val &= 0xffff; DEBUG_PRINT(("RTL8139C+ command register write(w) val=0x%04x\n", val)); @@ -1423,6 +1425,20 @@ static void rtl8139_CpCmd_write(RTL8139State *s, uint32_t val) /* mask unwriteable bits */ val = SET_MASKED(val, 0xff84, s->CpCmd); + if ( (s->CpCmd & CPlusTxEnb) && + !(val & CPlusTxEnb) ) + { + /* Reset TX status when the transmitter drops from C+ to + non-C+ mode. Windows has a habit of turning off C+ and + then waiting for the TX requests to clear as part of shut + down, and you get stuck forever if there are old DTCRs in + the registers. */ + for (i = 0; i < 4; i++) + { + s->TxStatus[i] = TxHostOwns; + } + } + s->CpCmd = val; } @@ -1765,6 +1781,7 @@ static int rtl8139_transmit_one(RTL8139State *s, int descriptor) { DEBUG_PRINT(("RTL8139: +++ cannot transmit from descriptor %d: transmitter disabled\n", descriptor)); + s->TxStatus[descriptor] = TxAborted | TxHostOwns; return 0; } @@ -1772,6 +1789,7 @@ static int rtl8139_transmit_one(RTL8139State *s, int descriptor) { DEBUG_PRINT(("RTL8139: +++ cannot transmit from descriptor %d: owned by host (%08x)\n", descriptor, s->TxStatus[descriptor])); + s->TxStatus[descriptor] = TxAborted | TxHostOwns; return 0; } -- 2.39.5