[PATCH 1/2] gianfar: region request returns NULL on already mapped region

Renaud Barbier renaud.barbier at ge.com
Thu Sep 13 13:41:50 EDT 2012


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 at 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




More information about the barebox mailing list