Page 1 of 1

[solved]Qemu Problem with RTL8139 NIC emulation

Posted: Sat Jul 20, 2013 11:50 am
by karuon
Hi,

I am currently writing a driver for RTL8139 NIC and I'm testing it under qemu. Sending packets seems to work well, but receiving is a bit more problematical. In order to test network under qemu, I have set up a tap device and given it an IPv4 address so as to be able to ping my guest machine from the host. I also use Wireshark to sniff the incoming (and outcoming) packets on the tap. When I ping my guest OS, my tap interface does receive ICMP (and also ARP) packets according to Wireshark. qemu also reacts : I get an interrupt with "Reception OK" flag in the Interrupt Status Register of the NIC. The problem is even though an interrupt has been raised to notify an incoming packet, the whole receive buffer is still filled with zeros (as it was initialized at the OS startup). It seems the receive buffer has not been filled with the incoming bytes.

I know there has been a similar issue on the forum (http://forum.osdev.org/viewtopic.php?f=1&t=26555). However, this has not been solved. There's also another point: I have not only tested my driver on qemu but also on real machine. And on real machine, it worked as expected: it dumped as many incoming packets as I wanted, and the dumped bytes were accurate (I could check it with Wireshark again). The NIC I use on my real PC is a RTL8139C. So maybe my driver is not compatible with all the variants of the RTL8139, and in particular not compatible with the version emulated by qemu... But this last assumption is hard to check and I hope there's a simpler explanation.

What do you think about it ?

Thanks in advance.

Re: [qemu] Problem with RTL8139 NIC emulation

Posted: Sat Jul 20, 2013 7:06 pm
by Jezze
Good someone else had the same problem =) I was starting to think I was going crazy there for a moment...

I havent given it any more work since then so I'm still in the same situation as you. :( I think it is a bug with QEMU but I havent gotten around to actually seek the exact problem out. Will be following this thread closely though.

Re: [qemu] Problem with RTL8139 NIC emulation

Posted: Sun Jul 21, 2013 4:15 am
by hidnplayr
I too am troubled with a driver that works on real RTL8139 (tested on at least versions B, C and D), but not fully in QEMU.
The problem I seem to have in QEMU is that interrupts are not fired for received packets.

http://websvn.kolibrios.org/filedetails ... TL8139.asm

Re: [qemu] Problem with RTL8139 NIC emulation

Posted: Sun Jul 21, 2013 5:35 am
by karuon
hidnplayr wrote:I too am troubled with a driver that works on real RTL8139 (tested on at least versions B, C and D), but not fully in QEMU.
The problem I seem to have in QEMU is that interrupts are not fired for received packets.
Normally, an interrupt is fired when a packet is received. To get sure the packet is received, try to use a tap device and dump the incoming packets on your tap with tcpdump or Wireshark.

I have modified the code of qemu a bit so that it displays the received packet to the console : appearently, qemu does receive the good packet. The question now is why it doesn't end up in the receive buffer.

Re: [qemu] Problem with RTL8139 NIC emulation

Posted: Sun Jul 21, 2013 5:37 am
by XanClic
I remember a similar problem of mine… So I'm just asking: Did you enable bus mastering in the PCI command register? (I guess it could work on a real machine because the BIOS already did that – however, I remember that not being the case for qemu)

Re: [qemu] Problem with RTL8139 NIC emulation

Posted: Sun Jul 21, 2013 5:42 am
by Jezze
Hmm that might be it... perhaps they added support for that in later versions of QEMU.

Re: [qemu] Problem with RTL8139 NIC emulation

Posted: Sun Jul 21, 2013 6:01 am
by Kevin
qemu checks the Bus Master bit since version 1.3. Says my commit message at least, I had to fix my code back then, too...

Re: [qemu] Problem with RTL8139 NIC emulation

Posted: Sun Jul 21, 2013 6:15 am
by karuon
XanClic wrote:I remember a similar problem of mine… So I'm just asking: Did you enable bus mastering in the PCI command register? (I guess it could work on a real machine because the BIOS already did that – however, I remember that not being the case for qemu)
I enabled bus mastering and it worked. Thanks ! :D

Re: [qemu] Problem with RTL8139 NIC emulation

Posted: Sun Jul 21, 2013 6:24 am
by Nable
Will anybody update wiki to add this fact?

Re: [qemu] Problem with RTL8139 NIC emulation

Posted: Sun Jul 21, 2013 6:32 am
by Jezze
Can I just say: EXCELLENT!

Re: [qemu] Problem with RTL8139 NIC emulation

Posted: Sun Jul 21, 2013 7:13 am
by karuon
Nable wrote:Will anybody update wiki to add this fact?
Ok, I have updated the Wiki.

Re: [qemu] Problem with RTL8139 NIC emulation

Posted: Sun Jul 21, 2013 10:28 am
by Jezze
I can now also confirm this works =)

Re: [qemu] Problem with RTL8139 NIC emulation

Posted: Sun Jul 21, 2013 10:40 am
by dozniak
Mark it [solved] will you?

Re: [solved]Qemu Problem with RTL8139 NIC emulation

Posted: Wed Aug 07, 2013 8:33 am
by hidnplayr
Just for reference:
My driver did not work on qemu because I wrote the receive configuration register as a word (instead of dword)
This works on real hardware but not in Qemu.