Storing MAC address in the system page

bridged with qnx.rtos
Post Reply
Jacek Rudnicki

Storing MAC address in the system page

Post by Jacek Rudnicki » Thu Jun 28, 2007 7:07 am

Hi,

I would like to write MAC address to the system page
and this must be done when the system (procnto) is running.

Is it possible ?

Regards,
Jacek

David Gibbs

Re: Storing MAC address in the system page

Post by David Gibbs » Thu Jul 05, 2007 5:08 pm

Jacek Rudnicki <jacek.rudnicki@quantum.com.pl> wrote:
Hi,

I would like to write MAC address to the system page
and this must be done when the system (procnto) is running.
Why the system page? After proc is running, couldn't you use
a shared memory object or something for sharing that information?
Is it possible ?
Ugly, but probably doable.

You'd need to make sure there was space reserved in the system
page for this -- probably customize startup to allocate some
space for this.

Then, in the process that needs to change this -- get the physical
address of the system page, map this in with write privilege, then
change the contents of that location.

-David Gibbs
--
David Gibbs
QNX Training Services
dagibbs@qnx.com

Jacek Rudnicki

Re: Storing MAC address in the system page

Post by Jacek Rudnicki » Fri Jul 06, 2007 11:45 am

Why the system page? After proc is running, couldn't you use
a shared memory object or something for sharing that information?
Because driver looks into this area and automatically takes a right data.
Ugly, but probably doable.

You'd need to make sure there was space reserved in the system
page for this -- probably customize startup to allocate some
space for this.
Do you have any example which reserves that space ?
Then, in the process that needs to change this -- get the physical
address of the system page, map this in with write privilege, then
change the contents of that location.
Jacek

Andrew_Boyd

RE: Re: Storing MAC address in the system page

Post by Andrew_Boyd » Fri Jul 06, 2007 1:49 pm

Why not just use the "mac=XXX" command line option to the
driver?

David Gibbs

Re: Storing MAC address in the system page

Post by David Gibbs » Fri Jul 06, 2007 7:57 pm

Jacek Rudnicki <jacek.rudnicki@quantum.com.pl> wrote:
Why the system page? After proc is running, couldn't you use
a shared memory object or something for sharing that information?

Because driver looks into this area and automatically takes a right data.
I guessed that, having read a thread you posted elsewhere, but read it
after this thread.
Ugly, but probably doable.

You'd need to make sure there was space reserved in the system
page for this -- probably customize startup to allocate some
space for this.

Do you have any example which reserves that space ?
Nope, I don't. The startup library function add_typed_string comes to mind,
though.

-David
--
David Gibbs
QNX Training Services
dagibbs@qnx.com

Jacek Rudnicki

Re: Storing MAC address in the system page

Post by Jacek Rudnicki » Mon Jul 09, 2007 1:38 pm

Nope, I don't. The startup library function add_typed_string comes to
mind,
though.
I'm not sure if this will work.

There are two functions:
hwi_add_device();
hwi_add_nicaddr();
but not documented very well.

How to use them and how to check (after system start)
that the system page was updated ?

Does startup code (started in verbose mode)
print any info about MAC address ?
If yes, where ?

Jacek

Jacek Rudnicki

Re: Re: Storing MAC address in the system page

Post by Jacek Rudnicki » Mon Jul 09, 2007 1:59 pm

Why not just use the "mac=XXX" command line option to the
driver?
I need to do that in buildfile. So, I call "start_net" macro.

[+script] .script = {
....
start_net
....
}

....

[gid=0 uid=0 perms=777] /bin/start_net = {
#!/bin/sh

MACADDR=`printmac`

io-net -dcrys8900 mac=$MACADDR ...
}

This macro requires shell and it must be
a "ksh" binary ([type=link] /bin/sh = /bin/ksh).

For example fesh is not able to pass output
from 'printmac' to environment variable.

In fact in the target device there will not be
any shell executable file.

Unfortunately doing similar job inside startup
script doesn't work:

[+script] .script = {
....
MACADDR=`printmac`

io-net -dcrys8900 mac=$MACADDR ...
....
}

Jacek

Colin Burgess

Re: Storing MAC address in the system page

Post by Colin Burgess » Mon Jul 09, 2007 2:12 pm

You can't use those functions after startup has run.

Why can't you change startup to check this information?

Jacek Rudnicki wrote:
Nope, I don't. The startup library function add_typed_string comes to
mind,
though.

I'm not sure if this will work.

There are two functions:
hwi_add_device();
hwi_add_nicaddr();
but not documented very well.

How to use them and how to check (after system start)
that the system page was updated ?

Does startup code (started in verbose mode)
print any info about MAC address ?
If yes, where ?

Jacek

--
cburgess@qnx.com

Colin Burgess

Re: Storing MAC address in the system page

Post by Colin Burgess » Mon Jul 09, 2007 2:13 pm

Why not write a tiny little util that reads the mac and then spawns io-net with the appropriate arguments?

Jacek Rudnicki wrote:
Why not just use the "mac=XXX" command line option to the
driver?

I need to do that in buildfile. So, I call "start_net" macro.

[+script] .script = {
...
start_net
...
}

...

[gid=0 uid=0 perms=777] /bin/start_net = {
#!/bin/sh

MACADDR=`printmac`

io-net -dcrys8900 mac=$MACADDR ...
}

This macro requires shell and it must be
a "ksh" binary ([type=link] /bin/sh = /bin/ksh).

For example fesh is not able to pass output
from 'printmac' to environment variable.

