linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] Staging: octeon-ethernet: Assign proper MAC addresses.
  2009-10-12 19:04 [PATCH] Staging: octeon-ethernet: Assign proper MAC addresses David Daney
@ 2009-10-12 19:04 ` Greg KH
  2009-10-12 22:52   ` Ralf Baechle
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2009-10-12 19:04 UTC (permalink / raw)
  To: David Daney; +Cc: linux-mips, ralf

On Mon, Oct 12, 2009 at 12:04:32PM -0700, David Daney wrote:
> Allocate MAC addresses using the same method as the bootloader.  This
> avoids changing the MAC between bootloader and kernel operation as
> well as avoiding duplicates and use of addresses outside of the
> assigned range.
> 
> Signed-off-by: David Daney <ddaney@caviumnetworks.com>
> ---
> 
> This could merge via Ralf's tree as Octeon is MIPS based and all the
> rest of the Octeon patches seem to be going in this way.

Fine with me.

thanks,

greg k-h

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

* [PATCH] Staging: octeon-ethernet: Assign proper MAC addresses.
@ 2009-10-12 19:04 David Daney
  2009-10-12 19:04 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: David Daney @ 2009-10-12 19:04 UTC (permalink / raw)
  To: linux-mips, ralf, gregkh; +Cc: David Daney

Allocate MAC addresses using the same method as the bootloader.  This
avoids changing the MAC between bootloader and kernel operation as
well as avoiding duplicates and use of addresses outside of the
assigned range.

Signed-off-by: David Daney <ddaney@caviumnetworks.com>
---

This could merge via Ralf's tree as Octeon is MIPS based and all the
rest of the Octeon patches seem to be going in this way.

 drivers/staging/octeon/ethernet.c |   53 ++++++++++++++++++++++++++++--------
 1 files changed, 41 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
index b847951..492c502 100644
--- a/drivers/staging/octeon/ethernet.c
+++ b/drivers/staging/octeon/ethernet.c
@@ -111,6 +111,16 @@ MODULE_PARM_DESC(disable_core_queueing, "\n"
 	"\tallows packets to be sent without lock contention in the packet\n"
 	"\tscheduler resulting in some cases in improved throughput.\n");
 
+
+/*
+ * The offset from mac_addr_base that should be used for the next port
+ * that is configured.  By convention, if any mgmt ports exist on the
+ * chip, they get the first mac addresses, The ports controlled by
+ * this driver are numbered sequencially following any mgmt addresses
+ * that may exist.
+ */
+static unsigned int cvm_oct_mac_addr_offset;
+
 /**
  * Periodic timer to check auto negotiation
  */
