OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 1:15 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Intel 8254x doesn't report received packets?
PostPosted: Mon Jul 03, 2017 5:29 am 
Offline
Member
Member

Joined: Sat Oct 16, 2010 3:38 pm
Posts: 587
I am having some real difficulties getting the Intel 8254x to receive properly. Here's my current code:

https://github.com/madd-games/glidix/bl ... 00/e1000.c

I'm not sure at all where i might be going wrong, but the situation is as follows: the device sometimes fails to report received packets to the system on time (or at all). This usually happens if some packets are received early. I have attached a wireshark capture of the situation where this bug is triggered; the 4 M-SEARCH packets are received just as glidix is booting, then when glidix sends out DHCP discovery, it is not seeing the DHCP offer. As seen in the code, I added a kprintf_debug() to test which interrupts are arriving. I got the "receive" interrupt (bit 7, 0x0080) 4 times; and it receives the M-SEARCH packets, but not the DHCP offers. LATER, however, when more packets arrive, it DOES receive the bit 7 interrupt again, and the packets arrive; but why am I not getting an interrupt at the moment the packets acually arrive?

Is this the wrong way of receiving on said device?

Furthermore, on line 313 I have a commented-out loop which tries to get as many packets as possible by testing the "descriptor done" bit in the descriptor's status. When I uncomment this loop, then the situation is better, but STILL fails sometimes (mainly if there is more traffic). There has to be some sort of a race somewhere...

I am really stuck on this because any attempts at debugging seem to just hide the bug; suddenly when I dump packets the bug becomes extremely rare, and when I catch it, all I see is that the packets, once again, simply arrive late.

Does anyone have any suggestions at all?

(EDIT: attached the wireshark dump, which i forgot to do)


Top
 Profile  
 
 Post subject: Re: Intel 8254x doesn't report received packets?
PostPosted: Mon Jul 03, 2017 2:50 pm 
Offline
Member
Member

Joined: Sat Oct 16, 2010 3:38 pm
Posts: 587
More information: when i do put that loop in (so it tries reading all "Done" descriptors), as I said it mostly works. And in the case it DOESN'T work, it's because, for reasons I do not understand, the first descriptor (index 0) does not have the "descriptor done" bit set, despite the fact that the "head" pointer is already ahead...


Top
 Profile  
 
 Post subject: Re: Intel 8254x doesn't report received packets?
PostPosted: Mon Jul 03, 2017 9:30 pm 
Offline
Member
Member

Joined: Sat Jul 02, 2016 7:02 am
Posts: 207
- Interrupt coalescing hardware or emulator may mean a single interrupt for multiple packets.
- You may want to try and reduce the number of rx desc to 1 or 2, and examine the behaviour.
- The pcapng shows the interface name is vboxnet0. Manually tracing the emulator's source, with the parameters your driver passes, can help.


Edit:

Since the rx direction has problems, it may help to keep the tx functionality disabled in the driver, and use a small program on the host to blast your guest with packets to exercise the driver.

If nothing else works, programming a simpler device, such as ne2k or pcnet, may help as a stepping stone towards the support for e1000.


Top
 Profile  
 
 Post subject: Re: Intel 8254x doesn't report received packets?
PostPosted: Tue Jul 04, 2017 6:45 am 
Offline
Member
Member
User avatar

Joined: Thu Aug 06, 2015 6:41 am
Posts: 97
Location: Netherlands
I'm not sure if this could be the cause, but in your initialisation code you set the tail pointer to NUM_RX_DESC, but if I understand the manual for the device correctly it should be 0. The manual says the ring is empty if head and tail are equal, and that tail should always point to an area in the descriptor ring, so since initially head is 0 and the descriptor ring is empty, tail should also be 0.
mariuszp wrote:
in the case it DOESN'T work, it's because, for reasons I do not understand, the first descriptor (index 0) does not have the "descriptor done" bit set, despite the fact that the "head" pointer is already ahead...
But do you actually receive an interrupt in this case? And have any of the descriptor fields or the buffer it points to actually been filled with (new) data despite the DD bit not being set?
Also note that the manual says this:
Manual, 13.4.28, Receive Descriptor Head wrote:
Reading the descriptor head to determine which buffers are finished is not reliable.
Which doesn't mean you can't use it for debugging (it is still a useful indication that the device received something), but it could explain why the head can move while the DD bit is still zero.


Top
 Profile  
 
 Post subject: Re: Intel 8254x doesn't report received packets?
PostPosted: Tue Jul 04, 2017 7:13 am 
Offline
Member
Member

Joined: Sat Oct 16, 2010 3:38 pm
Posts: 587
It seems fixed. but..

1) The reason the DD bits were set is because i enabled bus mastering too late. THat is now fixed.
2) Now, suddenly, all the descritpros HAD the DD bit set, so I had to check both that bit AND the head.
3) The final problem was that now it was all working, but in some cases it neither sent nor received any packets (no interrupts arrived). I think I fixed it and it was due to the interrupt handler being registered only after interrupts were enabled (but surely no interrupts should be arriving before the receiver is enbaled anyway...)

