netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: ben@fluff.org.uk
To: netdev@vger.kernel.org
Cc: linux@simtec.co.uk, doong.ping@micrel.com, tristram.ha@micrel.com
Subject: [patch 3/9] KS8851: Add support for EEPROM MAC address
Date: Mon, 07 Dec 2009 12:15:04 +0000	[thread overview]
Message-ID: <20091207121646.572304617@fluff.org.uk> (raw)
In-Reply-To: 20091207121501.819539008@fluff.org.uk

[-- Attachment #1: ks8851-mac-from-eeprom.patch --]
[-- Type: text/plain, Size: 3404 bytes --]

Add support for reading the MAC address from the system registers if there
is an EEPROM present. This involves caching the KS_CCR register for later
use (will also be useful for ETHTOOL support) and adding a print to say
that there is an EEPROM present.

Signed-off-by: Ben Dooks <ben@simtec.co.uk>

---

---
 drivers/net/ks8851.c |   46 +++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 39 insertions(+), 7 deletions(-)

Index: b/drivers/net/ks8851.c
===================================================================
--- a/drivers/net/ks8851.c	2009-12-07 10:59:14.000000000 +0000
+++ b/drivers/net/ks8851.c	2009-12-07 10:59:24.000000000 +0000
@@ -76,6 +76,7 @@ union ks8851_tx_hdr {
  * @msg_enable: The message flags controlling driver output (see ethtool).
  * @fid: Incrementing frame id tag.
  * @rc_ier: Cached copy of KS_IER.
+ * @rc_ccr: Cached copy of KS_CCR.
  * @rc_rxqcr: Cached copy of KS_RXQCR.
  *
  * The @lock ensures that the chip is protected when certain operations are
@@ -107,6 +108,7 @@ struct ks8851_net {
 
 	u16			rc_ier;
 	u16			rc_rxqcr;
+	u16			rc_ccr;
 
 	struct mii_if_info	mii;
 	struct ks8851_rxctrl	rxctrl;
@@ -367,21 +369,47 @@ static int ks8851_write_mac_addr(struct 
 }
 
 /**
+ * ks8851_read_mac_addr - read mac address from device registers
+ * @dev: The network device
+ *
+ * Update our copy of the KS8851 MAC address from the registers of @dev.
+*/
+static void ks8851_read_mac_addr(struct net_device *dev)
+{
+	struct ks8851_net *ks = netdev_priv(dev);
+	int i;
+
+	mutex_lock(&ks->lock);
+
+	for (i = 0; i < ETH_ALEN; i++)
+		dev->dev_addr[i] = ks8851_rdreg8(ks, KS_MAR(i));
+
+	mutex_unlock(&ks->lock);
+}
+
+/**
  * ks8851_init_mac - initialise the mac address
  * @ks: The device structure
  *
  * Get or create the initial mac address for the device and then set that
- * into the station address register. Currently we assume that the device
- * does not have a valid mac address in it, and so we use random_ether_addr()
+ * into the station address register. If there is an EEPROM present, then
+ * we try that. If no valid mac address is found we use random_ether_addr()
  * to create a new one.
- *
- * In future, the driver should check to see if the device has an EEPROM
- * attached and whether that has a valid ethernet address in it.
  */
 static void ks8851_init_mac(struct ks8851_net *ks)
 {
 	struct net_device *dev = ks->netdev;
 
+	/* first, try reading what we've got already */
+	if (ks->rc_ccr & CCR_EEPROM) {
+		ks8851_read_mac_addr(dev);
+		if (is_valid_ether_addr(dev->dev_addr))
+			return;
+
+		ks_err(ks, "invalid mac address read %pM\n",
+			dev->dev_addr);
+	}
+
 	random_ether_addr(dev->dev_addr);
 	ks8851_write_mac_addr(dev);
 }
@@ -1280,6 +1308,9 @@ static int __devinit ks8851_probe(struct
 		goto err_id;
 	}
 
+  	/* cache the contents of the CCR register for EEPROM, etc. */
+  	ks->rc_ccr = ks8851_rdreg16(ks, KS_CCR);
+
 	ks8851_read_selftest(ks);
 	ks8851_init_mac(ks);
 	ks->tx_space = ks8851_rdreg16(ks, KS_TXMIR);
@@ -1297,9 +1328,10 @@ static int __devinit ks8851_probe(struct
 		goto err_netdev;
 	}
 
-	dev_info(&spi->dev, "revision %d, MAC %pM, IRQ %d\n",
+	dev_info(&spi->dev, "revision %d, MAC %pM, IRQ %d, %s EEPROM\n",
 		 CIDER_REV_GET(ks8851_rdreg16(ks, KS_CIDER)),
-		 ndev->dev_addr, ndev->irq);
+		 ndev->dev_addr, ndev->irq,
+		 ks->rc_ccr & CCR_EEPROM ? "has" : "no");
 
 	return 0;
 


  parent reply	other threads:[~2009-12-07 12:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20091207121501.819539008@fluff.org.uk>
2009-12-07 12:15 ` [patch 1/9] eeprom_93cx6: Add data direction control ben
2009-12-07 12:34   ` Ben Dooks
2009-12-07 12:15 ` [patch 2/9] eeprom_93cx6: Add write support ben
2009-12-07 12:15 ` ben [this message]
2009-12-09  4:45   ` [patch 3/9] KS8851: Add support for EEPROM MAC address David Miller
2009-12-07 12:15 ` [patch 4/9] KS8851: Add ethtool support for EEPROM ben
2009-12-07 12:15 ` [patch 5/9] KS8851: Add debugfs export for driver state ben
2009-12-07 12:15 ` [patch 6/9] KS8851: ks8851_mll.c: Use the ks8851.h header for device register defines ben
2009-12-07 12:15 ` [patch 7/9] KS8851: Update ks8851.h header from ks8851_mll.c ben
2009-12-07 12:15 ` [patch 8/9] KS8851: Use the ks8851.h header to hold union ks8851_tx_hdr ben
2009-12-07 12:15 ` [patch 9/9] KS8851: Add platform data to specific IRQ trigger type ben
     [not found] <20091207121727.016092171@fluff.org.uk>
2009-12-07 12:17 ` [patch 3/9] KS8851: Add support for EEPROM MAC address Ben Dooks

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=20091207121646.572304617@fluff.org.uk \
    --to=ben@fluff.org.uk \
    --cc=doong.ping@micrel.com \
    --cc=linux@simtec.co.uk \
    --cc=netdev@vger.kernel.org \
    --cc=tristram.ha@micrel.com \
    /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 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).