Transmit data in rtl8139 driver

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
Mohsen
Posts: 8
Joined: Tue Feb 18, 2014 11:25 am

Transmit data in rtl8139 driver

Post 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

Code: Select all

outd(io_base + 0x3E,0x4);
I just clear the TOK bit in ISR.
User avatar
zhiayang
Member
Member
Posts: 368
Joined: Tue Dec 27, 2011 7:57 am
Libera.chat IRC: zhiayang

Re: trnasmit data in rtl8139 driver

Post 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:

Code: Select all

uint16_t size;
...

(size << 16)
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.
Mohsen
Posts: 8
Joined: Tue Feb 18, 2014 11:25 am

Re: trnasmit data in rtl8139 driver

Post 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.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: trnasmit data in rtl8139 driver

Post 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.
User avatar
zhiayang
Member
Member
Posts: 368
Joined: Tue Dec 27, 2011 7:57 am
Libera.chat IRC: zhiayang

Re: trnasmit data in rtl8139 driver

Post 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?
Mohsen
Posts: 8
Joined: Tue Feb 18, 2014 11:25 am

Re: trnasmit data in rtl8139 driver

Post 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.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: trnasmit data in rtl8139 driver

Post 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.
User avatar
zhiayang
Member
Member
Posts: 368
Joined: Tue Dec 27, 2011 7:57 am
Libera.chat IRC: zhiayang

Re: Transmit data in rtl8139 driver

Post by zhiayang »

Got it, thanks Candy.
Post Reply