Page 1 of 1

RTL8139 MAC Address (using QEMU)

Posted: Sat Jul 24, 2010 5:01 am
by jasonc122
Hi,

I've an easy question for those that have got networking working using the RTL8139 on QEMU...

I'm trying to correctly read the MAC address for the RTL8139 network device using QEMU. I set the MAC using:

qemu ... -net nic, model=rtl8139, macaddr=52:54:00:12:34:56

However, I'm getting 0xFFFFFFFFFFFF as the MAC from my OS. What's going wrong here? I'm reading BAR0 from the PCI config to get the IO base address and then I'm reading the MAC i.e. inl(io_base + 0x00) and inw(io_base + 0x40).

I'm reading 0x3040 as the IO base from BAR0 which has value 0xc101.

Code: Select all

pci_device_t *pci_dev;
		u8int cmd;
		u8int interrupt_line;
		u32int MAC0;
		u16int MAC4;
		u32int work;

		pci_dev = _ki_load_pci_device(0x10ec,0x8139);
		if( pci_dev == 0)
		{
			ki_printf("couldn't load network pci device\n");
			return;
		}

		ki_printf_klog("BAR0 for RTL8139 device is 0x%x\n",pci_dev->config.reg4.bar0);

		io_base = (u16int)_ki_get_pci_io_bar(pci_dev->config.reg4.bar0);
		ki_printf_klog("IO base for RTL8139 device is 0x%x\n",io_base);

		interrupt_line = pci_dev->config.reg15.interrupt_line;
		ki_printf_klog("RTL8139 interrupt line nr is %d\n", interrupt_line);
	
		MAC0 = ki_inl(io_base + 0x00);
		MAC4 = ki_inw(io_base + 0x04);
		ki_printf_klog("RTL8139 MAC: 0x%x%x\n",MAC0,MAC4);
TIA

Re: RTL8139 MAC Address (using QEMU)

Posted: Sat Jul 24, 2010 7:28 am
by jasonc122
thanks to froggey and hindplayr this problems been solved.

The error was in my "_ki_get_pci_io_bar" routine which should have returned 0xc100 instead 0x3040.

Re: RTL8139 MAC Address (using QEMU)

Posted: Tue Jul 27, 2010 11:48 am
by IanSeyler
I made the same mistake. You clear the 2 lowest bits from the value in BAR0 to get the Base IO... not shifting right by 2.

Code: Select all

os_net_rtl8139_probe_found:            ; Supported device was found. Get the Base IO
    mov cl, 0x04                ; BAR0
    call os_pci_read_reg
    and eax, 0xFFFFFFFC            ; EAX now holds the Base IO Address (clear the low 2 bits)
    mov word [os_NetIOAddress], ax