Received: from milmhbs1.lsil.com (147.145.21.209) by coscas01.lsi.com
 (172.21.36.60) with Microsoft SMTP Server id 8.1.393.1; Thu, 5 Nov 2009
 10:57:13 -0700
Received: from mail2.lsil.com (mail2.lsil.com [147.145.40.22])	by
 milmhbs1.lsil.com (8.12.11/8.12.11) with ESMTP id nA5HvDUk024596	for
 <andy.sharp@lsi.com>; Thu, 5 Nov 2009 09:57:13 -0800
Received: from psmtp.com (na3sys009amx254.postini.com [74.125.149.138])	by
 mail2.lsil.com (8.12.11/8.12.11) with SMTP id nA5HrL4L013324	for
 <andy.sharp@lsi.com>; Thu, 5 Nov 2009 09:53:22 -0800 (PST)
Received: from source ([78.24.191.182]) by na3sys009amx254.postini.com
 ([74.125.148.14]) with SMTP;	Thu, 05 Nov 2009 09:57:12 PST
Received: from localhost.localdomain ([127.0.0.1]:46406 "EHLO
	eddie.linux-mips.org" rhost-flags-OK-OK-OK-FAIL) by ftp.linux-mips.org	with
 ESMTP id S1492842AbZKER5L (ORCPT <rfc822;andy.sharp@lsi.com>);	Thu, 5 Nov
 2009 18:57:11 +0100
Received: with ECARTIS (v1.0.0; list linux-mips); Thu, 05 Nov 2009 18:56:53
 +0100 (CET)
Received: from localhost.localdomain ([127.0.0.1]:58913 "EHLO h5.dl5rb.org.uk"
	rhost-flags-OK-OK-OK-FAIL) by ftp.linux-mips.org with ESMTP	id
 S1492990AbZKERzn (ORCPT <rfc822;linux-mips@linux-mips.org>);	Thu, 5 Nov 2009
 18:55:43 +0100
Received: from h5.dl5rb.org.uk (localhost.localdomain [127.0.0.1])	by
 h5.dl5rb.org.uk (8.14.3/8.14.3) with ESMTP id nA5Hv7jO024937;	Thu, 5 Nov 2009
 18:57:07 +0100
Received: (from ralf@localhost)	by h5.dl5rb.org.uk (8.14.3/8.14.3/Submit) id
 nA5Hv57K024936;	Thu, 5 Nov 2009 18:57:05 +0100
From: Ralf Baechle <ralf@linux-mips.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
CC: David Daney <ddaney@caviumnetworks.com>, Greg Kroah-Hartman
	<gregkh@suse.de>, "devel@driverdev.osuosl.org" <devel@driverdev.osuosl.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-mips@linux-mips.org" <linux-mips@linux-mips.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Sender: "linux-mips-bounce@linux-mips.org" <linux-mips-bounce@linux-mips.org>
Date: Thu, 5 Nov 2009 08:25:59 -0700
Subject: [PATCH 3/6] Staging: octeon-ethernet: Assign proper MAC addresses.
Thread-Topic: [PATCH 3/6] Staging: octeon-ethernet: Assign proper MAC
 addresses.
Thread-Index: AcpeQWf29SZlcSU2SpKiVaZKfSdhIw==
Message-ID: <20091105152702.201728770@linux-mips.org>
References: <20091105152555.227009519@linux-mips.org>
Accept-Language: en-US
Content-Language: en-US
X-MS-Exchange-Organization-AuthAs: Anonymous
X-MS-Exchange-Organization-AuthSource: coscas01.lsi.com
X-MS-Has-Attach:
X-Auto-Response-Suppress: All
X-MS-TNEF-Correlator:
x-scanned-by: MIMEDefang 2.39
errors-to: linux-mips-bounce@linux-mips.org
x-pstn-levels: (S:79.95094/99.90000 CV:99.9000 FC:95.5390 LC:95.5390
 R:95.9108 P:95.9108 M:97.0282 C:98.6951 )
x-pstn-settings: 3 (1.0000:1.0000) s cv gt3 gt2 gt1 r p m c 
x-pstn-addresses: from <ralf@linux-mips.org> [22/1] 
x-pstn-neptune: 0/0/0.00/0
user-agent: quilt/0.47-1
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

From: David Daney <ddaney@caviumnetworks.com>

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>
Cc: Greg Kroah-Hartman <gregkh@suse.de>
Cc: devel@driverdev.osuosl.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-mips@linux-mips.org
Cc: netdev@vger.kernel.org
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

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

Index: upstream-linus/drivers/staging/octeon/ethernet.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- upstream-linus.orig/drivers/staging/octeon/ethernet.c
+++ upstream-linus/drivers/staging/octeon/ethernet.c
@@ -111,6 +111,16 @@ MODULE_PARM_DESC(disable_core_queueing,=20
 	"\tallows packets to be sent without lock contention in the packet\n"
 	"\tscheduler resulting in some cases in improved throughput.\n");
=20
+
+/*
+ * 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_addres
  */
 int cvm_oct_common_init(struct net_device *dev)
 {
-	static int count;
-	char mac[8] =3D { 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 =3D netdev_priv(dev);
+	struct sockaddr sa;
+	u64 mac =3D ((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 +=3D cvm_oct_mac_addr_offset;
+	sa.sa_data[0] =3D (mac >> 40) & 0xff;
+	sa.sa_data[1] =3D (mac >> 32) & 0xff;
+	sa.sa_data[2] =3D (mac >> 24) & 0xff;
+	sa.sa_data[3] =3D (mac >> 16) & 0xff;
+	sa.sa_data[4] =3D (mac >> 8) & 0xff;
+	sa.sa_data[5] =3D mac & 0xff;
+
+	if (cvm_oct_mac_addr_offset >=3D 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++;
=20
 	/*
 	 * Force the interface to use the POW send if always_use_pow
@@ -496,14 +520,12 @@ int cvm_oct_common_init(struct net_devic
 	if (priv->queue !=3D -1 && USE_HW_TCPUDP_CHECKSUM)
 		dev->features |=3D NETIF_F_IP_CSUM;
=20
-	count++;
-
 	/* We do our own locking, Linux doesn't need to */
 	dev->features |=3D NETIF_F_LLTX;
 	SET_ETHTOOL_OPS(dev, &cvm_oct_ethtool_ops);
=20
 	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);
=20
 	/*
@@ -620,6 +642,13 @@ static int __init cvm_oct_init_module(vo
=20
 	pr_notice("cavium-ethernet %s\n", OCTEON_ETHERNET_VERSION);
=20
+	if (OCTEON_IS_MODEL(OCTEON_CN52XX))
+		cvm_oct_mac_addr_offset =3D 2; /* First two are the mgmt ports. */
+	else if (OCTEON_IS_MODEL(OCTEON_CN56XX))
+		cvm_oct_mac_addr_offset =3D 1; /* First one is the mgmt port. */
+	else
+		cvm_oct_mac_addr_offset =3D 0;
+
 	cvm_oct_proc_initialize();
 	cvm_oct_rx_initialize();
 	cvm_oct_configure_common_hw();