@@ -474,16 +484,30 @@ static int cvm_oct_common_set_mac_address(struct net_device *dev, void *addr)
  */
 int cvm_oct_common_init(struct net_device *dev)
 {
-	static int count;
-	char mac[8] = { 0x00, 0x00,
-		octeon_bootinfo->mac_addr_base[0],
-		octeon_bootinfo->mac_addr_base[1],
-		octeon_bootinfo->mac_addr_base[2],
-		octeon_bootinfo->mac_addr_base[3],
-		octeon_bootinfo->mac_addr_base[4],
-		octeon_bootinfo->mac_addr_base[5] + count
-	};
 	struct octeon_ethernet *priv = netdev_priv(dev);
+	struct sockaddr sa;
+	u64 mac = ((u64)(octeon_bootinfo->mac_addr_base[0] & 0xff) << 40) |
+		((u64)(octeon_bootinfo->mac_addr_base[1] & 0xff) << 32) |
+		((u64)(octeon_bootinfo->mac_addr_base[2] & 0xff) << 24) |
+		((u64)(octeon_bootinfo->mac_addr_base[3] & 0xff) << 16) |
+		((u64)(octeon_bootinfo->mac_addr_base[4] & 0xff) << 8) |
+		(u64)(octeon_bootinfo->mac_addr_base[5] & 0xff);
+
+	mac += cvm_oct_mac_addr_offset;
+	sa.sa_data[0] = (mac >> 40) & 0xff;
+	sa.sa_data[1] = (mac >> 32) & 0xff;
+	sa.sa_data[2] = (mac >> 24) & 0xff;
+	sa.sa_data[3] = (mac >> 16) & 0xff;
+	sa.sa_data[4] = (mac >> 8) & 0xff;
+	sa.sa_data[5] = mac & 0xff;
+
+	if (cvm_oct_mac_addr_offset >= octeon_bootinfo->mac_addr_count)
+		printk(KERN_DEBUG "%s: Using MAC outside of the assigned range:"
+			" %02x:%02x:%02x:%02x:%02x:%02x\n", dev->name,
+			sa.sa_data[0] & 0xff, sa.sa_data[1] & 0xff,
+			sa.sa_data[2] & 0xff, sa.sa_data[3] & 0xff,
+			sa.sa_data[4] & 0xff, sa.sa_data[5] & 0xff);
+	cvm_oct_mac_addr_offset++;
 
 	/*
 	 * Force the interface to use the POW send if always_use_pow
@@ -496,14 +520,12 @@ int cvm_oct_common_init(struct net_device *dev)
 	if (priv->queue != -1 && USE_HW_TCPUDP_CHECKSUM)
 		dev->features |= NETIF_F_IP_CSUM;
 
-	count++;
-
 	/* We do our own locking, Linux doesn't need to */
 	dev->features |= NETIF_F_LLTX;
 	SET_ETHTOOL_OPS(dev, &cvm_oct_ethtool_ops);
 
 	cvm_oct_mdio_setup_device(dev);
-	dev->netdev_ops->ndo_set_mac_address(dev, mac);
+	dev->netdev_ops->ndo_set_mac_address(dev, &sa);
 	dev->netdev_ops->ndo_change_mtu(dev, dev->mtu);
 
 	/*
@@ -620,6 +642,13 @@ static int __init cvm_oct_init_module(void)
 
 	pr_notice("cavium-ethernet %s\n", OCTEON_ETHERNET_VERSION);
 
+	if (OCTEON_IS_MODEL(OCTEON_CN52XX))
+		cvm_oct_mac_addr_offset = 2; /* First two are the mgmt ports. */
+	else if (OCTEON_IS_MODEL(OCTEON_CN56XX))
+		cvm_oct_mac_addr_offset = 1; /* First one is the mgmt port. */
+	else
+		cvm_oct_mac_addr_offset = 0;
+
 	cvm_oct_proc_initialize();
 	cvm_oct_rx_initialize();
 	cvm_oct_configure_common_hw();
-- 
1.6.0.6

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

* Re: [PATCH] Staging: octeon-ethernet: Assign proper MAC addresses.
  2009-10-12 19:04 ` Greg KH
@ 2009-10-12 22:52   ` Ralf Baechle
  0 siblings, 0 replies; 3+ messages in thread
From: Ralf Baechle @ 2009-10-12 22:52 UTC (permalink / raw)
  To: Greg KH; +Cc: David Daney, linux-mips

On Mon, Oct 12, 2009 at 12:04:09PM -0700, Greg KH wrote:

> 
> On Mon, Oct 12, 2009 at 12:04:32PM -0700, David Daney wrote:
> > Allocate MAC addresses using the same method as the bootloader.  This
> > avoids changing the MAC between bootloader and kernel operation as
> > well as avoiding duplicates and use of addresses outside of the
> > assigned range.
> > 
> > Signed-off-by: David Daney <ddaney@caviumnetworks.com>
> > ---
> > 
> > This could merge via Ralf's tree as Octeon is MIPS based and all the
> > rest of the Octeon patches seem to be going in this way.
> 
> Fine with me.

Thanks, applied.

  Ralf

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

end of thread, other threads:[~2009-10-12 22:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-12 19:04 [PATCH] Staging: octeon-ethernet: Assign proper MAC addresses David Daney
2009-10-12 19:04 ` Greg KH
2009-10-12 22:52   ` Ralf Baechle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).