All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v3] Program net device MAC addresses after initializing
@ 2010-04-26  5:56 Ben Warren
  2010-04-26 10:09 ` Prafulla Wadaskar
  0 siblings, 1 reply; 4+ messages in thread
From: Ben Warren @ 2010-04-26  5:56 UTC (permalink / raw)
  To: u-boot

Add a new function to the eth_device struct for programming a network
controller's hardware address.

After all network devices have been initialized and the proper MAC address for
each has been determined, make a device driver call to program the address
into the device.  Only device instances with valid unicast addresses will be
programmed.

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Acked-by: Heiko Schocher <hs@denx.de>
Acked-by: Prafulla Wadaskar <prafulla@marvell.com>
Acked-by: Detlev Zundel <dzu@denx.de>
---
v2->v3 Made the sprintf in new function actually work :(
v1->v2 Add documentation & environment variable for overriding new behavior
ACKs mentioned above are for v1

 README                 |    5 +++++
 doc/README.drivers.eth |    7 ++++++-
 doc/README.enetaddr    |   10 ++++++----
 include/net.h          |    1 +
 net/eth.c              |   13 +++++++++++++
 5 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/README b/README
index cdd81d4..2f92bd2 100644
--- a/README
+++ b/README
@@ -3303,6 +3303,11 @@ o If both the SROM and the environment contain a MAC address, and the
 o If neither SROM nor the environment contain a MAC address, an error
   is raised.
 
+If Ethernet drivers implement the 'write_hwaddr' function, valid MAC addresses
+will be programmed into hardware as part of the initialization process.  This
+may be skipped by setting the appropriate 'ethmacskip' environment variable.
+The naming convention is as follows:
+"eth0macskip" (=>eth0), "eth1macskip" (=>eth1) etc.
 
 Image Formats:
 ==============
diff --git a/doc/README.drivers.eth b/doc/README.drivers.eth
index d0c3571..eb83038 100644
--- a/doc/README.drivers.eth
+++ b/doc/README.drivers.eth
@@ -70,6 +70,7 @@ int ape_register(bd_t *bis, int iobase)
 	dev->halt = ape_halt;
 	dev->send = ape_send;
 	dev->recv = ape_recv;
+	dev->write_hwaddr = ape_write_hwaddr;
 
 	eth_register(dev);
 
@@ -102,11 +103,12 @@ not checking its state or doing random probing.
  -----------
 
 Now that we've registered with the ethernet layer, we can start getting some
-real work done.  You will need four functions:
+real work done.  You will need five functions:
 	int ape_init(struct eth_device *dev, bd_t *bis);
 	int ape_send(struct eth_device *dev, volatile void *packet, int length);
 	int ape_recv(struct eth_device *dev);
 	int ape_halt(struct eth_device *dev);
+	int ape_write_hwaddr(struct eth_device *dev);
 
 The init function checks the hardware (probing/identifying) and gets it ready
 for send/recv operations.  You often do things here such as resetting the MAC
@@ -150,6 +152,9 @@ The halt function should turn off / disable the hardware and place it back in
 its reset state.  It can be called at any time (before any call to the related
 init function), so make sure it can handle this sort of thing.
 
+The write_hwaddr function should program the MAC address stored in dev->enetaddr
+into the Ethernet controller.
+
 So the call graph at this stage would look something like:
 some net operation (ping / tftp / whatever...)
 	eth_init()
diff --git a/doc/README.enetaddr b/doc/README.enetaddr
index 94d800a..53a0c25 100644
--- a/doc/README.enetaddr
+++ b/doc/README.enetaddr
@@ -33,11 +33,13 @@ Correct flow of setting up the MAC address (summarized):
 1. Read from hardware in initialize() function
 2. Read from environment in net/eth.c after initialize()
 3. Give priority to the value in the environment if a conflict
-4. Program hardware in the device's init() function.
+4. Program the address into hardware if the following conditions are met:
+	a) The relevant driver has a 'write_addr' function
+	b) The user hasn't set an 'eth%dmacskip' environment varialbe
+	c) The address is valid (unicast, not all-zeros)
 
-If somebody wants to subvert the design philosophy, this can be done
-in the board-specific board_eth_init() function by calling eth_init()
-after all the NICs have been registered.
+Previous behavior had the MAC address always being programmed into hardware
+in the device's init() function.
 
 -------
  Usage
diff --git a/include/net.h b/include/net.h
index 3f6a5d1..a180881 100644
--- a/include/net.h
+++ b/include/net.h
@@ -105,6 +105,7 @@ struct eth_device {
 #ifdef CONFIG_MCAST_TFTP
 	int (*mcast) (struct eth_device*, u32 ip, u8 set);
 #endif
+	int  (*write_hwaddr) (struct eth_device*);
 	struct eth_device *next;
 	void *priv;
 };
diff --git a/net/eth.c b/net/eth.c
index aff6987..1653ea9 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -60,6 +60,14 @@ int eth_getenv_enetaddr_by_index(int index, uchar *enetaddr)
 	return eth_getenv_enetaddr(enetvar, enetaddr);
 }
 
+static int eth_mac_skip(int index)
+{
+	char enetvar[15];
+	char *skip_state;
+	sprintf(enetvar, "eth%dmacskip", index);
+	return ((skip_state = getenv(enetvar)) != NULL);
+}
+ 
 #ifdef CONFIG_NET_MULTI
 
 /*
@@ -242,6 +250,11 @@ int eth_initialize(bd_t *bis)
 
 				memcpy(dev->enetaddr, env_enetaddr, 6);
 			}
+			if (dev->write_hwaddr &&
+				!eth_mac_skip(eth_number) &&
+				is_valid_ether_addr(dev->enetaddr)) {
+				dev->write_hwaddr(dev);
+			}
 
 			eth_number++;
 			dev = dev->next;
-- 
1.6.0.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH v3] Program net device MAC addresses after initializing
  2010-04-26  5:56 [U-Boot] [PATCH v3] Program net device MAC addresses after initializing Ben Warren
@ 2010-04-26 10:09 ` Prafulla Wadaskar
  2010-04-26 16:39   ` Ben Warren
  0 siblings, 1 reply; 4+ messages in thread
From: Prafulla Wadaskar @ 2010-04-26 10:09 UTC (permalink / raw)
  To: u-boot

 

> -----Original Message-----
> From: u-boot-bounces at lists.denx.de 
> [mailto:u-boot-bounces at lists.denx.de] On Behalf Of Ben Warren
> Sent: Monday, April 26, 2010 11:26 AM
> To: u-boot at lists.denx.de
> Cc: biggerbadderben at gmail.com
> Subject: [U-Boot] [PATCH v3] Program net device MAC addresses 
> after initializing
> 
> Add a new function to the eth_device struct for programming a network
> controller's hardware address.
> 
> After all network devices have been initialized and the 
> proper MAC address for
> each has been determined, make a device driver call to 
> program the address
> into the device.  Only device instances with valid unicast 
> addresses will be
> programmed.
> 
> Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
> Acked-by: Heiko Schocher <hs@denx.de>
> Acked-by: Prafulla Wadaskar <prafulla@marvell.com>
> Acked-by: Detlev Zundel <dzu@denx.de>
> ---
> v2->v3 Made the sprintf in new function actually work :(
> v1->v2 Add documentation & environment variable for 
> overriding new behavior
> ACKs mentioned above are for v1
> 
>  README                 |    5 +++++
>  doc/README.drivers.eth |    7 ++++++-
>  doc/README.enetaddr    |   10 ++++++----
>  include/net.h          |    1 +
>  net/eth.c              |   13 +++++++++++++
>  5 files changed, 31 insertions(+), 5 deletions(-)
> 
..snip..
> diff --git a/net/eth.c b/net/eth.c
> index aff6987..1653ea9 100644
> --- a/net/eth.c
> +++ b/net/eth.c
> @@ -60,6 +60,14 @@ int eth_getenv_enetaddr_by_index(int 
> index, uchar *enetaddr)
>  	return eth_getenv_enetaddr(enetvar, enetaddr);
>  }
>  
> +static int eth_mac_skip(int index)
> +{
> +	char enetvar[15];
> +	char *skip_state;
> +	sprintf(enetvar, "eth%dmacskip", index);
> +	return ((skip_state = getenv(enetvar)) != NULL);
> +}
> + 

Hi Ben
Pls remove the white space in the above line,
I have tested the patch on guruplug platform and found functional properly

Regards..
Prafulla . .

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH v3] Program net device MAC addresses after initializing
  2010-04-26 10:09 ` Prafulla Wadaskar
