Page 1 of 1
Transmit data in rtl8139 driver
Posted: Sat Jul 19, 2014 4:10 am
by Mohsen
Hi I am working on rtl8139 driver, now I want to try to transmit data using the driver according to the datasheet the OWN bit in Transmit Status Register must be set when the whole packet is moved to FIFO, but in my code it is not set for the descriptor that I am using, but it is set in all other descriptors why? Also I can only send one time.
this is my code for sending data:
Code: Select all
void send(uint8 *data,uint16 size){
uint32 tsd = (uint32)((size << 16) | 0x0 | (size));
outd(io_base + 0x20,data);
outd(io_base + 0x10,tsd);
tsd = ind(io_base + 0x10);
while(tsd & 0x2000)
tsd = ind(io_base + 0x10);
here the code never returns because OWN bit is never set by the card.
this is part of my interrupt routine that handles packet transmission ok interrupt
I just clear the TOK bit in ISR.
Re: trnasmit data in rtl8139 driver
Posted: Sat Jul 19, 2014 7:42 am
by zhiayang
Hello. I'm not quite sure what the issue is. Is the packet sending? If it's sending, just leave it alone -- the RTL8139 (or at least QEMU's emulation of it) is a little iffy.
If it's not sending: Are you receiving the Tx OK interrupt? Use QEMU with '-net dump,file=netdump.wcap' -- open the file in Wireshark or any other competent packet sniffer.
Also:
What? This might be why your code is failing.
Look at the datasheet/programmer's guide.
Only bits 0 - 12 (13 bits) are the packet's size. Everything above that is for something else, so (size << 16) is setting a bunch wrong bits in the wrong place.
Next -- don't use your uint8_t* data variable directly. The card /needs/ a physical address below 4GB and possibly has some kind of alignment need -- passing any old pointer and writing that to the card is not going to cut it.
Finally, don't poll the IO port directly. Have your interrupt handler set a flag, then loop based on that flag.
Re: trnasmit data in rtl8139 driver
Posted: Sat Jul 19, 2014 12:49 pm
by Mohsen
thanks your hints helped me, the problem was that I was using the same transmit descriptor every time, I should use all descriptors the first then the second then third and finally the fourth then back to the first.
Re: trnasmit data in rtl8139 driver
Posted: Sat Jul 19, 2014 2:52 pm
by Candy
Small bit of advice - enable the rtl8139 specific logging in Qemu. That helped me immensely in understanding what didn't work and why.
Re: trnasmit data in rtl8139 driver
Posted: Sat Jul 19, 2014 8:29 pm
by zhiayang
Mohsen wrote:thanks your hints helped me, the problem was that I was using the same transmit descriptor every time, I should use all descriptors the first then the second then third and finally the fourth then back to the first.
Ah yes, that got me too, until I looked at thePowersGang's driver code and figured out what was going on.
Candy wrote:Small bit of advice - enable the rtl8139 specific logging in Qemu. That helped me immensely in understanding what didn't work and why.
Where's that?
Re: trnasmit data in rtl8139 driver
Posted: Sun Jul 20, 2014 7:15 am
by Mohsen
Candy wrote:Small bit of advice - enable the rtl8139 specific logging in Qemu. That helped me immensely in understanding what didn't work and why.
How can I enable this? I have no idea about it.
Re: trnasmit data in rtl8139 driver
Posted: Mon Jul 21, 2014 4:23 am
by Candy
In qemu sources, hw/net/rtl8139.c line 64 is
Code: Select all
/* debug RTL8139 card */
#define DEBUG_RTL8139 1
Be sure to have that define. That outputs a *lot* of interesting info from the card. By default it is off. You do have to recompile qemu afterwards.
Re: Transmit data in rtl8139 driver
Posted: Mon Jul 21, 2014 9:30 am
by zhiayang
Got it, thanks Candy.