But if reading the head pointer is unreliable, that puts (2) to question. And most of all I don't understand why all descriptors were marked "done" before they arrived.

I will now be running it repeatedly to test if the problem occurs ever again.

And the reason i was setting the tails to NUM_TX_DESCRIPTORS / NUM_RX_DESCRIPTORS was because the binary guy's example code (linking on the wiki) was doing it. But then agaiin, it wasn't doing the things I listed above so I don't know where exactly the problem lies.

Given that information, would you suggest anything else or does this seem like a valid solution?


Top
 Profile  
 
 Post subject: Re: Intel 8254x doesn't report received packets?
PostPosted: Tue Jul 04, 2017 9:33 am 
Offline
Member
Member
User avatar

Joined: Thu Aug 06, 2015 6:41 am
Posts: 97
Location: Netherlands
mariuszp wrote:
3) The final problem was that now it was all working, but in some cases it neither sent nor received any packets (no interrupts arrived). I think I fixed it and it was due to the interrupt handler being registered only after interrupts were enabled (but surely no interrupts should be arriving before the receiver is enabled anyway...)
There is a Link Status Change interrupt which fires once the link has been set up, and a Transmit Descriptor Queue Empty interrupt which fires when the transmit queue becomes empty (perhaps initialising an empty queue triggers it as well), so you could get one of those during initialisation before receiving is enabled...
mariuszp wrote:
Given that information, would you suggest anything else or does this seem like a valid solution?
If that weird thing where all the descriptors have the DD bit set for no apparent reason no longer happens, and you receive all packets, then I'd say everything is OK. If you can't rely on just the DD bit alone, then there is probably something wrong since both the example linked to by the wiki and the manual suggest that you should use just the DD bit.


Top
 Profile  
 
 Post subject: Re: Intel 8254x doesn't report received packets?
PostPosted: Tue Jul 04, 2017 2:19 pm 
Offline
Member
Member

Joined: Sun Jun 16, 2013 4:09 am
Posts: 333
  • Start by disabling all interrupts.
  • Setup Buffer to 4096
  • For Each Item in Buffer set PacketInfo to 0 & Create Ethernet Frame and Put this pointer in buffer.
  • Create a loop that just checks for PacketInfo changing, displaying the hex values or break it down into the parts, DD etc...

Remember the NIC cannot use virtual memory locations.
Remember to set PacketInfo to 0 after it changes, as the NIC does not do this, also move the RDT.
After you have this working set up basic interrupts.
Set up interrupt throttling, test again using your loop and count the amount of PacketInfo's changed in one interrupt.
After you have basic interrupts going set up MSI-X.
When changing buffer size it must (mod 128 = 0)
Remember to ackowledge APIC interrupts.
There are other things to do, such as automatic interrupt clearing, etc..
The intel 82599 manuals are good, once you read them a couple of times.

Ali


Top
 Profile  
 
 Post subject: Re: Intel 8254x doesn't report received packets?
PostPosted: Sun Jul 09, 2017 6:29 am 
Offline
Member
Member

Joined: Sat Oct 16, 2010 3:38 pm
Posts: 587
Ugh, the thing where interrupts don't arrive and nothing can be sent or received still happens... very rarely.

It seems to happen almost always when I reboot the system via software, but resolves itself when I power off the VM completly then start it again.


Top
 Profile  
 
 Post subject: Re: Intel 8254x doesn't report received packets?
PostPosted: Sun Jul 09, 2017 5:36 pm 
Offline
Member
Member

Joined: Sun Jun 16, 2013 4:09 am
Posts: 333
mariuszp wrote:
Ugh, the thing where interrupts don't arrive and nothing can be sent or received still happens... very rarely.

It seems to happen almost always when I reboot the system via software, but resolves itself when I power off the VM completly then start it again.

Hi, more than likely it will be your code. Have you done it in a loop with interrupts off, sending and receiving millions of packets and testing each one?

Ali


Top
 Profile  
 
 Post subject: Re: Intel 8254x doesn't report received packets?
PostPosted: Wed Jul 12, 2017 4:37 pm 
Offline
Member
Member
User avatar

Joined: Thu Aug 06, 2015 6:41 am
Posts: 97
Location: Netherlands
I've just noticed that in your initialisation you don't set CTRL.ASDE and you don't clear CTRL.LRST after reseting the card, both of which are necessary for the card to automatically establish a link, and to my understanding you can't send or receive without them unless the card operates in internal PHY mode and the speed of the link happens to match the 1000Mb/s default of the card.
So at this point I'm almost suprised that most of the times you CAN send and receive... But I guess you happened to be lucky or I could have missed something.
Either way, I suggest you check out section 14.2 - 14.5 of the manual and compare the recommendations there side-by-side with your initialisation since the bug may very well be in there.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 69 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group