@ 2010-04-26 16:39   ` Ben Warren
  2010-04-27  1:34     ` Prafulla Wadaskar
  0 siblings, 1 reply; 4+ messages in thread
From: Ben Warren @ 2010-04-26 16:39 UTC (permalink / raw)
  To: u-boot

Hi Prafulla,

On 4/26/2010 3:09 AM, Prafulla Wadaskar wrote:
>
>
>    
>> -----Original Message-----
>> From: u-boot-bounces at lists.denx.de
>> [mailto:u-boot-bounces at lists.denx.de] On Behalf Of Ben Warren
>> Sent: Monday, April 26, 2010 11:26 AM
>> To: u-boot at lists.denx.de
>> Cc: biggerbadderben at gmail.com
>> Subject: [U-Boot] [PATCH v3] Program net device MAC addresses
>> after initializing
>>
>> Add a new function to the eth_device struct for programming a network
>> controller's hardware address.
>>
>> After all network devices have been initialized and the
>> proper MAC address for
>> each has been determined, make a device driver call to
>> program the address
>> into the device.  Only device instances with valid unicast
>> addresses will be
>> programmed.
>>
>> Signed-off-by: Ben Warren<biggerbadderben@gmail.com>
>> Acked-by: Heiko Schocher<hs@denx.de>
>> Acked-by: Prafulla Wadaskar<prafulla@marvell.com>
>> Acked-by: Detlev Zundel<dzu@denx.de>
>> ---
>> v2->v3 Made the sprintf in new function actually work :(
>> v1->v2 Add documentation&  environment variable for
>> overriding new behavior
>> ACKs mentioned above are for v1
>>
>>   README                 |    5 +++++
>>   doc/README.drivers.eth |    7 ++++++-
>>   doc/README.enetaddr    |   10 ++++++----
>>   include/net.h          |    1 +
>>   net/eth.c              |   13 +++++++++++++
>>   5 files changed, 31 insertions(+), 5 deletions(-)
>>
>>      
> ..snip..
>    
>> diff --git a/net/eth.c b/net/eth.c
>> index aff6987..1653ea9 100644
>> --- a/net/eth.c
>> +++ b/net/eth.c
>> @@ -60,6 +60,14 @@ int eth_getenv_enetaddr_by_index(int
>> index, uchar *enetaddr)
>>   	return eth_getenv_enetaddr(enetvar, enetaddr);
>>   }
>>
>> +static int eth_mac_skip(int index)
>> +{
>> +	char enetvar[15];
>> +	char *skip_state;
>> +	sprintf(enetvar, "eth%dmacskip", index);
>> +	return ((skip_state = getenv(enetvar)) != NULL);
>> +}
>> +
>>      
> Hi Ben
> Pls remove the white space in the above line,
> I have tested the patch on guruplug platform and found functional properly
>
>    
Will do.  I'll change your line to "Tested-by" if you don't mind.
> Regards..
> Prafulla . .
>    
Thanks a lot,
Ben

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH v3] Program net device MAC addresses after initializing
  2010-04-26 16:39   ` Ben Warren
@ 2010-04-27  1:34     ` Prafulla Wadaskar
  0 siblings, 0 replies; 4+ messages in thread
