mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* i.MX fec cleanup
@ 2011-07-28 10:08 Sascha Hauer
  2011-07-28 10:08 ` [PATCH 1/5] ARM dma_alloc_coherent: Fix alignment for !MMU case Sascha Hauer
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Sascha Hauer @ 2011-07-28 10:08 UTC (permalink / raw)
  To: barebox

The following series contains some i.MX fec ethernet driver
cleanups.

Sascha Hauer (5):
      ARM dma_alloc_coherent: Fix alignment for !MMU case
      net i.MX fec: make multi instance safe
      net i.MX fec: remove unnecessary alignment
      net i.MX fec: embed ethernet device into priv
      net i.MX fec: rename driver struct to be generic

 arch/arm/include/asm/mmu.h |    2 +-
 drivers/net/fec_imx.c      |   64 ++++++++++++++++++++++---------------------
 drivers/net/fec_imx.h      |    1 +
 3 files changed, 35 insertions(+), 32 deletions(-)

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

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

* [PATCH 1/5] ARM dma_alloc_coherent: Fix alignment for !MMU case
  2011-07-28 10:08 i.MX fec cleanup Sascha Hauer
@ 2011-07-28 10:08 ` Sascha Hauer
  2011-07-28 10:08 ` [PATCH 2/5] net i.MX fec: make multi instance safe Sascha Hauer
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2011-07-28 10:08 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/include/asm/mmu.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/arm/include/asm/mmu.h b/arch/arm/include/asm/mmu.h
index 7789cc9..f235448 100644
--- a/arch/arm/include/asm/mmu.h
+++ b/arch/arm/include/asm/mmu.h
@@ -28,7 +28,7 @@ void *phys_to_virt(unsigned long phys);
 #else
 static inline void *dma_alloc_coherent(size_t size)
 {
-	return xmalloc(size);
+	return xmemalign(4096, size);
 }
 
 static inline void dma_free_coherent(void *mem)
-- 
1.7.5.4


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

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

* [PATCH 2/5] net i.MX fec: make multi instance safe
  2011-07-28 10:08 i.MX fec cleanup Sascha Hauer
  2011-07-28 10:08 ` [PATCH 1/5] ARM dma_alloc_coherent: Fix alignment for !MMU case Sascha Hauer
@ 2011-07-28 10:08 ` Sascha Hauer
  2011-07-28 10:08 ` [PATCH 3/5] net i.MX fec: remove unnecessary alignment Sascha Hauer
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2011-07-28 10:08 UTC (permalink / raw)
  To: barebox

The driver uses a static int once variable to alloc the
rx packets. remove this to make the driver multi instance
safe. While at it, remove the crappy selfmade alignment.
dma_alloc_coherent returns sufficiently aligned memory.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/fec_imx.c |   34 ++++++++++++++++++++--------------
 1 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/drivers/net/fec_imx.c b/drivers/net/fec_imx.c
index fcb8cc5..552d281 100644
--- a/drivers/net/fec_imx.c
+++ b/drivers/net/fec_imx.c
@@ -200,25 +200,11 @@ static void imx28_fix_endianess_rd(uint32_t *buf, unsigned wlen)
 static int fec_rbd_init(struct fec_priv *fec, int count, int size)
 {
 	int ix;
-	static int once = 0;
-	unsigned long p = 0;
-
-	if (!once) {
-		/* reserve data memory and consider alignment */
-		p = (unsigned long)dma_alloc_coherent(size * count + DB_DATA_ALIGNMENT);
-		p += DB_DATA_ALIGNMENT - 1;
-		p &= ~(DB_DATA_ALIGNMENT - 1);
-	}
 
 	for (ix = 0; ix < count; ix++) {
-		if (!once) {
-			writel(virt_to_phys((void *)p), &fec->rbd_base[ix].data_pointer);
-			p += size;
-		}
 		writew(FEC_RBD_EMPTY, &fec->rbd_base[ix].status);
 		writew(0, &fec->rbd_base[ix].data_length);
 	}
-	once = 1;	/* malloc done now (and once) */
 	/*
 	 * mark the last RBD to close the ring
 	 */
@@ -592,6 +578,24 @@ static int fec_recv(struct eth_device *dev)
 	return len;
 }
 
