[solved]Qemu Problem with RTL8139 NIC emulation

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
karuon
Posts: 22
Joined: Sat Jun 29, 2013 6:16 am

[solved]Qemu Problem with RTL8139 NIC emulation

Post 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.
User avatar
Jezze
Member
Member
Posts: 395
Joined: Thu Jul 26, 2007 1:53 am
Libera.chat IRC: jfu
Contact:

Re: [qemu] Problem with RTL8139 NIC emulation

Post 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.
Fudge - Simplicity, clarity and speed.
http://github.com/Jezze/fudge/
hidnplayr
Posts: 23
Joined: Sat Aug 09, 2008 5:07 pm

Re: [qemu] Problem with RTL8139 NIC emulation

Post 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
karuon
Posts: 22
Joined: Sat Jun 29, 2013 6:16 am

Re: [qemu] Problem with RTL8139 NIC emulation

Post 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.
User avatar
XanClic
Member
Member
Posts: 138
Joined: Wed Feb 13, 2008 9:38 am

Re: [qemu] Problem with RTL8139 NIC emulation

Post 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)
User avatar
Jezze
Member
Member
Posts: 395
Joined: Thu Jul 26, 2007 1:53 am
Libera.chat IRC: jfu
Contact:

Re: [qemu] Problem with RTL8139 NIC emulation

Post by Jezze »

Hmm that might be it... perhaps they added support for that in later versions of QEMU.
Fudge - Simplicity, clarity and speed.
http://github.com/Jezze/fudge/
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: [qemu] Problem with RTL8139 NIC emulation

Post 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...
Developer of tyndur - community OS of Lowlevel (German)
karuon
Posts: 22
Joined: Sat Jun 29, 2013 6:16 am

Re: [qemu] Problem with RTL8139 NIC emulation

Post 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
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: [qemu] Problem with RTL8139 NIC emulation

Post by Nable »

Will anybody update wiki to add this fact?
User avatar
Jezze
Member
Member
Posts: 395
Joined: Thu Jul 26, 2007 1:53 am
Libera.chat IRC: jfu
Contact:

Re: [qemu] Problem with RTL8139 NIC emulation

Post by Jezze »

Can I just say: EXCELLENT!
Fudge - Simplicity, clarity and speed.
http://github.com/Jezze/fudge/
karuon
Posts: 22
Joined: Sat Jun 29, 2013 6:16 am

Re: [qemu] Problem with RTL8139 NIC emulation

Post by karuon »

Nable wrote:Will anybody update wiki to add this fact?
Ok, I have updated the Wiki.
User avatar
Jezze
Member
Member
Posts: 395
Joined: Thu Jul 26, 2007 1:53 am
Libera.chat IRC: jfu
Contact:

Re: [qemu] Problem with RTL8139 NIC emulation

Post by Jezze »

I can now also confirm this works =)
Fudge - Simplicity, clarity and speed.
http://github.com/Jezze/fudge/
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: [qemu] Problem with RTL8139 NIC emulation

Post by dozniak »

Mark it [solved] will you?
Learn to read.
hidnplayr
Posts: 23
Joined: Sat Aug 09, 2008 5:07 pm

Re: [solved]Qemu Problem with RTL8139 NIC emulation

Post 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.
Post Reply