accessing the network card
Re: accessing the network card
OK found it in the dev guide for broadcom, we have to set command register to enable i/o or memory access
Thanks
Thanks
Re: accessing the network card
yep, that's what I mean with bit 0 and bit 1 of the command register.aloktiagi wrote:OK found it in the dev guide for broadcom, we have to set command register to enable i/o or memory access
Thanks
You should also note that, when trying to figure out the io base and memory base, you will first have to distinguish whether the address in BARn is the io base or memory base. In my OS, im looping through BAR0 - BAR5 and check the first bit of the BAR. If it is set to 1 its an io base, otherwise its a memory base.
It's actually described quite good in the wiki, but here's still a code snipped how I'm discovering the bases in my os:
Code: Select all
u32_t bar[6];
u32_t iobase, membase;
u8_t i;
/* I assume that all base address registers are stored in bar */
iobase = 0;
membase = 0;
for(i = 0; i < 6; i++) {
if(bar[i] & 0x1) {
/* bit 0 is set, hence its an io base */
if(!iobase) {
iobase = bar[i] & ~0x3;
}
} else {
/* bit 0 is clear; its a memory base */
if(!membase) {
membase = bar[i] & ~0xf;
}
}
}
Re: accessing the network card
Hi
I got the BAR0 as F8000004. So my memory base address is F8000000. So using this address can i now access NICs registers by adding offsets to this memory base address, for eg
I got the BAR0 as F8000004. So my memory base address is F8000000. So using this address can i now access NICs registers by adding offsets to this memory base address, for eg
Code: Select all
inb(F8000000+offset)
Re: accessing the network card
not quite.. you have to use the io base instead of the memory base
but aside of that its correct to use inb(iobase+offset)
but aside of that its correct to use inb(iobase+offset)
Re: accessing the network card
Hi,
Ok but i found only a memory base address i.e BAR[0] there was no other address in the other BAR registers. So where is the I/O base register value?
Ok but i found only a memory base address i.e BAR[0] there was no other address in the other BAR registers. So where is the I/O base register value?
Re: accessing the network card
oops, sorry I thought we're talking about a realtek nic here.
According to broadcom's specs, the registers are located in the memory address space (offset 0x400 - 0x8000 [see page 32 of the manual]), so membase+offset is correct.
According to broadcom's specs, the registers are located in the memory address space (offset 0x400 - 0x8000 [see page 32 of the manual]), so membase+offset is correct.
Re: accessing the network card
I got the BAR0 as F8000004. So my memory base address is F8000000.
Now when i do something like this
Here all that i get for register vlaues are FFFF and don't see any MAC addresses which should be present at offset ox410!!
Now when i do something like this
Code: Select all
add=0x410;
for (j = 0; j < 10; j++)
{
addr = F8000000;
reg_value = inl(addr+add);
printf("REG VALUE = %X \n",reg_value);
add = add + 0x04;
}
Re: accessing the network card
Doesn't this cause a compiler error?aloktiagi wrote:Code: Select all
addr = F8000000;
Try 0xf8000000 instead.
I've just had a look at the manual and the offset you're using isn't correct. According to the manual the device id registers are located at offset 0x2 (see page 152, NetXtreme II Programmer's Reference Guide)
Re: accessing the network card
@aloktiagi
You can't use IO instructions on memory. They're two completely independent address spaces; you just use a normal pointer at (membase + offset). So you can dereference it at whatever address you want, use memcpy or whatever to transfer buffers, etc. etc. That ease of use, along with the fact that memory accesses are faster and have a larger address space, is why you're unlikely to find IO ports used for non-legacy purposes.
You can't use IO instructions on memory. They're two completely independent address spaces; you just use a normal pointer at (membase + offset). So you can dereference it at whatever address you want, use memcpy or whatever to transfer buffers, etc. etc. That ease of use, along with the fact that memory accesses are faster and have a larger address space, is why you're unlikely to find IO ports used for non-legacy purposes.
Re: accessing the network card
@selenic
Yes thats what i thought,but then mkruk told using inb for memory addresses was ok .
So i'll use something like void *memcpy(void *dest, const void *src, size_t n); to transfer register data at F8000000
Yes thats what i thought,but then mkruk told using inb for memory addresses was ok .
So i'll use something like void *memcpy(void *dest, const void *src, size_t n); to transfer register data at F8000000
Re: accessing the network card
This is enough:aloktiagi wrote:@selenic
Yes thats what i thought,but then mkruk told using inb for memory addresses was ok .
So i'll use something like void *memcpy(void *dest, const void *src, size_t n); to transfer register data at F8000000
Code: Select all
char reg_value = *((char*)addr);
Re: accessing the network card
@eddyb
I used your method
But i'm getting a seg fault . Any idea why?
I used your method
So i should get the value of the register at 0xF8000000 in reg_value?char reg_value = *((char*)0xF8000000);
But i'm getting a seg fault . Any idea why?
Re: accessing the network card
Could someone comment on the previous post!!
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: accessing the network card
Of course nobody has a clue. The intel processor doesn't do segfaults. It's a unix thing.
So if I have to trust your description, you're trying to access hardware from an existing OS. Which is just stupid because the kernel won't allow it.
So if I have to trust your description, you're trying to access hardware from an existing OS. Which is just stupid because the kernel won't allow it.
Re: accessing the network card
And it is stupid to not have anticipated this from my previous posts