[U-Boot] [PATCH] mgcoge make ether_scc.c work with CONFIG_NET_MULTI

Ben Warren biggerbadderben at gmail.com
Mon Nov 10 07:09:30 CET 2008


Hi Gary,

Gary Jennejohn wrote:
> This change is needed for mgcoge because it uses two ethernet drivers.
>
>   
I like the idea of moving drivers to use CONFIG_NET_MULTI, particularly 
so that we can get rid of it as an option...  There are a few more 
things you need to think about, though.
> Add a check for the presence of the PIGGY board on mgcoge.  Without this
> board networking cannot work and the initialization must be aborted.
>
> Only allocate rtx once to prevent DPRAM exhaustion.
>
> Initialize ether_scc.c and the keymile-specific HDLC driver (to be added
> soon) in eth.c.
>
> Signed-off-by: Gary Jennejohn <garyj at denx.de>
> ---
>
> I ran "MAKEALL ppc" and no errors were caused by this patch.
>
>  cpu/mpc8260/ether_scc.c |   56 +++++++++++++++++++++++++++++++++++++++++------
>  net/eth.c               |    8 ++++++
>  2 files changed, 57 insertions(+), 7 deletions(-)
>
> diff --git a/cpu/mpc8260/ether_scc.c b/cpu/mpc8260/ether_scc.c
> index c65f0e0..537cd39 100644
> --- a/cpu/mpc8260/ether_scc.c
> +++ b/cpu/mpc8260/ether_scc.c
> @@ -10,6 +10,12 @@
>   * Advent Networks, Inc. <http://www.adventnetworks.com>
>   * Jay Monkman <jtm at smoothsmoothie.com>
>   *
> + * Modified so that it plays nicely when more than one ETHERNET interface
> + * is in use a la ether_fcc.c.
> + * (C) Copyright 2008
> + * DENX Software Engineerin GmbH
> + * Gary Jennejohn <garyj at denx.de>
> + *
>   * See file CREDITS for list of people who contributed to this
>   * project.
>   *
> @@ -32,12 +38,17 @@
>  #include <common.h>
>  #include <asm/cpm_8260.h>
>  #include <mpc8260.h>
> +#include <malloc.h>
>  #include <net.h>
>  #include <command.h>
>  #include <config.h>
>  
>  #if defined(CONFIG_ETHER_ON_SCC) && defined(CONFIG_CMD_NET)
>   
While you're mucking around with this file, please settle on a single 
CONFIG that can allow conditional compilation from the Makefile, then 
get rid of this stuff.
>  
> +#ifndef CONFIG_NET_MULTI
> +#error "CONFIG_NET_MULTI must be defined."
> +#endif
> +
>  #if (CONFIG_ETHER_INDEX == 1)
>  #  define PROFF_ENET            PROFF_SCC1
>  #  define CPM_CR_ENET_PAGE      CPM_CR_SCC1_PAGE
> @@ -100,7 +111,7 @@ typedef volatile struct CommonBufferDescriptor {
>  static RTXBD *rtx;
>  
>  
> -int eth_send(volatile void *packet, int length)
> +int sec_send(struct eth_device *dev, volatile void *packet, int length)
>   
Please give all these functions, except initialize(), file scope (i.e. 
make them static).  I'm not crazy about the name 'sec', but if it's 
static the objection doesn't carry much weight.  I also can't think of a 
better name.
>  {
>      int i;
>      int result = 0;
> @@ -137,7 +148,7 @@ int eth_send(volatile void *packet, int length)
>  }
>  
>  
> -int eth_rx(void)
> +int sec_rx(struct eth_device *dev)
>  {
>      int length;
>  
> @@ -184,19 +195,32 @@ int eth_rx(void)
>   *
>   *************************************************************/
>  
> -int eth_init(bd_t *bis)
> +int sec_init(struct eth_device *dev, bd_t *bis)
>  {
>      int i;
>      volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
>      scc_enet_t *pram_ptr;
>      uint dpaddr;
>  
> +#if defined(CONFIG_CHECK_ETHERNET_PRESENT)
> +	if (ethernet_present (CONFIG_ETHER_INDEX) == 0) {
> +		printf("Ethernet index: %d not present.\n",
> +		       CONFIG_ETHER_INDEX);
> +		return -1;
> +	}
> +#endif
> +
>      rxIdx = 0;
>      txIdx = 0;
>  
> -    /* assign static pointer to BD area */
> -    dpaddr = m8260_cpm_dpalloc(sizeof(RTXBD) + 2, 16);
> -    rtx = (RTXBD *)&immr->im_dprambase[dpaddr];
> +    /*
> +     * Assign static pointer to BD area.
> +     * Avoid exhausting DPRAM, which would cause a panic.
> +     */
> +    if (rtx == NULL) {
> +	    dpaddr = m8260_cpm_dpalloc(sizeof(RTXBD) + 2, 16);
> +	    rtx = (RTXBD *)&immr->im_dprambase[dpaddr];
> +    }
>  
>      /* 24.21 - (1-3): ioports have been set up already */
>  
> @@ -338,7 +362,7 @@ int eth_init(bd_t *bis)
>  }
>  
>  
> -void eth_halt(void)
> +void sec_halt(struct eth_device *dev)
>  {
>      volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
>      immr->im_scc[CONFIG_ETHER_INDEX-1].scc_gsmrl &= ~(SCC_GSMRL_ENR |
> @@ -354,4 +378,22 @@ void restart(void)
>  }
>  #endif
>  
> +int sec_initialize(bd_t *bis)
>   
For this function with global namespace, please pick a more descriptive 
name.  Maybe 82xx_scc_initialize() or something?
> +{
> +	struct eth_device *dev;
> +
> +	dev = (struct eth_device *) malloc(sizeof *dev);
> +	memset(dev, 0, sizeof *dev);
> +
> +	sprintf(dev->name, "SCC ETHERNET");
> +	dev->init   = sec_init;
> +	dev->halt   = sec_halt;
> +	dev->send   = sec_send;
> +	dev->recv   = sec_rx;
> +
> +	eth_register(dev);
> +
> +	return 1;
> +}
> +
>  #endif
> diff --git a/net/eth.c b/net/eth.c
> index ccd871a..5fe8b83 100644
> --- a/net/eth.c
> +++ b/net/eth.c
> @@ -48,6 +48,8 @@ extern int ppc_4xx_eth_initialize(bd_t *);
>  extern int scc_initialize(bd_t*);
>  extern int npe_initialize(bd_t *);
>  extern int uec_initialize(int);
> +extern int sec_initialize(bd_t *);
> +extern int keymile_hdlc_enet_initialize(bd_t *);
>  
>  #ifdef CONFIG_API
>  extern void (*push_packet)(volatile void *, int);
> @@ -196,6 +198,12 @@ int eth_initialize(bd_t *bis)
>  #if defined(CONFIG_IXP4XX_NPE)
>  	npe_initialize(bis);
>  #endif
> +#if defined(CONFIG_ETHER_ON_SCC) && defined(CONFIG_MPC8260)
> +	sec_initialize(bis);
> +#endif
> +#if defined(CONFIG_KEYMILE_HDLC_ENET)
> +	keymile_hdlc_enet_initialize(bis);
> +#endif
>  	if (!eth_devices) {
>  		puts ("No ethernet found.\n");
>  		show_boot_progress (-64);
>   
Please don't add anything to this file.  All initializations now go in 
cpu_eth_init()/board_eth_init().  There are plenty of examples you can 
draw from.  Don't forget to add your initializer function to 
include/netdev.h

You get bonus points if you move this driver to drivers/net

regards,
Ben



More information about the U-Boot mailing list