Page 1 of 1

How to make sure rtl8139 is connected to the PIC in QEMU

Posted: Thu Apr 03, 2014 2:43 pm
by kemosparc
Hi,

I am writing a driver for rtl8139 network card for my os.

I cannot get the card to fire interrupts.

My question is how to make sure that the card is connected to PIC and if it is not how to connect it.

I am using qemu.

Thanks
Karim.

Re: How to make sure rtl8139 is connected to the PIC in QEMU

Posted: Fri Apr 04, 2014 9:55 am
by Jezze
The irq number is found in the pci configuration space. If you dont recieve interrupts make sure that number is not masked in your pic code.

Re: How to make sure rtl8139 is connected to the PIC in QEMU

Posted: Fri Apr 04, 2014 11:14 am
by kemosparc
Yes,

I can read it from the pci configuration space.

It is IRQ Line 11 and and IRQ Pin 1.

I make sure to clear the mask through calling this function with the IRQ Number:

Code: Select all

void IRQ_clear_mask(unsigned char IRQline) {
    uint16_t port;
    uint8_t value;

    if(IRQline < 8) {
        port = PIC1_DATA;
    } else {
        port = PIC2_DATA;
        IRQline -= 8;
    }
    value = Ports::inportb(port) & ~(1 << IRQline);
    Ports::outportb(port, value);
}
Is that what you mean?

Thanks,
Karim.

Re: How to make sure rtl8139 is connected to the PIC in QEMU

Posted: Fri Apr 04, 2014 11:47 am
by kemosparc
Hi,

Okay, what I have done is that I have compiled qemu with debug info and I have enabled debug inside the rtl8139.c file to see what is going on.


My packets get received by the card and it is copied to the rx buffer, and when I inspected the IntrMask and the IntrStatus of the device I found that their values are:

IntrMask: c07f
IntrStatus: 0001

The documentation at http://wiki.osdev.org/PCI says that bit 3 of the IntrStatus should be set for the interrupt to get fired. I don't know what is the reason for IntrStatus not to be set correctly, and when it should be set?


Any suggestions?

Thanks
Karim

Re: How to make sure rtl8139 is connected to the PIC in QEMU

Posted: Fri Apr 04, 2014 2:09 pm
by bwat
What interrupt mask and interrupt status registers are you talking about? In my Realtek 8139 driver I had the following:

Code: Select all

#define RL_ISR		0x003E		/* interrupt status register */

#define RL_ISR_RX_OK		0x0001
#define RL_ISR_RX_ERR		0x0002
You should be getting 1 on a good RX. I checked my mask and it gets programmed to 0xc07f, so I think you've received OK. My interrupt is 5 on the PIC.

Re: How to make sure rtl8139 is connected to the PIC in QEMU

Posted: Fri Apr 04, 2014 2:49 pm
by kemosparc
I am talking about the IntrStatus and the IntrMask of the qemu.

The debug mode prints them on every packet receival

Thanks
Karim

Re: How to make sure rtl8139 is connected to the PIC in QEMU

Posted: Fri Apr 04, 2014 2:52 pm
by kemosparc
So Why do you think the interrupt does not fire?

Although PIT and the Keyboard fire their interrupts?

I have been working in this for the past 5 days, and I have traced the qemu as much as I can and I cannot know why the interrupt does not fire.

Any suggestions ?
Thanks
Karim

Re: How to make sure rtl8139 is connected to the PIC in QEMU

Posted: Fri Apr 04, 2014 3:10 pm
by bwat
kemosparc wrote:I have been working in this for the past 5 days, and I have traced the qemu as much as I can and I cannot know why the interrupt does not fire.
1) Five days is nothing!
2) I've never seen the source code for qemu but there's no doubt in my mind that if you stepped through the code you would eventually figure out why you weren't getting an interrupt. It's just a question of how badly you want to solve the problem.

Re: How to make sure rtl8139 is connected to the PIC in QEMU

Posted: Sat Apr 05, 2014 12:51 pm
by kemosparc
I am kind of confused,

How to know if the hardware is configured with PIC or APIC?

Basically, the qemu fires the interrupt once, but it never reaches my handler hub, and it never fires again!!

Any help?
Thanks
Karim

Re: How to make sure rtl8139 is connected to the PIC in QEMU

Posted: Sat Apr 05, 2014 12:54 pm
by kemosparc
Another question,

Is there any special consisderation of my kernel runs in 64-bit Long mode?

Thanks
Karim

[SOLVED]How to make sure rtl8139 is connected to the PIC in

Posted: Sun Apr 06, 2014 4:38 pm
by kemosparc
Okay,

Finally I discovered my problem.

The IRQ for the network card is IRQ 11 which is on PIC 2.

So I had to enable IRQ2 (unmask it) as it cascades the interrupts on PIC2.

Now the interrupt fires

Thanks
Karim..