In fact in the target device there will not be
any shell executable file.

Unfortunately doing similar job inside startup
script doesn't work:

[+script] .script = {
...
MACADDR=`printmac`

io-net -dcrys8900 mac=$MACADDR ...
...
}

Jacek

--
cburgess@qnx.com

Jacek Rudnicki

Re: Storing MAC address in the system page

Post by Jacek Rudnicki » Tue Jul 10, 2007 6:53 am

You can't use those functions after startup has run.
I would like to use them in startup code just for reserving
space for the default MAC address.

But I don't know how.
Why can't you change startup to check this information?
I don't have a direct access to source code. Startup is
managed by the separate company. I will ask them if they
are able to reserve some memory for the MAC info

Jacek

Jacek Rudnicki

Re: Storing MAC address in the system page

Post by Jacek Rudnicki » Tue Jul 10, 2007 7:00 am

Why not write a tiny little util that reads the mac and then spawns io-net
with the appropriate arguments?
Nice solution. I will test it soon...

Overwriting MAC address, starting io-net as usual is more user friendly.

Jacek

Robert Craig

Re: Storing MAC address in the system page

Post by Robert Craig » Wed Jul 11, 2007 3:03 pm

Here's some example code of how to set up the system page with NIC
information in startup...


static void add_one_tsec(unsigned off,
unsigned intr_tx,
unsigned int intr_rx,
unsigned int intr_err,
unsigned char *mac)
{
paddr_t paddr = immr_paddr + off;

hwi_add_device(HWI_ITEM_BUS_UNKNOWN, HWI_ITEM_DEVCLASS_NETWORK, "tsec", 0);

hwi_add_location(paddr, 8, 0, hwi_find_as(paddr, 0));

hwi_add_irq(intr_tx);
hwi_add_irq(intr_rx);
hwi_add_irq(intr_err);

if (mac != NULL) {
hwi_add_nicaddr(mac, 6);
}

}

Adds a device identifier, register location information, interrupts and
a MAC.

Here's the corresponding code in the driver:

static inline unsigned
ppc8xxx_get_syspage_params(struct tsec_params *tsec, unsigned last)
{
hwi_tag *tag;
int irqnum = 0;
unsigned off;
unsigned item;
char *name;

/* Find network hardware information. */
item = hwi_find_item(last, HWI_ITEM_DEVCLASS_NETWORK, "tsec", NULL);

if (item == HWI_NULL_OFF) {
return(item);
}

off = item;
tsec->paddr = 0;
tsec->irq_present = 0;
tsec->mac_present = 0;
tsec->phy_present = 0;

while((off = hwi_next_tag(off, 1)) != HWI_NULL_OFF) {
tag = hwi_off2tag(off);
name = __hwi_find_string(((hwi_tag *)tag)->prefix.name);

if(strcmp(name, HWI_TAG_NAME_location) == 0) {
tsec->paddr = (paddr_t)tag->location.base;
} else if(strcmp(name, HWI_TAG_NAME_irq) == 0) {
switch (irqnum) {
case 0:
tsec->irq_tx = tag->irq.vector;
break;
case 1:
tsec->irq_rx = tag->irq.vector;
break;
case 2:
tsec->irq_err = tag->irq.vector;
break;
default:
break;
}
irqnum++;
} else if (strcmp(name, HWI_TAG_NAME_nicaddr) == 0) {
if (tag->nicaddr.len == 6) {
memcpy(tsec->mac, tag->nicaddr.addr, 6);
tsec->mac_present = 1;
}
} else if (strcmp(name, HWI_TAG_NAME_nicphyaddr) == 0) {
tsec->phy_addr = tag->nicphyaddr.addr;
tsec->phy_present = 1;
}
}

if (irqnum == 3) {
tsec->irq_present = 1;
}

return(item);
}


And to use the function...

config_offset = ppc8xxx_get_syspage_params(&tsec, config_offset);

if (config_offset == HWI_NULL_OFF) {
nic_slogf (_SLOGC_NETWORK, _SLOG_ERROR,
"devn-xxxx: No syspage hardware configuration information found");
return(ENODEV);
}

while (config_offset != HWI_NULL_OFF) {
(Ad the device)
}


Hope this helps

Robert.

Jacek Rudnicki wrote:
You can't use those functions after startup has run.

I would like to use them in startup code just for reserving
space for the default MAC address.

But I don't know how.

Why can't you change startup to check this information?

I don't have a direct access to source code. Startup is
managed by the separate company. I will ask them if they
are able to reserve some memory for the MAC info

Jacek

Robert Craig

Re: Storing MAC address in the system page

Post by Robert Craig » Wed Jul 11, 2007 4:08 pm

And to use the function...
Oops! Forgot the initialization line...

unsigned config_offset = HWI_NULL_OFF;

config_offset = ppc8xxx_get_syspage_params(&tsec, config_offset);

if (config_offset == HWI_NULL_OFF) {
nic_slogf (_SLOGC_NETWORK, _SLOG_ERROR,
"devn-xxxx: No syspage hardware configuration information found");
return(ENODEV);
}

while (config_offset != HWI_NULL_OFF) {
(Ad the device)
}


Hope this helps

Robert.

Jacek Rudnicki wrote:
You can't use those functions after startup has run.

I would like to use them in startup code just for reserving
space for the default MAC address.

But I don't know how.

Why can't you change startup to check this information?

I don't have a direct access to source code. Startup is
managed by the separate company. I will ask them if they
are able to reserve some memory for the MAC info

Jacek

Post Reply

Return to “qnx.rtos”