All of lore.kernel.org
 help / color / mirror / Atom feed
From: gerg@snapgear.com (Greg Ungerer)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 03/10] net/fec: add mac field into platform data and consolidate fec_get_mac
Date: Wed, 29 Dec 2010 15:29:01 +1000	[thread overview]
Message-ID: <4D1AC71D.9020305@snapgear.com> (raw)
In-Reply-To: <1293548155-16328-4-git-send-email-shawn.guo@freescale.com>

Hi Shawn,

On 29/12/10 00:55, Shawn Guo wrote:
> Add mac field into fec_platform_data and consolidate function
> fec_get_mac to get mac address in following order.
>
>   1) kernel command line fec_mac=xx:xx:xx...
>   2) from flash in case of CONFIG_M5272 or fec_platform_data mac
>      field for others, which typically have mac stored in fuse

Looking at this we can move that 5272 specific code into its
arch code with these changes. I can do that later if you don't
want to do it in this series.

Regards
Greg


>   3) fec mac address registers set by bootloader
>
> Signed-off-by: Shawn Guo<shawn.guo@freescale.com>
> ---
>   drivers/net/fec.c   |   90 ++++++++++++++++++++++++++++----------------------
>   include/linux/fec.h |    2 +
>   2 files changed, 52 insertions(+), 40 deletions(-)
>
> diff --git a/drivers/net/fec.c b/drivers/net/fec.c
> index 47f6b3b..cd59814 100644
> --- a/drivers/net/fec.c
> +++ b/drivers/net/fec.c
> @@ -59,15 +59,9 @@
>   #define FEC_ALIGNMENT	0x3
>   #endif
>
> -/*
> - * Define the fixed address of the FEC hardware.
> - */
> -#if defined(CONFIG_M5272)
> -
> -static unsigned char	fec_mac_default[] = {
> -	0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> -};
> +static unsigned char fec_mac_default[ETH_ALEN];
>
> +#if defined(CONFIG_M5272)
>   /*
>    * Some hardware gets it MAC address out of local flash memory.
>    * if this is non-zero then assume it is the address to get MAC from.
> @@ -537,27 +531,40 @@ rx_processing_done:
>   }
>
>   /* ------------------------------------------------------------------------- */
> -#ifdef CONFIG_M5272
>   static void __inline__ fec_get_mac(struct net_device *dev)
>   {
>   	struct fec_enet_private *fep = netdev_priv(dev);
> +	struct fec_platform_data *pdata = fep->pdev->dev.platform_data;
>   	unsigned char *iap, tmpaddr[ETH_ALEN];
>
> -	if (FEC_FLASHMAC) {
> -		/*
> -		 * Get MAC address from FLASH.
> -		 * If it is all 1's or 0's, use the default.
> -		 */
> -		iap = (unsigned char *)FEC_FLASHMAC;
> -		if ((iap[0] == 0)&&  (iap[1] == 0)&&  (iap[2] == 0)&&
> -		    (iap[3] == 0)&&  (iap[4] == 0)&&  (iap[5] == 0))
> -			iap = fec_mac_default;
> -		if ((iap[0] == 0xff)&&  (iap[1] == 0xff)&&  (iap[2] == 0xff)&&
> -		    (iap[3] == 0xff)&&  (iap[4] == 0xff)&&  (iap[5] == 0xff))
> -			iap = fec_mac_default;
> -	} else {
> -		*((unsigned long *)&tmpaddr[0]) = readl(fep->hwp + FEC_ADDR_LOW);
> -		*((unsigned short *)&tmpaddr[4]) = (readl(fep->hwp + FEC_ADDR_HIGH)>>  16);
> +	/*
> +	 * try to get mac address in following order:
> +	 *
> +	 * 1) kernel command line fec_mac=xx:xx:xx...
> +	 */
> +	iap = fec_mac_default;
> +
> +	/*
> +	 * 2) from flash or fuse (via platform data)
> +	 */
> +	if (!is_valid_ether_addr(iap)) {
> +#ifdef CONFIG_M5272
> +		if (FEC_FLASHMAC)
> +			iap = (unsigned char *)FEC_FLASHMAC;
> +#else
> +		if (pdata)
> +			memcpy(iap, pdata->mac, ETH_ALEN);
> +#endif
> +	}
> +
> +	/*
> +	 * 3) FEC mac registers set by bootloader
> +	 */
> +	if (!is_valid_ether_addr(iap)) {
> +		*((unsigned long *)&tmpaddr[0]) =
> +			be32_to_cpu(readl(fep->hwp + FEC_ADDR_LOW));
> +		*((unsigned short *)&tmpaddr[4]) =
> +			be16_to_cpu(readl(fep->hwp + FEC_ADDR_HIGH)>>  16);
>   		iap =&tmpaddr[0];
>   	}
>
> @@ -567,7 +574,6 @@ static void __inline__ fec_get_mac(struct net_device *dev)
>   	if (iap == fec_mac_default)
>   		 dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->pdev->id;
>   }
> -#endif
>
>   /* ------------------------------------------------------------------------- */
>
> @@ -1063,6 +1069,24 @@ static const struct net_device_ops fec_netdev_ops = {
>   	.ndo_do_ioctl           = fec_enet_ioctl,
>   };
>
> +static int __init fec_mac_addr_setup(char *mac_addr)
> +{
> +	int i;
> +	unsigned int tmp;
> +
> +	for (i = 0; i<  ETH_ALEN; i++) {
> +		if (sscanf(mac_addr + 3*i, "%2x",&tmp) != 1) {
> +			printk(KERN_WARNING "Malformed fec mac address\n");
> +			return 0;
> +		}
> +		fec_mac_default[i] = tmp;
> +	}
> +
> +	return 1;
> +}
> +
> +__setup("fec_mac=", fec_mac_addr_setup);
> +
>    /*
>     * XXX:  We need to clean up on failure exits here.
>     *
> @@ -1087,22 +1111,8 @@ static int fec_enet_init(struct net_device *dev)
>   	fep->hwp = (void __iomem *)dev->base_addr;
>   	fep->netdev = dev;
>
> -	/* Set the Ethernet address */
> -#ifdef CONFIG_M5272
> +	/* Get the Ethernet address */
>   	fec_get_mac(dev);
> -#else
> -	{
> -		unsigned long l;
> -		l = readl(fep->hwp + FEC_ADDR_LOW);
> -		dev->dev_addr[0] = (unsigned char)((l&  0xFF000000)>>  24);
> -		dev->dev_addr[1] = (unsigned char)((l&  0x00FF0000)>>  16);
> -		dev->dev_addr[2] = (unsigned char)((l&  0x0000FF00)>>  8);
> -		dev->dev_addr[3] = (unsigned char)((l&  0x000000FF)>>  0);
> -		l = readl(fep->hwp + FEC_ADDR_HIGH);
> -		dev->dev_addr[4] = (unsigned char)((l&  0xFF000000)>>  24);
> -		dev->dev_addr[5] = (unsigned char)((l&  0x00FF0000)>>  16);
> -	}
> -#endif
>
>   	/* Set receive and transmit descriptor base. */
>   	fep->rx_bd_base = cbd_base;
> diff --git a/include/linux/fec.h b/include/linux/fec.h
> index 5d3523d..bf0c69f 100644
> --- a/include/linux/fec.h
> +++ b/include/linux/fec.h
> @@ -1,6 +1,7 @@
>   /* include/linux/fec.h
>    *
>    * Copyright (c) 2009 Orex Computed Radiography
> + * Copyright (C) 2010 Freescale Semiconductor, Inc.
>    *   Baruch Siach<baruch@tkos.co.il>
>    *
>    * Header file for the FEC platform data
> @@ -16,6 +17,7 @@
>
>   struct fec_platform_data {
>   	phy_interface_t phy;
> +	unsigned char mac[ETH_ALEN];
>   };
>
>   #endif


-- 
------------------------------------------------------------------------
Greg Ungerer  --  Principal Engineer        EMAIL:     gerg at snapgear.com
SnapGear Group, McAfee                      PHONE:       +61 7 3435 2888
8 Gardner Close                             FAX:         +61 7 3217 5323
Milton, QLD, 4064, Australia                WEB: http://www.SnapGear.com

  reply	other threads:[~2010-12-29  5:29 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-28 14:55 [PATCH 00/10] net/fec: add dual fec support for i.MX28 Shawn Guo
2010-12-28 14:55 ` [PATCH 01/10] net/fec: fix MMFR_OP type in fec_enet_mdio_write Shawn Guo
2010-12-28 14:55 ` [PATCH 02/10] net/fec: remove the use of "index" which is legacy Shawn Guo
2010-12-28 14:55 ` [PATCH 03/10] net/fec: add mac field into platform data and consolidate fec_get_mac Shawn Guo
2010-12-29  5:29   ` Greg Ungerer [this message]
2010-12-29  9:51     ` Shawn Guo
2010-12-29  6:53   ` Baruch Siach
2010-12-29 10:05     ` Shawn Guo
2010-12-29 10:31       ` Uwe Kleine-König
2010-12-29 11:58         ` Shawn Guo
2010-12-29 11:58           ` Shawn Guo
2010-12-29 12:42           ` Uwe Kleine-König
2010-12-29 12:42             ` Uwe Kleine-König
2010-12-30  2:12             ` Shawn Guo
2010-12-30  2:12               ` Shawn Guo
2010-12-30  8:04               ` Uwe Kleine-König
2010-12-30  8:04                 ` Uwe Kleine-König
2010-12-30  4:29       ` Shawn Guo
2010-12-30  4:29         ` Shawn Guo
2010-12-30  5:29         ` Baruch Siach
2010-12-30  5:29           ` Baruch Siach
2010-12-30  7:20           ` Shawn Guo
2010-12-30  7:20             ` Shawn Guo
2010-12-29 10:30     ` Shawn Guo
2010-12-29 10:37       ` Uwe Kleine-König
2010-12-29 10:37         ` Uwe Kleine-König
2010-12-29 11:08         ` Shawn Guo
2010-12-29 11:08           ` Shawn Guo
2010-12-29 11:10           ` Uwe Kleine-König
2010-12-29 11:10             ` Uwe Kleine-König
2010-12-29 12:00             ` Shawn Guo
2010-12-29 12:00               ` Shawn Guo
2010-12-28 14:55 ` [PATCH 04/10] net/fec: improve pm for better suspend/resume Shawn Guo
2010-12-28 14:55 ` [PATCH 05/10] net/fec: add dual fec support for mx28 Shawn Guo
2010-12-28 14:55 ` [PATCH 06/10] ARM: mx28: update clocks for dual fec support Shawn Guo
2010-12-29  6:57   ` Baruch Siach
2010-12-29  8:10     ` Uwe Kleine-König
2010-12-29 10:14       ` Shawn Guo
2010-12-29 10:28         ` Uwe Kleine-König
2010-12-28 14:55 ` [PATCH 07/10] ARM: mx28: add the second fec device registration Shawn Guo
2010-12-29 10:50   ` Uwe Kleine-König
2010-12-29 12:05     ` Shawn Guo
2010-12-28 14:55 ` [PATCH 08/10] ARM: mxs: add ocotp read function Shawn Guo
2010-12-29 10:47   ` Uwe Kleine-König
2010-12-29 12:08     ` Shawn Guo
2010-12-29 13:47       ` Uwe Kleine-König
2010-12-29 11:22   ` Uwe Kleine-König
2010-12-30  5:50     ` Shawn Guo
2010-12-30  9:15       ` Uwe Kleine-König
2010-12-31  1:43         ` Shawn Guo
2010-12-31 16:11           ` Uwe Kleine-König
2011-01-01 13:03             ` Shawn Guo
2010-12-30  8:41     ` Shawn Guo
2010-12-30  9:02       ` Uwe Kleine-König
2010-12-31  1:46         ` Shawn Guo
2010-12-28 14:55 ` [PATCH 09/10] ARM: mx28: read fec mac address from ocotp Shawn Guo
2010-12-29 10:53   ` Uwe Kleine-König
2010-12-29 12:13     ` Shawn Guo
2010-12-29 12:45       ` Uwe Kleine-König
2010-12-30  2:19         ` Shawn Guo
2010-12-30  8:33         ` Shawn Guo
2010-12-28 14:55 ` [PATCH 10/10] ARM: mxs: add initial pm support Shawn Guo
2010-12-29 10:57   ` Uwe Kleine-König
2010-12-29 12:15     ` Shawn Guo
2010-12-30  8:50     ` Shawn Guo
2010-12-29  5:26 ` [PATCH 00/10] net/fec: add dual fec support for i.MX28 Greg Ungerer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D1AC71D.9020305@snapgear.com \
    --to=gerg@snapgear.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.