From: Prafulla Wadaskar @ 2010-04-27  1:34 UTC (permalink / raw)
  To: u-boot

 

> -----Original Message-----
> From: Ben Warren [mailto:biggerbadderben at gmail.com] 
> Sent: Monday, April 26, 2010 10:09 PM
> To: Prafulla Wadaskar
> Cc: u-boot at lists.denx.de
> Subject: Re: [U-Boot] [PATCH v3] Program net device MAC 
> addresses after initializing
> 
> Hi Prafulla,
> 
> On 4/26/2010 3:09 AM, Prafulla Wadaskar wrote:
> >
> >
> >    
> >> -----Original Message-----
> >> From: u-boot-bounces at lists.denx.de
> >> [mailto:u-boot-bounces at lists.denx.de] On Behalf Of Ben Warren
> >> Sent: Monday, April 26, 2010 11:26 AM
> >> To: u-boot at lists.denx.de
> >> Cc: biggerbadderben at gmail.com
> >> Subject: [U-Boot] [PATCH v3] Program net device MAC addresses
> >> after initializing
> >>
> >> Add a new function to the eth_device struct for 
> programming a network
> >> controller's hardware address.
> >>
> >> After all network devices have been initialized and the
> >> proper MAC address for
> >> each has been determined, make a device driver call to
> >> program the address
> >> into the device.  Only device instances with valid unicast
> >> addresses will be
> >> programmed.
> >>
> >> Signed-off-by: Ben Warren<biggerbadderben@gmail.com>
> >> Acked-by: Heiko Schocher<hs@denx.de>
> >> Acked-by: Prafulla Wadaskar<prafulla@marvell.com>
> >> Acked-by: Detlev Zundel<dzu@denx.de>
> >> ---
> >> v2->v3 Made the sprintf in new function actually work :(
> >> v1->v2 Add documentation&  environment variable for
> >> overriding new behavior
> >> ACKs mentioned above are for v1
> >>
> >>   README                 |    5 +++++
> >>   doc/README.drivers.eth |    7 ++++++-
> >>   doc/README.enetaddr    |   10 ++++++----
> >>   include/net.h          |    1 +
> >>   net/eth.c              |   13 +++++++++++++
> >>   5 files changed, 31 insertions(+), 5 deletions(-)
> >>
> >>      
> > ..snip..
> >    
> >> diff --git a/net/eth.c b/net/eth.c
> >> index aff6987..1653ea9 100644
> >> --- a/net/eth.c
> >> +++ b/net/eth.c
> >> @@ -60,6 +60,14 @@ int eth_getenv_enetaddr_by_index(int
> >> index, uchar *enetaddr)
> >>   	return eth_getenv_enetaddr(enetvar, enetaddr);
> >>   }
> >>
> >> +static int eth_mac_skip(int index)
> >> +{
> >> +	char enetvar[15];
> >> +	char *skip_state;
> >> +	sprintf(enetvar, "eth%dmacskip", index);
> >> +	return ((skip_state = getenv(enetvar)) != NULL);
> >> +}
> >> +
> >>      
> > Hi Ben
> > Pls remove the white space in the above line,
> > I have tested the patch on guruplug platform and found 
> functional properly
> >
> >    
> Will do.  I'll change your line to "Tested-by" if you don't mind.

Yes, you can..

Regards..
Prafulla . .

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-04-27  1:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-26  5:56 [U-Boot] [PATCH v3] Program net device MAC addresses after initializing Ben Warren
2010-04-26 10:09 ` Prafulla Wadaskar
2010-04-26 16:39   ` Ben Warren
2010-04-27  1:34     ` Prafulla Wadaskar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.