[U-Boot] [PATCH 01/27 v2] Blackfin: bfin_mac: force board_get_enetaddr() usage
Mike Frysinger
vapier at gentoo.org
Mon Feb 2 21:05:16 CET 2009
On Thursday 29 January 2009 20:23:06 Mike Frysinger wrote:
> at any rate, i'm fine with having the driver assume bi_enetaddr is sane.
> so the series of patches i just posted starts unifying the things i whined
> about earlier and does what you suggested.
>
> unfortunately, with this small review i noticed another layer of confusion
> ;). every ethernet device is represented as struct eth_device, and that
> device has an enetaddr member. the board makes sure ethaddr is set in the
> environment during misc init. then when the network is actually used, the
> eth layer calls the board init which calls the driver init which registers
> a new eth_device. then the eth layer sets up dev->enetaddr based on the
> appropriate ethaddr env var. so imo, no eth driver should be touching the
> global data (and thus the bi_enetaddr's contained in there).
>
> going back a step, i dont think the board itself should be touching the
> global bi_enetaddr. when the board sets the ethaddr env var, the common
> code in cmd_nvedit.c syncs the value to the global data.
>
> if i were to document this mess, where would be the best place ? start a
> new doc/README.enetaddr as i dont see any document that covers the eth
> layer ? that way in the future we can all easily agree on how things should
> be done.
how about this document at doc/README.enetaddr ...
-mike
---------------------------------
Ethernet Address (MAC) Handling
---------------------------------
There are a variety of places in U-Boot where the MAC address is used, parse,
and stored. This document covers proper usage of each location and the moving
of data between them.
-----------
Locations
-----------
Here are the places where MAC addresses are stored:
- board-specific location (eeprom, dedicated flash, ...)
- environment ("ethaddr", "eth1addr", ...)
- global data (bi_enetaddr, bi_enet1addr, ...)
- ethernet data (struct eth_device -> enetaddr)
-------
Usage
-------
During board init (like the board-specific misc_init_r() function), boards
should take care of locating the MAC address, initializing the environment,
and seeding the global data.
During runtime, the ethernet layer will use the environment variables to sync
the MAC addresses to the ethernet structures. All ethernet driver code should
then only use the enetaddr member of the eth_device structure.
The common environment code will take care of passing environment changes to
the global data and to the ethernet layer.
Any other common code that wishes to access the MAC address should then query
the global data directly. No one should be looking in the environment for any
addresses.
---------
Helpers
---------
To assist in the management of these layers, a few helper functions exist. You
should use these rather than attempt to do any kind of parsing/manipulation
yourself as many common errors have arisen in the past.
* void eth_parse_enetaddr(char *addr, uchar *enetaddr);
Convert a string representation of a MAC address to the binary version.
char *addr = "00:11:22:33:44:55";
uchar enetaddr[6];
eth_parse_enetaddr(addr, enetaddr);
/* enetaddr now equals { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 } */
* bool eth_getenv_enetaddr(char *name, uchar *enetaddr);
Look up an environment variable and convert the stored address. If the env var
is not set, then the function returns false. Otherwise, the conversion occurs
and returns true.
uchar enetaddr[6];
if (eth_getenv_enetaddr("ethaddr", enetaddr))
/* enetaddr is now set to the value stored in the ethaddr env var */
else
/* "ethaddr" is not set in the environment */
* int eth_setenv_enetaddr(char *name, uchar *enetaddr);
Store the MAC address into the named environment variable. The return value is
the same as the setenv() function.
uchar enetaddr[6] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 };
eth_setenv_enetaddr("ethaddr", enetaddr);
/* the "ethaddr" env var should now be set to "00:11:22:33:44:55" */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090202/4b98a04d/attachment.pgp
More information about the U-Boot
mailing list