+static int fec_alloc_receive_packets(struct fec_priv *fec, int count, int size)
+{
+	void *p;
+	int i;
+
+	/* reserve data memory and consider alignment */
+	p = dma_alloc_coherent(size * count);
+	if (!p)
+		return -ENOMEM;
+
+	for (i = 0; i < count; i++) {
+		writel(virt_to_phys(p), &fec->rbd_base[i].data_pointer);
+		p += size;
+	}
+
+	return 0;
+}
+
 static int fec_probe(struct device_d *dev)
 {
         struct fec_platform_data *pdata = (struct fec_platform_data *)dev->platform_data;
@@ -638,6 +642,8 @@ static int fec_probe(struct device_d *dev)
 	writel((uint32_t)virt_to_phys(fec->tbd_base), fec->regs + FEC_ETDSR);
 	writel((uint32_t)virt_to_phys(fec->rbd_base), fec->regs + FEC_ERDSR);
 
+	fec_alloc_receive_packets(fec, FEC_RBD_NUM, FEC_MAX_PKT_SIZE);
+
 	fec->xcv_type = pdata->xcv_type;
 
 	if (fec->xcv_type != SEVENWIRE) {
-- 
1.7.5.4


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

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

* [PATCH 3/5] net i.MX fec: remove unnecessary alignment
  2011-07-28 10:08 i.MX fec cleanup Sascha Hauer
  2011-07-28 10:08 ` [PATCH 1/5] ARM dma_alloc_coherent: Fix alignment for !MMU case Sascha Hauer
  2011-07-28 10:08 ` [PATCH 2/5] net i.MX fec: make multi instance safe Sascha Hauer
@ 2011-07-28 10:08 ` Sascha Hauer
  2011-07-28 10:08 ` [PATCH 4/5] net i.MX fec: embed ethernet device into priv Sascha Hauer
  2011-07-28 10:08 ` [PATCH 5/5] net i.MX fec: rename driver struct to be generic Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2011-07-28 10:08 UTC (permalink / raw)
  To: barebox

dma_alloc_coherent returns sufficiently aligned memory. While
at it, remove some unnecessary casts.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/fec_imx.c |   22 +++++++++-------------
 1 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/drivers/net/fec_imx.c b/drivers/net/fec_imx.c
index 552d281..6886ccc 100644
--- a/drivers/net/fec_imx.c
+++ b/drivers/net/fec_imx.c
@@ -601,7 +601,7 @@ static int fec_probe(struct device_d *dev)
         struct fec_platform_data *pdata = (struct fec_platform_data *)dev->platform_data;
         struct eth_device *edev;
 	struct fec_priv *fec;
-	uint32_t base;
+	void *base;
 #ifdef CONFIG_ARCH_IMX27
 	PCCR0 |= PCCR0_FEC_EN;
 #endif
@@ -629,18 +629,14 @@ static int fec_probe(struct device_d *dev)
 	 * reserve memory for both buffer descriptor chains at once
 	 * Datasheet forces the startaddress of each chain is 16 byte aligned
 	 */
-	base = (uint32_t)dma_alloc_coherent((2 + FEC_RBD_NUM) *
-			sizeof(struct buffer_descriptor) + 2 * DB_ALIGNMENT);
-	base += (DB_ALIGNMENT - 1);
-	base &= ~(DB_ALIGNMENT - 1);
-	fec->rbd_base = (struct buffer_descriptor __force __iomem *)base;
-	base += FEC_RBD_NUM * sizeof (struct buffer_descriptor) +
-		(DB_ALIGNMENT - 1);
-	base &= ~(DB_ALIGNMENT - 1);
-	fec->tbd_base = (struct buffer_descriptor __force __iomem *)base;
-
-	writel((uint32_t)virt_to_phys(fec->tbd_base), fec->regs + FEC_ETDSR);
-	writel((uint32_t)virt_to_phys(fec->rbd_base), fec->regs + FEC_ERDSR);
+	base = dma_alloc_coherent((2 + FEC_RBD_NUM) *
+			sizeof(struct buffer_descriptor));
+	fec->rbd_base = base;
+	base += FEC_RBD_NUM * sizeof(struct buffer_descriptor);
+	fec->tbd_base = base;
+
+	writel(virt_to_phys(fec->tbd_base), fec->regs + FEC_ETDSR);
+	writel(virt_to_phys(fec->rbd_base), fec->regs + FEC_ERDSR);
 
 	fec_alloc_receive_packets(fec, FEC_RBD_NUM, FEC_MAX_PKT_SIZE);
 
-- 
1.7.5.4


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

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

* [PATCH 4/5] net i.MX fec: embed ethernet device into priv
  2011-07-28 10:08 i.MX fec cleanup Sascha Hauer
                   ` (2 preceding siblings ...)
  2011-07-28 10:08 ` [PATCH 3/5] net i.MX fec: remove unnecessary alignment Sascha Hauer
@ 2011-07-28 10:08 ` Sascha Hauer
  2011-07-28 10:08 ` [PATCH 5/5] net i.MX fec: rename driver struct to be generic Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2011-07-28 10:08 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/fec_imx.c |    4 ++--
 drivers/net/fec_imx.h |    1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/fec_imx.c b/drivers/net/fec_imx.c
index 6886ccc..72f7faa 100644
--- a/drivers/net/fec_imx.c
+++ b/drivers/net/fec_imx.c
@@ -605,9 +605,9 @@ static int fec_probe(struct device_d *dev)
 #ifdef CONFIG_ARCH_IMX27
 	PCCR0 |= PCCR0_FEC_EN;
 #endif
-	edev = (struct eth_device *)xzalloc(sizeof(struct eth_device));
+	fec = xzalloc(sizeof(*fec));
+	edev = &fec->edev;
 	dev->type_data = edev;
-	fec = (struct fec_priv *)xzalloc(sizeof(*fec));
 	edev->priv = fec;
 	edev->open = fec_open;
 	edev->init = fec_init;
diff --git a/drivers/net/fec_imx.h b/drivers/net/fec_imx.h
index e07071a..19f4709 100644
--- a/drivers/net/fec_imx.h
+++ b/drivers/net/fec_imx.h
@@ -144,6 +144,7 @@ struct buffer_descriptor {
  * @brief i.MX27-FEC private structure
  */
 struct fec_priv {
+	struct eth_device edev;
 	void __iomem *regs;
 	xceiver_type xcv_type;			/* transceiver type          */
 	struct buffer_descriptor __iomem *rbd_base;	/* RBD ring                  */
-- 
1.7.5.4


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

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

* [PATCH 5/5] net i.MX fec: rename driver struct to be generic
  2011-07-28 10:08 i.MX fec cleanup Sascha Hauer
                   ` (3 preceding siblings ...)
  2011-07-28 10:08 ` [PATCH 4/5] net i.MX fec: embed ethernet device into priv Sascha Hauer
@ 2011-07-28 10:08 ` Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2011-07-28 10:08 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/fec_imx.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/fec_imx.c b/drivers/net/fec_imx.c
index 72f7faa..4cfb98b 100644
--- a/drivers/net/fec_imx.c
+++ b/drivers/net/fec_imx.c
@@ -666,7 +666,7 @@ static void fec_remove(struct device_d *dev)
 /**
  * Driver description for registering
  */
-static struct driver_d imx27_driver = {
+static struct driver_d fec_driver = {
         .name   = "fec_imx",
         .probe  = fec_probe,
 	.remove = fec_remove,
@@ -674,7 +674,7 @@ static struct driver_d imx27_driver = {
 
 static int fec_register(void)
 {
-        register_driver(&imx27_driver);
+        register_driver(&fec_driver);
         return 0;
 }
 
-- 
1.7.5.4


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

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

end of thread, other threads:[~2011-07-28 10:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-28 10:08 i.MX fec cleanup Sascha Hauer
2011-07-28 10:08 ` [PATCH 1/5] ARM dma_alloc_coherent: Fix alignment for !MMU case Sascha Hauer
2011-07-28 10:08 ` [PATCH 2/5] net i.MX fec: make multi instance safe Sascha Hauer
2011-07-28 10:08 ` [PATCH 3/5] net i.MX fec: remove unnecessary alignment Sascha Hauer
2011-07-28 10:08 ` [PATCH 4/5] net i.MX fec: embed ethernet device into priv Sascha Hauer
2011-07-28 10:08 ` [PATCH 5/5] net i.MX fec: rename driver struct to be generic Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox