Page 1 of 1

ne2000 receive

Posted: Thu Jun 30, 2011 11:12 am
by lama
Hello, so once again i'm stuck with my networking. I have decided to write driver for Ne2k because both Bochs and Qemu supports it.
Sending a packet works fine, i'm able to transmit a packet and that very packet can then be properly received by other machine.
The thing is, that when i try to receive this packet using my system (picture two Qemu connected together, both running my system) i get strange data. There must be something wrong with the routine that handles DMA receiving, because that received data does not match the original ones (data that has been sent) at all.
There is this snippet of code that does DMA read, this routine is called when there is a packet waiting and irq is fired - that isr will call this routine.

Code: Select all

; in cx is size to be read
; in edi is location where to put data
mov al, CR_PS1 ; bank 1
mov edx, dword [BASE]
out dx, al
add dx, 7	; CURR PAGE REGISTER
in ax, dx
push ax
mov al, CR_PS0 ; bank 0
mov edx, dword [BASE]
out dx, al
inc cx
and cx, 0fffeh
mov edx, dword [BASE]
add dx, RBCR0
mov al, cl
out dx, al
mov edx, dword [BASE]
add dx, RBCR1
mov al, ch
out dx, al
pop ax      ; Get our page back
mov edx, dword [BASE]
add dx, RSAR0
out dx, al
mov edx, dword [BASE]
add dx, RSAR1
mov al, ah
out dx, al
mov edx, dword [BASE]
mov al, 0ah               ; Read and start ( bank 0, read, sta)
out dx, al
add dx, ASIC ; (io)
shr cx, 1
push es
mov ax, 0x10
mov es, ax
iter:
in  ax, dx
stosw
loop iter
pop es
ret
Thanks for any ideas.

Re: ne2000 receive

Posted: Fri Jul 01, 2011 2:41 pm
by lama
So, can anyone please tell me the exact sequence of receiving packet? I have read the entire datasheet and some other stuff, but things are not getting clearer..
From my point of view (and please correct me if i'm wrong, and i surely am), this is a procedure that i should follow:

1. Wait for IRQ to fire and make sure that this is the case of PRX interrupt.
2. Initialize DMA by inputing size to RBCR counter registers, then program RSAR registers to point at correct place in NE2k ring buffer.
This page address i can obtain by reading the register 7 in bank 1 containing current page of ring buffer (CURR).
3. When ready, issue a DMA read command and read that data from netcard's data port.
4. Reset PIC and netcard's ISR
Correct?

After each successful DMA read is RBCR decremented, RSAR incremented and when end of page (in that ring buffer) is reached, then CURR is set to the following page that contains additional data. Correct?

The proper size and next page pointer can also be obtained from NIC header, which should be stored at very beginning of each page (second byte is that pointer, following word is size). Correct?

And above all, the entire packet is received in one go? I mean , at first the netcard receives entire packet and then signals IRQ? So there is only one interrupt per one packet, right?

Feel free to correct the mistakes i have made.

Re: ne2000 receive

Posted: Thu Jul 07, 2011 1:45 pm
by lama
Netcard's command for auto DMA transfers (Send Packet, RD2,RD1,RD0 set to 011) which should automatically load RBCR and RSAR with proper values and issue DMA read, does not work for me too. According to datasheet i should keep sending this command until Boundary Register is equal to Current Page Register. Sadly, this command produces same results as manual receive - trash is being received.
Advice?

Re: ne2000 receive

Posted: Fri Jul 08, 2011 10:40 am
by bifferos
I don't have an answer to your question, but feel free to copy/look at my ne2000 driver:
http://sites.google.com/site/bifferboar ... loppy-disk

It was written solely for the purpose of developing networking stacks under Qemu. The ne2000 hardware is the easiest to write a driver for, but most implementations currently 'complicate' things by including support for PCI, interrupts etc.... This driver only includes the bare minimum. Perhaps you'll find it useful, and yes, I also got the tx working some while before the rx!

regards,
Biff.

Re: ne2000 receive

Posted: Fri Jul 08, 2011 11:32 am
by IanSeyler
I can't offer any advice on the NE2000 but the Intel 8254X can be used as a network device under QEMU, VirtualBox, and VMware (though not in Bochs).

It looks like you are writing in Assembly so this would be of use to you if you wanted to go that route: http://code.google.com/p/baremetal/sour ... i8254x.asm

-Ian