mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Renaud Barbier <renaud.barbier@ge.com>
To: barebox@lists.infradead.org
Subject: [PATCH 1/2] gianfar: region request returns NULL on already mapped region
Date: Thu, 13 Sep 2012 18:41:50 +0100	[thread overview]
Message-ID: <1347558111-1633-2-git-send-email-renaud.barbier@ge.com> (raw)
In-Reply-To: <1347558111-1633-1-git-send-email-renaud.barbier@ge.com>

When requesting a memory region and that region has already been
requested within an instance of the driver or another instance, a NULL
pointer is obtained from the function dev_request_mem_region.
For a eTSEC port we have three sets of registers:
- MAC registers
- External phy access registers
- TBI registers.

Depending on the eTSEC port number and eTSEC version (v1/v2), the overlap
may happen between registers of a port or between registers of two ports
or more.
For instance, in eTSEC v1 all ports use the external phy registers from
eTSEC1 and for each port the MAC registers = TBI registers.
This patch works around the memory overlapping.

Signed-off-by: Renaud Barbier <renaud.barbier@ge.com>
---
 drivers/net/gianfar.c |   30 +++++++++++++++++++++++++++++-
 1 files changed, 29 insertions(+), 1 deletions(-)

diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index 19544de..917f843 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -28,6 +28,8 @@
 #define RX_BUF_CNT 	PKTBUFSRX
 #define BUF_ALIGN	8
 
+static void __iomem *phyregs;
+
 /*
  * Initialize required registers to appropriate values, zeroing
  * those we don't care about (unless zero is bad, in which case,
@@ -488,9 +490,35 @@ static int gfar_probe(struct device_d *dev)
 
 	edev = &priv->edev;
 
+	/*
+	 * Memory region requests may return NULL because depending on
+	 * the Ethernet port, it may have been already mapped.
+	 * TSECv1:
+	 *  port 1: region 0 = 1 = 2
+	 *  port 2,3: region 0 = 2, region 1 = port 1 region 1
+	 *
+	 * TSECv2:
+	 *  port 1: 1 = 2
+	 *  port 2,3: no overlap, region 1 = port 1 region 1
+	 */
 	priv->regs = dev_request_mem_region(dev, 0);
-	priv->phyregs = dev_request_mem_region(dev, 1);
+	if (priv->regs == NULL)
+		priv->regs = phyregs;
+
+	if (phyregs == NULL) {
+		phyregs = dev_request_mem_region(dev, 1);
+		if (phyregs == NULL)
+			phyregs = priv->regs;
+	}
+	priv->phyregs = phyregs;
+
 	priv->phyregs_sgmii = dev_request_mem_region(dev, 2);
+	if (priv->phyregs_sgmii == NULL)
+#ifdef CONFIG_TSECV2
+		priv->phyregs_sgmii = priv->phyregs;
+#else
+		priv->phyregs_sgmii = priv->regs;
+#endif
 
 	priv->phyaddr = gfar_info->phyaddr;
 	priv->tbicr = gfar_info->tbicr;
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2012-09-13 17:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-13 17:41 [PATCH 0/2] P2020RDB eTSEC2 Renaud Barbier
2012-09-13 17:41 ` Renaud Barbier [this message]
2012-09-13 17:41 ` [PATCH 2/2] P2020rdb: eTSEC2 support Renaud Barbier
2012-09-14  7:33 ` [PATCH 0/2] P2020RDB eTSEC2 Sascha Hauer

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=1347558111-1633-2-git-send-email-renaud.barbier@ge.com \
    --to=renaud.barbier@ge.com \
    --cc=barebox@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox